Created
January 31, 2018 08:09
-
-
Save dany1468/4841beec8109ba84999a7e939e28a066 to your computer and use it in GitHub Desktop.
ASP.NET Core MVC 2.0 時点での xUnit と Microsoft.AspNetCore.TestHost を利用した Integration Test で気をつける点 ref: https://qiita.com/dany1468/items/ceffb14738342d296839
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| public class PrimeWebDefaultRequestShould | |
| { | |
| private readonly TestServer _server; | |
| private readonly HttpClient _client; | |
| public PrimeWebDefaultRequestShould() | |
| { | |
| // Arrange | |
| _server = new TestServer(new WebHostBuilder() | |
| .UseStartup<Startup>()); | |
| _client = _server.CreateClient(); | |
| } | |
| [Fact] | |
| public async Task ReturnHelloWorld() | |
| { | |
| // Act | |
| var response = await _client.GetAsync("/"); | |
| response.EnsureSuccessStatusCode(); | |
| var responseString = await response.Content.ReadAsStringAsync(); | |
| // Assert | |
| Assert.Equal("Hello World!", | |
| responseString); | |
| } | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| var asm = typeof(Startup).Assembly.GetName().Name; | |
| string appRootPath = Path.GetFullPath(Path.Combine( | |
| AppContext.BaseDirectory, | |
| "..", "..", "..", "..", asm)); | |
| _server = new TestServer(new WebHostBuilder() | |
| .UseContentRoot(appRootPath) // 💡 これを追加 | |
| .UseStartup<Startup>()); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <Target Name="CopyAditionalFiles" 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> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment