-
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
Mathieu Gamache
committed
Dec 20, 2023
1 parent
2e14be5
commit c63ae7f
Showing
6 changed files
with
123 additions
and
0 deletions.
There are no files selected for viewing
36 changes: 36 additions & 0 deletions
36
src/tests/WebApi.MsBuild.SystemTest.ContractFirst/Controllers/WeatherForecastController.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,36 @@ | ||
using Microsoft.AspNetCore.Mvc; | ||
|
||
namespace WebApi.MsBuild.SystemTest.Controllers; | ||
|
||
[ApiController] | ||
[Route("[controller]")] | ||
[Produces("application/json")] | ||
[ApiExplorerSettings(GroupName = "v1")] | ||
public class WeatherForecastController : ControllerBase | ||
{ | ||
private static readonly string[] Summaries = new[] | ||
{ | ||
"Freezing", "Bracing", "Chilly", "Cool", "Mild", "Warm", "Balmy", "Hot", "Sweltering", "Scorching", | ||
}; | ||
|
||
private readonly ILogger<WeatherForecastController> _logger; | ||
|
||
public WeatherForecastController(ILogger<WeatherForecastController> logger) | ||
{ | ||
this._logger = logger; | ||
} | ||
|
||
[HttpGet(Name = "GetWeatherForecast")] | ||
[ProducesResponseType(StatusCodes.Status200OK)] | ||
[ProducesResponseType(StatusCodes.Status403Forbidden)] | ||
public IEnumerable<WeatherForecast> Get() | ||
{ | ||
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(); | ||
} | ||
} |
30 changes: 30 additions & 0 deletions
30
src/tests/WebApi.MsBuild.SystemTest.ContractFirst/Controllers/WeatherManagementController.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,30 @@ | ||
using Microsoft.AspNetCore.Mvc; | ||
|
||
namespace WebApi.MsBuild.SystemTest.Controllers; | ||
|
||
[ApiController] | ||
[Route("[controller]")] | ||
[Produces("application/json")] | ||
[ApiExplorerSettings(GroupName = "v1-management")] | ||
public class WeatherManagementController : ControllerBase | ||
{ | ||
private static readonly string[] Sources = | ||
{ | ||
"Accuweather", "AerisWeather", "Foreca", "Open Weathermap", "National Oceanic and Atmospheric Administration", | ||
}; | ||
|
||
private readonly ILogger<WeatherManagementController> _logger; | ||
|
||
public WeatherManagementController(ILogger<WeatherManagementController> logger) | ||
{ | ||
this._logger = logger; | ||
} | ||
|
||
[HttpGet(Name = "GetWeatherSources")] | ||
[ProducesResponseType(StatusCodes.Status200OK)] | ||
[ProducesResponseType(StatusCodes.Status403Forbidden)] | ||
public IEnumerable<string> Get() | ||
{ | ||
return Sources; | ||
} | ||
} |
28 changes: 28 additions & 0 deletions
28
src/tests/WebApi.MsBuild.SystemTest.ContractFirst/Program.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,28 @@ | ||
using Microsoft.OpenApi.Models; | ||
|
||
var builder = WebApplication.CreateBuilder(args); | ||
|
||
builder.Services.AddControllers(); | ||
builder.Services.AddEndpointsApiExplorer(); | ||
builder.Services.AddSwaggerGen(c => | ||
{ | ||
c.SwaggerDoc("v1", new OpenApiInfo { Title = "V1 API General", Version = "v1" }); | ||
c.SwaggerDoc("v1-management", new OpenApiInfo { Title = "V1 API management", Version = "v1-management" }); | ||
}); | ||
|
||
var app = builder.Build(); | ||
|
||
app.UseSwagger(); | ||
app.UseSwaggerUI(options => | ||
{ | ||
options.SwaggerEndpoint("v1/swagger.json", "v1"); | ||
options.SwaggerEndpoint("v1-management/swagger.json", "v1-management"); | ||
}); | ||
|
||
app.UseHttpsRedirection(); | ||
|
||
app.UseAuthorization(); | ||
|
||
app.MapControllers(); | ||
|
||
app.Run(); |
12 changes: 12 additions & 0 deletions
12
src/tests/WebApi.MsBuild.SystemTest.ContractFirst/WeatherForecast.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,12 @@ | ||
namespace WebApi.MsBuild.SystemTest; | ||
|
||
public class WeatherForecast | ||
{ | ||
public DateTime Date { get; set; } | ||
|
||
public int TemperatureC { get; init; } | ||
|
||
public int TemperatureF => 32 + (int)(this.TemperatureC / 0.5556); | ||
|
||
public string? Summary { get; set; } | ||
} |
8 changes: 8 additions & 0 deletions
8
src/tests/WebApi.MsBuild.SystemTest.ContractFirst/appsettings.Development.json
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 @@ | ||
{ | ||
"Logging": { | ||
"LogLevel": { | ||
"Default": "Information", | ||
"Microsoft.AspNetCore": "Warning" | ||
} | ||
} | ||
} |
9 changes: 9 additions & 0 deletions
9
src/tests/WebApi.MsBuild.SystemTest.ContractFirst/appsettings.json
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,9 @@ | ||
{ | ||
"Logging": { | ||
"LogLevel": { | ||
"Default": "Information", | ||
"Microsoft.AspNetCore": "Warning" | ||
} | ||
}, | ||
"AllowedHosts": "*" | ||
} |