-
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.
- Loading branch information
Braga Lund
committed
Nov 26, 2021
1 parent
7de87a2
commit 5a60b4a
Showing
12 changed files
with
139 additions
and
66 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
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,34 @@ | ||
using System.Net; | ||
using System.Threading.Tasks; | ||
using Microsoft.AspNetCore.Mvc.Testing; | ||
using Microsoft.Extensions.Hosting; | ||
using Microsoft.VisualStudio.TestPlatform.TestHost; | ||
using Xunit; | ||
|
||
namespace bragapi_tests.Controllers | ||
{ | ||
public class SwaggerTests | ||
{ | ||
[Fact] | ||
public async Task GetSwaggerUI_Returns_OK() | ||
{ | ||
await using var application = new BragaApiApplication(); | ||
|
||
var client = application.CreateClient(); | ||
var response = await client.GetAsync("/swagger/index.html"); | ||
|
||
Assert.Equal(HttpStatusCode.OK, response.StatusCode); | ||
} | ||
|
||
class BragaApiApplication : WebApplicationFactory<Program> | ||
{ | ||
protected override IHost CreateHost(IHostBuilder builder) | ||
{ | ||
// Add mock/test services to the builder here | ||
builder.ConfigureServices(services => { }); | ||
|
||
return base.CreateHost(builder); | ||
} | ||
} | ||
} | ||
} |
35 changes: 35 additions & 0 deletions
35
backend/bragapi-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,35 @@ | ||
using System.Net; | ||
using System.Threading.Tasks; | ||
using Microsoft.AspNetCore.Mvc.Testing; | ||
using Microsoft.Extensions.Hosting; | ||
using Microsoft.VisualStudio.TestPlatform.TestHost; | ||
using Xunit; | ||
|
||
namespace bragapi_tests.Controllers | ||
{ | ||
public class WeatherForecastControllerTests | ||
{ | ||
|
||
[Fact] | ||
public async Task GetWeatherForecast_WhenRequested_ShouldReturnArray() | ||
{ | ||
await using var application = new BragaApiApplication(); | ||
|
||
var client = application.CreateClient(); | ||
var response = await client.GetAsync("/WeatherForecast"); | ||
|
||
Assert.Equal(HttpStatusCode.OK, response.StatusCode); | ||
} | ||
class BragaApiApplication : WebApplicationFactory<Program> | ||
{ | ||
protected override IHost CreateHost(IHostBuilder builder) | ||
{ | ||
// Add mock/test services to the builder here | ||
builder.ConfigureServices(services => { }); | ||
|
||
return base.CreateHost(builder); | ||
} | ||
} | ||
|
||
} | ||
} |
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,12 +1,14 @@ | ||
using Xunit; | ||
|
||
namespace bragapi_tests; | ||
|
||
public class UnitTest1 | ||
namespace bragapi_tests | ||
{ | ||
[Fact] | ||
public void Test1() | ||
|
||
public class UnitTest1 | ||
{ | ||
[Fact] | ||
public void Test1() | ||
{ | ||
|
||
} | ||
} | ||
} |
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 |
---|---|---|
@@ -1,32 +1,37 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using Microsoft.AspNetCore.Mvc; | ||
using Microsoft.Extensions.Logging; | ||
|
||
namespace bragapi.Controllers; | ||
|
||
[ApiController] | ||
[Route("[controller]")] | ||
public class WeatherForecastController : ControllerBase | ||
namespace bragapi.Controllers | ||
{ | ||
private static readonly string[] Summaries = new[] | ||
[ApiController] | ||
[Route("[controller]")] | ||
public class WeatherForecastController : ControllerBase | ||
{ | ||
"Freezing", "Bracing", "Chilly", "Cool", "Mild", "Warm", "Balmy", "Hot", "Sweltering", "Scorching" | ||
}; | ||
private static readonly string[] Summaries = | ||
{ | ||
"Freezing", "Bracing", "Chilly", "Cool", "Mild", "Warm", "Balmy", "Hot", "Sweltering", "Scorching" | ||
}; | ||
|
||
private readonly ILogger<WeatherForecastController> _logger; | ||
private readonly ILogger<WeatherForecastController> _logger; | ||
|
||
public WeatherForecastController(ILogger<WeatherForecastController> logger) | ||
{ | ||
_logger = logger; | ||
} | ||
public WeatherForecastController(ILogger<WeatherForecastController> logger) | ||
{ | ||
_logger = logger; | ||
} | ||
|
||
[HttpGet(Name = "GetWeatherForecast")] | ||
public IEnumerable<WeatherForecast> Get() | ||
{ | ||
return Enumerable.Range(1, 5).Select(index => new WeatherForecast | ||
[HttpGet(Name = "GetWeatherForecast")] | ||
public IEnumerable<WeatherForecast> Get() | ||
{ | ||
Date = DateTime.Now.AddDays(index), | ||
TemperatureC = Random.Shared.Next(-20, 55), | ||
Summary = Summaries[Random.Shared.Next(Summaries.Length)] | ||
}) | ||
.ToArray(); | ||
return Enumerable.Range(1, 5).Select(index => new WeatherForecast | ||
{ | ||
Date = DateTime.Now.AddDays(index), | ||
TemperatureC = Random.Shared.Next(-20, 55), | ||
Summary = Summaries[Random.Shared.Next(Summaries.Length)] | ||
}) | ||
.ToArray(); | ||
} | ||
} | ||
} | ||
} |
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 |
---|---|---|
@@ -1,12 +1,16 @@ | ||
namespace bragapi; | ||
using System; | ||
|
||
public class WeatherForecast | ||
namespace bragapi | ||
{ | ||
public DateTime Date { get; set; } | ||
|
||
public int TemperatureC { get; set; } | ||
public class WeatherForecast | ||
{ | ||
public DateTime Date { get; set; } | ||
|
||
public int TemperatureF => 32 + (int)(TemperatureC / 0.5556); | ||
public int TemperatureC { get; set; } | ||
|
||
public string? Summary { get; set; } | ||
} | ||
public int TemperatureF => 32 + (int)(TemperatureC / 0.5556); | ||
|
||
public string? Summary { get; set; } | ||
} | ||
} |
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,13 +1,17 @@ | ||
<Project Sdk="Microsoft.NET.Sdk.Web"> | ||
|
||
<PropertyGroup> | ||
<TargetFramework>net6.0</TargetFramework> | ||
<Nullable>enable</Nullable> | ||
<ImplicitUsings>enable</ImplicitUsings> | ||
</PropertyGroup> | ||
|
||
<ItemGroup> | ||
<PackageReference Include="Swashbuckle.AspNetCore" Version="6.2.3" /> | ||
</ItemGroup> | ||
<PropertyGroup> | ||
<TargetFramework>net6.0</TargetFramework> | ||
<Nullable>enable</Nullable> | ||
<ImplicitUsings>enable</ImplicitUsings> | ||
</PropertyGroup> | ||
|
||
<ItemGroup> | ||
<PackageReference Include="Swashbuckle.AspNetCore" Version="6.2.3"/> | ||
</ItemGroup> | ||
|
||
<ItemGroup> | ||
<InternalsVisibleTo Include="bragapi-tests" /> | ||
</ItemGroup> | ||
|
||
</Project> |