Skip to content

Commit

Permalink
Upgrade to .net 8.0
Browse files Browse the repository at this point in the history
  • Loading branch information
aimenux committed Mar 5, 2024
1 parent 1b5afc9 commit c2cbab5
Show file tree
Hide file tree
Showing 15 changed files with 66 additions and 73 deletions.
6 changes: 3 additions & 3 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,11 @@ jobs:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4
- name: Setup .NET
uses: actions/setup-dotnet@v3
uses: actions/setup-dotnet@v4
with:
dotnet-version: 7.0.x
dotnet-version: 8.0.x
- name: Restore dependencies
run: dotnet restore
- name: Build
Expand Down
1 change: 1 addition & 0 deletions ModelBindingDemo.sln
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "SolutionFiles", "SolutionFi
ProjectSection(SolutionItems) = preProject
.github\workflows\ci.yml = .github\workflows\ci.yml
README.md = README.md
global.json = global.json
EndProjectSection
EndProject
Global
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,4 @@ In this repo, i m using various model binding ways in web api projects
>
> :two: `Example02` use [model binding with minimal api](https://learn.microsoft.com/en-us/aspnet/core/fundamentals/minimal-apis/parameter-binding)
>
**`Tools`** : net 7.0, web api, integration-testing, fluent-assertions
**`Tools`** : net 8.0, web api, integration-testing, fluent-assertions
4 changes: 1 addition & 3 deletions global.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
{
"sdk": {
"version": "7.0.400",
"allowPrerelease": false,
"rollForward": "latestFeature"
"allowPrerelease": false
}
}
5 changes: 2 additions & 3 deletions src/Example01/Controllers/ApiController.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
using Example01.Binders;
using Example01.Payloads;
using Microsoft.AspNetCore.Mvc;
using Microsoft.Extensions.Internal;

namespace Example01.Controllers;

Expand Down Expand Up @@ -54,11 +53,11 @@ public IActionResult List([FromQuery] ApiQuery query)
}

[HttpGet("date")]
public IActionResult Date([FromServices] ISystemClock systemClock)
public IActionResult Date([FromServices] TimeProvider timeProvider)
{
var response = new
{
UtcNow = systemClock.UtcNow,
UtcNow = timeProvider.GetUtcNow(),
Source = "FromServices"
};
return Ok(response);
Expand Down
4 changes: 2 additions & 2 deletions src/Example01/Example01.csproj
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
<Project Sdk="Microsoft.NET.Sdk.Web">

<PropertyGroup>
<TargetFramework>net7.0</TargetFramework>
<TargetFramework>net8.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Microsoft.AspNetCore.OpenApi" Version="7.0.10" />
<PackageReference Include="Microsoft.AspNetCore.OpenApi" Version="8.0.2" />
<PackageReference Include="Swashbuckle.AspNetCore" Version="6.5.0" />
</ItemGroup>

Expand Down
4 changes: 1 addition & 3 deletions src/Example01/Program.cs
Original file line number Diff line number Diff line change
@@ -1,11 +1,9 @@
using Microsoft.Extensions.Internal;

var builder = WebApplication.CreateBuilder(args);

builder.Services.AddControllers();
builder.Services.AddEndpointsApiExplorer();
builder.Services.AddSwaggerGen();
builder.Services.AddSingleton<ISystemClock, SystemClock>();
builder.Services.AddSingleton(TimeProvider.System);

var app = builder.Build();

Expand Down
4 changes: 2 additions & 2 deletions src/Example02/Example02.csproj
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
<Project Sdk="Microsoft.NET.Sdk.Web">

<PropertyGroup>
<TargetFramework>net7.0</TargetFramework>
<TargetFramework>net8.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Microsoft.AspNetCore.OpenApi" Version="7.0.10" />
<PackageReference Include="Microsoft.AspNetCore.OpenApi" Version="8.0.2" />
<PackageReference Include="Swashbuckle.AspNetCore" Version="6.5.0" />
</ItemGroup>

Expand Down
7 changes: 3 additions & 4 deletions src/Example02/Program.cs
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
using Example02.Binders;
using Example02.Payloads;
using Microsoft.AspNetCore.Mvc;
using Microsoft.Extensions.Internal;

var builder = WebApplication.CreateBuilder(args);

builder.Services.AddEndpointsApiExplorer();
builder.Services.AddSwaggerGen();
builder.Services.AddSingleton<ISystemClock, SystemClock>();
builder.Services.AddSingleton(TimeProvider.System);

var app = builder.Build();

Expand Down Expand Up @@ -75,11 +74,11 @@
});

