Added a unit test returns a razor view.

pull/113/head
Halil İbrahim Kalkan 8 years ago
parent fe3c763039
commit fcc4c6269d

@ -2,17 +2,22 @@
<PropertyGroup>
<TargetFramework>netcoreapp2.0</TargetFramework>
<AssetTargetFallback>$(AssetTargetFallback);portable-net45+win8+wp8+wpa81;</AssetTargetFallback>
<AssemblyName>Volo.Abp.AspNetCore.Mvc.Tests</AssemblyName>
<PackageId>Volo.Abp.AspNetCore.Mvc.Tests</PackageId>
<PreserveCompilationContext>true</PreserveCompilationContext>
<GenerateRuntimeConfigurationFiles>true</GenerateRuntimeConfigurationFiles>
<GenerateAssemblyConfigurationAttribute>false</GenerateAssemblyConfigurationAttribute>
<GenerateAssemblyCompanyAttribute>false</GenerateAssemblyCompanyAttribute>
<GenerateAssemblyProductAttribute>false</GenerateAssemblyProductAttribute>
<AutoGenerateBindingRedirects>true</AutoGenerateBindingRedirects>
<GenerateBindingRedirectsOutputType>true</GenerateBindingRedirectsOutputType>
<RootNamespace />
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="15.3.0" />
<PackageReference Include="Microsoft.AspNetCore.Mvc" Version="2.0.0" />
</ItemGroup>
<ItemGroup>
@ -22,4 +27,23 @@
<ProjectReference Include="..\Volo.Abp.MemoryDb.Tests\Volo.Abp.MemoryDb.Tests.csproj" />
</ItemGroup>
<!-- Below ItemGroup and Target tags are added according to https://github.com/aspnet/Hosting/issues/959#issuecomment-286351703 -->
<!-- Solves Problem#2 (404 when executing service calls hosted in other assemblies) -->
<!-- https://github.com/Microsoft/vstest/issues/196.-->
<ItemGroup>
<None Update="xunit.runner.json">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
</ItemGroup>
<!-- https://github.com/NuGet/Home/issues/4412. -->
<Target Name="CopyDepsFiles" AfterTargets="Build" Condition="'$(TargetFramework)'!=''">
<ItemGroup>
<DepsFilePaths Include="$([System.IO.Path]::ChangeExtension('%(_ResolvedProjectReferencePaths.FullPath)', '.deps.json'))" />
</ItemGroup>
<Copy SourceFiles="%(DepsFilePaths.FullPath)" DestinationFolder="$(OutputPath)" Condition="Exists('%(DepsFilePaths.FullPath)')" />
</Target>
</Project>

@ -9,5 +9,10 @@ namespace Volo.Abp.AspNetCore.App
{
return Content("Index-Result");
}
public ActionResult About()
{
return View();
}
}
}

@ -1,9 +1,43 @@
using System;
using System.IO;
using System.Linq;
using Microsoft.AspNetCore.Hosting;
using Volo.Abp.AspNetCore.App;
namespace Volo.Abp.AspNetCore.Mvc
{
public abstract class AspNetCoreMvcTestBase : AbpAspNetCoreTestBase<Startup>
{
protected override IWebHostBuilder CreateWebHostBuilder()
{
var contentRootPath = CalculateContentRootPath(
"Volo.Abp.AspNetCore.Mvc.Tests.csproj",
string.Format(
"Volo{0}Abp{0}AspNetCore{0}App",
Path.DirectorySeparatorChar
)
);
return base.CreateWebHostBuilder()
.UseContentRoot(contentRootPath);
}
private string CalculateContentRootPath(string projectFileName, string contentPath)
{
var currentDirectory = Directory.GetCurrentDirectory();
while (!ContainsFile(currentDirectory, projectFileName))
{
currentDirectory = new DirectoryInfo(currentDirectory).Parent.FullName;
}
return Path.Combine(currentDirectory, contentPath);
}
private bool ContainsFile(string currentDirectory, string projectFileName)
{
return Directory
.GetFiles(currentDirectory, "*.*", SearchOption.TopDirectoryOnly)
.Any(f => Path.GetFileName(f) == projectFileName);
}
}
}

@ -8,7 +8,7 @@ namespace Volo.Abp.AspNetCore.Mvc
public class SimpleController_Tests : AspNetCoreMvcTestBase
{
[Fact]
public async Task ActionResult_Return_Type_ContentResult_Return_Value()
public async Task ActionResult_ContentResult()
{
var result = await GetResponseAsStringAsync(
GetUrl<SimpleController>(nameof(SimpleController.Index))
@ -16,5 +16,15 @@ namespace Volo.Abp.AspNetCore.Mvc
result.ShouldBe("Index-Result");
}
[Fact]
public async Task ActionResult_ViewResult()
{
var result = await GetResponseAsStringAsync(
GetUrl<SimpleController>(nameof(SimpleController.About))
);
result.Trim().ShouldBe("<h2>About</h2>");
}
}
}

Loading…
Cancel
Save