-
-
Notifications
You must be signed in to change notification settings - Fork 287
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
docs: Add in process WeatherForecast example
- Loading branch information
1 parent
4dab255
commit 1ce11d3
Showing
10 changed files
with
130 additions
and
2 deletions.
There are no files selected for viewing
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,6 @@ | ||
# Autodetect text files | ||
* text=auto | ||
|
||
# Definitively text files | ||
*.cs text | ||
*.cake text | ||
|
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
.idea | ||
.vs | ||
bin | ||
build | ||
bin | ||
obj |
This file contains 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
This file contains 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
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -40,3 +40,7 @@ | |
app.MapBlazorHub(); | ||
app.MapFallbackToPage("/_Host"); | ||
app.Run(); | ||
|
||
public sealed partial class Program | ||
{ | ||
} |
This file contains 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
17 changes: 17 additions & 0 deletions
17
...eatherForecast/tests/WeatherForecast.InProcess.Test/WeatherForecast.InProcess.Test.csproj
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
<Project Sdk="Microsoft.NET.Sdk"> | ||
<Sdk Name="Microsoft.Build.CentralPackageVersions" Version="2.1.3"/> | ||
<PropertyGroup> | ||
<TargetFramework>net6.0</TargetFramework> | ||
</PropertyGroup> | ||
<ItemGroup> | ||
<PackageReference Include="JetBrains.Annotations"/> | ||
<PackageReference Include="Microsoft.AspNetCore.Mvc.Testing"/> | ||
<PackageReference Include="Microsoft.NET.Test.Sdk"/> | ||
<PackageReference Include="xunit.runner.visualstudio"/> | ||
<PackageReference Include="xunit"/> | ||
</ItemGroup> | ||
<ItemGroup> | ||
<ProjectReference Include="../../../../src/Testcontainers/Testcontainers.csproj"/> | ||
<ProjectReference Include="$(SolutionDir)src/WeatherForecast/WeatherForecast.csproj"/> | ||
</ItemGroup> | ||
</Project> |
79 changes: 79 additions & 0 deletions
79
examples/WeatherForecast/tests/WeatherForecast.InProcess.Test/WeatherForecastTest.cs
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,79 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Net; | ||
using System.Net.Http; | ||
using System.Text.Json; | ||
using System.Threading.Tasks; | ||
using DotNet.Testcontainers.Builders; | ||
using DotNet.Testcontainers.Configurations; | ||
using DotNet.Testcontainers.Containers; | ||
using JetBrains.Annotations; | ||
using Microsoft.AspNetCore.Mvc.Testing; | ||
using WeatherForecast.Entities; | ||
using Xunit; | ||
|
||
namespace WeatherForecast.InProcess.Test; | ||
|
||
[UsedImplicitly] | ||
public sealed class WeatherForecastTest : IAsyncLifetime | ||
{ | ||
private readonly MsSqlTestcontainer _mssqlContainer; | ||
|
||
public WeatherForecastTest() | ||
{ | ||
var mssqlConfiguration = new MsSqlTestcontainerConfiguration(); | ||
mssqlConfiguration.Password = Guid.NewGuid().ToString("D"); | ||
mssqlConfiguration.Database = Guid.NewGuid().ToString("D"); | ||
|
||
_mssqlContainer = new TestcontainersBuilder<MsSqlTestcontainer>() | ||
.WithDatabase(mssqlConfiguration) | ||
.Build(); | ||
} | ||
|
||
public Task InitializeAsync() | ||
{ | ||
return _mssqlContainer.StartAsync(); | ||
} | ||
|
||
public Task DisposeAsync() | ||
{ | ||
return _mssqlContainer.DisposeAsync().AsTask(); | ||
} | ||
|
||
public sealed class Api : IClassFixture<WeatherForecastTest> | ||
{ | ||
private readonly HttpClient _httpClient; | ||
|
||
public Api(WeatherForecastTest weatherForecastTest) | ||
{ | ||
Environment.SetEnvironmentVariable("ASPNETCORE_URLS", "https://+"); | ||
Environment.SetEnvironmentVariable("ASPNETCORE_Kestrel__Certificates__Default__Path", "certificate.crt"); | ||
Environment.SetEnvironmentVariable("ASPNETCORE_Kestrel__Certificates__Default__Password", "password"); | ||
Environment.SetEnvironmentVariable("ConnectionStrings__DefaultConnection", weatherForecastTest._mssqlContainer.ConnectionString); | ||
_httpClient = new WebApplicationFactory<Program>().CreateClient(); | ||
} | ||
|
||
[Fact] | ||
[Trait("Category", nameof(Api))] | ||
public async Task Get_WeatherForecast_ReturnsSevenDays() | ||
{ | ||
// Given | ||
const string path = "api/WeatherForecast"; | ||
|
||
// When | ||
var response = await _httpClient.GetAsync(path) | ||
.ConfigureAwait(false); | ||
|
||
var weatherForecastStream = await response.Content.ReadAsStreamAsync() | ||
.ConfigureAwait(false); | ||
|
||
var weatherForecast = await JsonSerializer.DeserializeAsync<IEnumerable<WeatherData>>(weatherForecastStream) | ||
.ConfigureAwait(false); | ||
|
||
// Then | ||
Assert.Equal(HttpStatusCode.OK, response.StatusCode); | ||
Assert.Equal(7, weatherForecast!.Count()); | ||
} | ||
} | ||
} |
This file contains 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