app
.MapGet("api/date", ([FromServices] ISystemClock systemClock) =>
.MapGet("api/date", ([FromServices] TimeProvider timeProvider) =>
{
var response = new
{
UtcNow = systemClock.UtcNow,
UtcNow = timeProvider.GetUtcNow(),
Source = "FromQuery"
};
return Results.Ok(response);
Expand Down
12 changes: 6 additions & 6 deletions test/Example01.Tests/Example01.Tests.csproj
Original file line number Diff line number Diff line change
@@ -1,22 +1,22 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>net7.0</TargetFramework>
<TargetFramework>net8.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<IsPackable>false</IsPackable>
<IsTestProject>true</IsTestProject>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="FluentAssertions" Version="6.12.0" />
<PackageReference Include="Microsoft.AspNetCore.Mvc.Testing" Version="7.0.12" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.6.0" />
<PackageReference Include="xunit" Version="2.4.2" />
<PackageReference Include="xunit.runner.visualstudio" Version="2.4.5">
<PackageReference Include="Microsoft.AspNetCore.Mvc.Testing" Version="8.0.2" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.9.0" />
<PackageReference Include="xunit" Version="2.7.0" />
<PackageReference Include="xunit.runner.visualstudio" Version="2.5.7">
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
<PrivateAssets>all</PrivateAssets>
</PackageReference>
<PackageReference Include="coverlet.collector" Version="3.2.0">
<PackageReference Include="coverlet.collector" Version="6.0.1">
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
<PrivateAssets>all</PrivateAssets>
</PackageReference>
Expand Down
36 changes: 18 additions & 18 deletions test/Example01.Tests/IntegrationTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@ public class IntegrationTests
public async Task Get_Route_Should_Return_Success_Response(int id)
{
// arrange
var fixture = new WebApiTestFixture();
var client = fixture.CreateClient();
var factory = new IntegrationWebApplicationFactory();
var client = factory.CreateClient();

// act
var response = await client.GetAsync($"/api/{id}");
Expand All @@ -29,8 +29,8 @@ public async Task Get_Route_Should_Return_Success_Response(int id)
public async Task Trace_Route_Should_Return_Success_Response()
{
// arrange
var fixture = new WebApiTestFixture();
var client = fixture.CreateClient();
var factory = new IntegrationWebApplicationFactory();
var client = factory.CreateClient();

// act
var response = await client
Expand All @@ -47,8 +47,8 @@ public async Task Trace_Route_Should_Return_Success_Response()
public async Task Search_Route_Should_Return_Success_Response()
{
// arrange
var fixture = new WebApiTestFixture();
var client = fixture.CreateClient();
var factory = new IntegrationWebApplicationFactory();
var client = factory.CreateClient();

// act
var response = await client.GetAsync("api/search?keyword=xyz");
Expand All @@ -63,8 +63,8 @@ public async Task Search_Route_Should_Return_Success_Response()
public async Task List_Route_Should_Return_Success_Response()
{
// arrange
var fixture = new WebApiTestFixture();
var client = fixture.CreateClient();
var factory = new IntegrationWebApplicationFactory();
var client = factory.CreateClient();

// act
var response = await client.GetAsync("api/list?take=50&skip=10");
Expand All @@ -79,8 +79,8 @@ public async Task List_Route_Should_Return_Success_Response()
public async Task Date_Route_Should_Return_Success_Response()
{
// arrange
var fixture = new WebApiTestFixture();
var client = fixture.CreateClient();
var factory = new IntegrationWebApplicationFactory();
var client = factory.CreateClient();

// act
var response = await client.GetAsync(@"api/date");
Expand All @@ -103,8 +103,8 @@ public async Task Date_Route_Should_Return_Success_Response()
public async Task Custom_Route_Should_Return_Success_Response(string answer)
{
// arrange
var fixture = new WebApiTestFixture();
var client = fixture.CreateClient();
var factory = new IntegrationWebApplicationFactory();
var client = factory.CreateClient();

// act
var response = await client.GetAsync($"api/custom?answer={answer}");
Expand All @@ -119,8 +119,8 @@ public async Task Custom_Route_Should_Return_Success_Response(string answer)
public async Task Post_Route_Should_Return_Success_Response()
{
// arrange
var fixture = new WebApiTestFixture();
var client = fixture.CreateClient();
var factory = new IntegrationWebApplicationFactory();
var client = factory.CreateClient();
var request = new ApiRequest(1, "Walter", "White");

// act
Expand All @@ -138,8 +138,8 @@ public async Task Post_Route_Should_Return_Success_Response()
public async Task Put_Route_Should_Return_Success_Response(int id)
{
// arrange
var fixture = new WebApiTestFixture();
var client = fixture.CreateClient();
var factory = new IntegrationWebApplicationFactory();
var client = factory.CreateClient();
var request = new ApiRequest(id, "Walter", "White");

// act
Expand All @@ -157,8 +157,8 @@ public async Task Put_Route_Should_Return_Success_Response(int id)
public async Task Delete_Route_Should_Return_Success_Response(int id)
{
// arrange
var fixture = new WebApiTestFixture();
var client = fixture.CreateClient();
var factory = new IntegrationWebApplicationFactory();
var client = factory.CreateClient();

// act
var response = await client.DeleteAsync($"api/{id}");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

namespace Example01.Tests;

internal class WebApiTestFixture : WebApplicationFactory<Program>
internal class IntegrationWebApplicationFactory : WebApplicationFactory<Program>
{
protected override void ConfigureWebHost(IWebHostBuilder builder)
{
Expand Down
14 changes: 6 additions & 8 deletions test/Example02.Tests/Example02.Tests.csproj
Original file line number Diff line number Diff line change
@@ -1,24 +1,22 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>net7.0</TargetFramework>
<TargetFramework>net8.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>

<IsPackable>false</IsPackable>
<IsTestProject>true</IsTestProject>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="FluentAssertions" Version="6.12.0" />
<PackageReference Include="Microsoft.AspNetCore.Mvc.Testing" Version="7.0.12" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.6.0" />
<PackageReference Include="xunit" Version="2.4.2" />
<PackageReference Include="xunit.runner.visualstudio" Version="2.4.5">
<PackageReference Include="Microsoft.AspNetCore.Mvc.Testing" Version="8.0.2" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.9.0" />
<PackageReference Include="xunit" Version="2.7.0" />
<PackageReference Include="xunit.runner.visualstudio" Version="2.5.7">
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
<PrivateAssets>all</PrivateAssets>
</PackageReference>
<PackageReference Include="coverlet.collector" Version="3.2.0">
<PackageReference Include="coverlet.collector" Version="6.0.1">
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
<PrivateAssets>all</PrivateAssets>
</PackageReference>
Expand Down
36 changes: 18 additions & 18 deletions test/Example02.Tests/IntegrationTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@ public class IntegrationTests
public async Task Get_Route_Should_Return_Success_Response(int id)
{
// arrange
var fixture = new WebApiTestFixture();
var client = fixture.CreateClient();
var factory = new IntegrationWebApplicationFactory();
var client = factory.CreateClient();

// act
var response = await client.GetAsync($"/api/{id}");
Expand All @@ -29,8 +29,8 @@ public async Task Get_Route_Should_Return_Success_Response(int id)
public async Task Trace_Route_Should_Return_Success_Response()
{
// arrange
var fixture = new WebApiTestFixture();
var client = fixture.CreateClient();
var factory = new IntegrationWebApplicationFactory();
var client = factory.CreateClient();

// act
var response = await client
Expand All @@ -47,8 +47,8 @@ public async Task Trace_Route_Should_Return_Success_Response()
public async Task Search_Route_Should_Return_Success_Response()
{
// arrange
var fixture = new WebApiTestFixture();
var client = fixture.CreateClient();
var factory = new IntegrationWebApplicationFactory();
var client = factory.CreateClient();

// act
var response = await client.GetAsync("api/search?keyword=xyz");
Expand All @@ -63,8 +63,8 @@ public async Task Search_Route_Should_Return_Success_Response()
public async Task List_Route_Should_Return_Success_Response()
{
// arrange
var fixture = new WebApiTestFixture();
var client = fixture.CreateClient();
var factory = new IntegrationWebApplicationFactory();
var client = factory.CreateClient();

// act
var response = await client.GetAsync("api/list?take=50&skip=10");
Expand All @@ -79,8 +79,8 @@ public async Task List_Route_Should_Return_Success_Response()
public async Task Date_Route_Should_Return_Success_Response()
{
// arrange
var fixture = new WebApiTestFixture();
var client = fixture.CreateClient();
var factory = new IntegrationWebApplicationFactory();
var client = factory.CreateClient();

// act
var response = await client.GetAsync(@"api/date");
Expand All @@ -103,8 +103,8 @@ public async Task Date_Route_Should_Return_Success_Response()
public async Task Custom_Route_Should_Return_Success_Response(string answer)
{
// arrange
var fixture = new WebApiTestFixture();
var client = fixture.CreateClient();
var factory = new IntegrationWebApplicationFactory();
var client = factory.CreateClient();

// act
var response = await client.GetAsync($"api/custom?answer={answer}");
Expand All @@ -119,8 +119,8 @@ public async Task Custom_Route_Should_Return_Success_Response(string answer)
public async Task Post_Route_Should_Return_Success_Response()
{
// arrange
var fixture = new WebApiTestFixture();
var client = fixture.CreateClient();
var factory = new IntegrationWebApplicationFactory();
var client = factory.CreateClient();
var request = new ApiRequest(1, "Walter", "White");

// act
Expand All @@ -138,8 +138,8 @@ public async Task Post_Route_Should_Return_Success_Response()
public async Task Put_Route_Should_Return_Success_Response(int id)
{
// arrange
var fixture = new WebApiTestFixture();
var client = fixture.CreateClient();
var factory = new IntegrationWebApplicationFactory();
var client = factory.CreateClient();
var request = new ApiRequest(id, "Walter", "White");

// act
Expand All @@ -157,8 +157,8 @@ public async Task Put_Route_Should_Return_Success_Response(int id)
public async Task Delete_Route_Should_Return_Success_Response(int id)
{
// arrange
var fixture = new WebApiTestFixture();
var client = fixture.CreateClient();
var factory = new IntegrationWebApplicationFactory();
var client = factory.CreateClient();

// act
var response = await client.DeleteAsync($"api/{id}");
Expand Down
Loading

0 comments on commit c2cbab5

Please sign in to comment.