-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add docker compose project and tests
- Loading branch information
Showing
12 changed files
with
251 additions
and
31 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
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
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,19 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<Project ToolsVersion="15.0" Sdk="Microsoft.Docker.Sdk"> | ||
<PropertyGroup Label="Globals"> | ||
<ProjectVersion>2.1</ProjectVersion> | ||
<DockerTargetOS>Linux</DockerTargetOS> | ||
<DockerPublishLocally>False</DockerPublishLocally> | ||
<ProjectGuid>69bc9238-50ac-4f4c-b884-717f1e75493f</ProjectGuid> | ||
<DockerLaunchAction>LaunchBrowser</DockerLaunchAction> | ||
<DockerServiceUrl>{Scheme}://localhost:{ServicePort}/swagger</DockerServiceUrl> | ||
<DockerServiceName>webapi</DockerServiceName> | ||
</PropertyGroup> | ||
<ItemGroup> | ||
<None Include="docker-compose.override.yml"> | ||
<DependentUpon>docker-compose.yml</DependentUpon> | ||
</None> | ||
<None Include="docker-compose.yml" /> | ||
<None Include=".dockerignore" /> | ||
</ItemGroup> | ||
</Project> |
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,14 @@ | ||
version: '3.4' | ||
|
||
services: | ||
webapi: | ||
environment: | ||
- ASPNETCORE_ENVIRONMENT=Development | ||
- ASPNETCORE_HTTP_PORTS=8080 | ||
- ASPNETCORE_HTTPS_PORTS=8081 | ||
ports: | ||
- "8080" | ||
- "8081" | ||
volumes: | ||
- ${APPDATA}/Microsoft/UserSecrets:/home/app/.microsoft/usersecrets:ro | ||
- ${APPDATA}/ASP.NET/Https:/home/app/.aspnet/https:ro |
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,8 @@ | ||
version: '3.4' | ||
|
||
services: | ||
webapi: | ||
image: ${DOCKER_REGISTRY-}webapi | ||
build: | ||
context: . | ||
dockerfile: WebApi/Dockerfile |
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,11 @@ | ||
{ | ||
"profiles": { | ||
"Docker Compose": { | ||
"commandName": "DockerCompose", | ||
"commandVersion": "1.0", | ||
"serviceActions": { | ||
"webapi": "StartDebugging" | ||
} | ||
} | ||
} | ||
} |
119 changes: 119 additions & 0 deletions
119
tests/backend/WebApi.Tests/Controllers/WeatherForecastControllerTests.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,119 @@ | ||
using Microsoft.AspNetCore.Mvc; | ||
using Microsoft.Extensions.Logging; | ||
using Moq; | ||
using WebApi.Controllers; | ||
using WebApi.Entities; | ||
|
||
namespace WebApi.Tests.Controllers; | ||
|
||
[TestFixture] | ||
public class WeatherForecastControllerTests | ||
{ | ||
[SetUp] | ||
public void SetUp() | ||
{ | ||
_loggerMock = new Mock<ILogger<WeatherForecastController>>(); | ||
_controller = new WeatherForecastController(_loggerMock.Object); | ||
} | ||
private Mock<ILogger<WeatherForecastController>> _loggerMock; | ||
private WeatherForecastController _controller; | ||
|
||
[Test] | ||
public async Task Get_ReturnsOkResult() | ||
{ | ||
// Act | ||
var result = await _controller.Get(); | ||
|
||
// Assert | ||
Assert.IsInstanceOf<ActionResult<IEnumerable<WeatherForecast>>>(result); | ||
Assert.IsInstanceOf<OkObjectResult>(result.Result); | ||
} | ||
|
||
[Test] | ||
public async Task Get_ReturnsFiveWeatherForecasts() | ||
{ | ||
// Act | ||
var result = await _controller.Get(); | ||
|
||
// Assert | ||
Assert.NotNull(result.Result); | ||
Assert.IsAssignableFrom<OkObjectResult>(result.Result); | ||
var okResult = (OkObjectResult) result.Result; | ||
Assert.NotNull(okResult.Value); | ||
Assert.IsAssignableFrom<WeatherForecast[]>(okResult.Value); | ||
Assert.That(((WeatherForecast[]) okResult.Value).Count(), Is.EqualTo(5)); | ||
} | ||
|
||
[Test] | ||
public async Task Get_ReturnsWeatherForecastsWithCorrectProperties() | ||
{ | ||
// Act | ||
var result = await _controller.Get(); | ||
|
||
// Assert | ||
Assert.NotNull(result.Result); | ||
Assert.IsAssignableFrom<OkObjectResult>(result.Result); | ||
var okResult = (OkObjectResult) result.Result; | ||
Assert.NotNull(okResult.Value); | ||
Assert.IsAssignableFrom<WeatherForecast[]>(okResult.Value); | ||
foreach (var weatherForecast in (WeatherForecast[]) okResult.Value) | ||
{ | ||
Assert.IsInstanceOf<DateOnly>(weatherForecast.Date); | ||
Assert.IsInstanceOf<int>(weatherForecast.TemperatureC); | ||
Assert.IsInstanceOf<string>(weatherForecast.Summary); | ||
} | ||
} | ||
|
||
[Test] | ||
public async Task Get_LogsInformationMessage() | ||
{ | ||
// Act | ||
await _controller.Get(); | ||
|
||
// Assert | ||
_loggerMock.Verify(static x => x.LogInformation(It.IsAny<string>()), Times.Once); | ||
} | ||
} | ||
|
||
/*using Microsoft.AspNetCore.Mvc; | ||
using Microsoft.Extensions.Logging; | ||
using Moq; | ||
using WebApi.Controllers; | ||
using WebApi.Entities; | ||
namespace WebApi.Tests.Controllers; | ||
public class WeatherForecastControllerTests | ||
{ | ||
private ILogger<WeatherForecastController> _logger; | ||
private WeatherForecastController _controller; | ||
[SetUp] | ||
public void Setup() | ||
{ | ||
_logger = Mock.Of<ILogger<WeatherForecastController>>(); | ||
_controller = new WeatherForecastController(_logger); | ||
} | ||
[Test] | ||
public async Task Get_ReturnsExpectedWeatherForecast() | ||
{ | ||
// Act | ||
var result = await _controller.Get(); | ||
// Assert | ||
Assert.IsInstanceOf<ActionResult<IEnumerable<WeatherForecast>>>(result); | ||
Assert.IsInstanceOf<IEnumerable<WeatherForecast>>(result.Value); | ||
Assert.IsNotNull(result.Value); | ||
Assert.That(((IEnumerable<WeatherForecast>) result.Value).Count(), Is.EqualTo(5)); | ||
foreach (var weatherForecast in result.Value) | ||
{ | ||
Assert.IsInstanceOf<DateOnly>(weatherForecast.Date); | ||
Assert.IsInstanceOf<int>(weatherForecast.TemperatureC); | ||
Assert.IsInstanceOf<string>(weatherForecast.Summary); | ||
} | ||
//Mock.Get(_logger).Verify(static x => x.Log<>(It.IsAny<ILogger>(), It.IsAny<LogLevel>(), default, default), Times.Once()); | ||
} | ||
}*/ |
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,24 +1,25 @@ | ||
<Project Sdk="Microsoft.NET.Sdk"> | ||
|
||
<PropertyGroup> | ||
<IsPackable>false</IsPackable> | ||
<IsTestProject>true</IsTestProject> | ||
</PropertyGroup> | ||
<PropertyGroup> | ||
<IsPackable>false</IsPackable> | ||
<IsTestProject>true</IsTestProject> | ||
</PropertyGroup> | ||
|
||
<ItemGroup> | ||
<PackageReference Include="coverlet.collector" Version="6.0.0" /> | ||
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.8.0" /> | ||
<PackageReference Include="NUnit" Version="3.14.0" /> | ||
<PackageReference Include="NUnit.Analyzers" Version="3.9.0" /> | ||
<PackageReference Include="NUnit3TestAdapter" Version="4.5.0" /> | ||
</ItemGroup> | ||
<ItemGroup> | ||
<PackageReference Include="coverlet.collector" Version="6.0.0"/> | ||
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.8.0"/> | ||
<PackageReference Include="Moq" Version="4.20.70"/> | ||
<PackageReference Include="NUnit" Version="3.14.0"/> | ||
<PackageReference Include="NUnit.Analyzers" Version="3.9.0"/> | ||
<PackageReference Include="NUnit3TestAdapter" Version="4.5.0"/> | ||
</ItemGroup> | ||
|
||
<ItemGroup> | ||
<ProjectReference Include="..\..\..\src\backend\WebApi\WebApi.csproj" /> | ||
</ItemGroup> | ||
<ItemGroup> | ||
<ProjectReference Include="..\..\..\src\backend\WebApi\WebApi.csproj"/> | ||
</ItemGroup> | ||
|
||
<ItemGroup> | ||
<Using Include="NUnit.Framework" /> | ||
</ItemGroup> | ||
<ItemGroup> | ||
<Using Include="NUnit.Framework"/> | ||
</ItemGroup> | ||
|
||
</Project> |
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