Skip to content

Commit

Permalink
Merge pull request #2 from AKlaus/feature/#1_Net7
Browse files Browse the repository at this point in the history
  • Loading branch information
AKlaus authored Jan 2, 2023
2 parents 1b3534d + c436b1c commit 63c2b03
Show file tree
Hide file tree
Showing 14 changed files with 57 additions and 44 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/build_test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ jobs:
- name: Setup .NET
uses: actions/setup-dotnet@v1
with:
dotnet-version: 6.0.x
dotnet-version: 7.0.x

- name: Install dotnet-ef
run: dotnet tool install --global dotnet-ef
Expand Down
8 changes: 4 additions & 4 deletions Api/Api.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,10 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="DateOnlyTimeOnly.AspNet" Version="1.0.3" />
<PackageReference Include="DateOnlyTimeOnly.AspNet.Swashbuckle" Version="1.0.3" />
<PackageReference Include="DomainResult" Version="3.0.0" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Design" Version="6.0.7">
<PackageReference Include="DateOnlyTimeOnly.AspNet" Version="2.0.0" />
<PackageReference Include="DateOnlyTimeOnly.AspNet.Swashbuckle" Version="2.0.0" />
<PackageReference Include="DomainResult" Version="3.1.0" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Design" Version="7.0.1">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
Expand Down
4 changes: 4 additions & 0 deletions Api/Startup.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,10 @@ public void ConfigureServices(IServiceCollection services)

services.AddAndConfigureDomainServices((settings.ConnectionString, true));

// The below converters were required for .NET 6. Since .NET 7 they work out-of-the-box,
// Swashbuckle is still lacking behind with the standard support, so need to keep these lines
// till Swashbuckle NuGet gets updated.
// Note: It'll also eliminate the need in DateOnlyTimeOnly.AspNet NuGet (https://github.com/maxkoshevoi/DateOnlyTimeOnly.AspNet)
services
.AddControllers(options => options.UseDateOnlyTimeOnlyStringConverters())
.AddJsonOptions(options => options.UseDateOnlyTimeOnlyStringConverters());
Expand Down
6 changes: 3 additions & 3 deletions Database/Database.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Microsoft.EntityFrameworkCore" Version="6.0.7" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Relational" Version="6.0.7" />
<PackageReference Include="Microsoft.EntityFrameworkCore.SqlServer" Version="6.0.7" />
<PackageReference Include="Microsoft.EntityFrameworkCore" Version="7.0.1" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Relational" Version="7.0.1" />
<PackageReference Include="Microsoft.EntityFrameworkCore.SqlServer" Version="7.0.1" />
</ItemGroup>
</Project>
2 changes: 1 addition & 1 deletion Database/Infrastructure/DateOnlyComparer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ public DateOnlyComparer() : base(
}

/// <summary>
/// Compares <see cref="DateOnly?" />.
/// Compares <see cref="Nullable{DateOnly}" />.
/// </summary>
public class NullableDateOnlyComparer : ValueComparer<DateOnly?>
{
Expand Down
2 changes: 1 addition & 1 deletion Database/Infrastructure/DateOnlyConverter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ public DateOnlyConverter() : base(
}

/// <summary>
/// Converts <see cref="DateOnly?" /> to <see cref="DateTime?"/> and vice versa.
/// Converts <see cref="Nullable{DateOnly}" /> to <see cref="Nullable{DateTime}"/> and vice versa.
/// </summary>
public class NullableDateOnlyConverter : ValueConverter<DateOnly?, DateTime?>
{
Expand Down
2 changes: 1 addition & 1 deletion Directory.Build.props
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<Project>
<PropertyGroup>
<TargetFramework>net6.0</TargetFramework>
<TargetFramework>net7.0</TargetFramework>
<LangVersion>latest</LangVersion>
<Nullable>enable</Nullable>
<Features>strict</Features>
Expand Down
20 changes: 10 additions & 10 deletions Domain.Tests/Domain.Tests.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -7,23 +7,23 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Microsoft.Extensions.Configuration" Version="6.0.1" />
<PackageReference Include="Microsoft.Extensions.Configuration.EnvironmentVariables" Version="6.0.1" />
<PackageReference Include="Microsoft.Extensions.Configuration.FileExtensions" Version="6.0.0" />
<PackageReference Include="Microsoft.Extensions.Configuration.Json" Version="6.0.0" />
<PackageReference Include="Microsoft.Extensions.Configuration.UserSecrets" Version="6.0.1" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.2.0" />
<PackageReference Include="Respawn" Version="5.0.1" />
<PackageReference Include="xunit" Version="2.4.1" />
<PackageReference Include="Microsoft.Extensions.Configuration" Version="7.0.0" />
<PackageReference Include="Microsoft.Extensions.Configuration.EnvironmentVariables" Version="7.0.0" />
<PackageReference Include="Microsoft.Extensions.Configuration.FileExtensions" Version="7.0.0" />
<PackageReference Include="Microsoft.Extensions.Configuration.Json" Version="7.0.0" />
<PackageReference Include="Microsoft.Extensions.Configuration.UserSecrets" Version="7.0.0" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.4.1" />
<PackageReference Include="Respawn" Version="6.0.0" />
<PackageReference Include="xunit" Version="2.4.2" />
<PackageReference Include="xunit.runner.visualstudio" Version="2.4.5">
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
<PrivateAssets>all</PrivateAssets>
</PackageReference>
<PackageReference Include="coverlet.msbuild" Version="3.1.2">
<PackageReference Include="coverlet.msbuild" Version="3.2.0">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
<PackageReference Include="coverlet.collector" Version="3.1.2">
<PackageReference Include="coverlet.collector" Version="3.2.0">
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
<PrivateAssets>all</PrivateAssets>
</PackageReference>
Expand Down
4 changes: 2 additions & 2 deletions Domain.Tests/Services/Client/ClientCreateUpdateDeleteTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ public async Task Create_Client_Works()
Assert.True(result.IsSuccess);
var client = await DataContext.Clients.FindAsync(clientId);
Assert.NotNull(client);
Assert.Equal("Test", client!.Name);
Assert.Equal("Test", client.Name);
}

[Fact]
Expand All @@ -42,7 +42,7 @@ public async Task Update_Client_Works()
Assert.True(result.IsSuccess);
var client = await DataContext.Clients.FindAsync(clientId);
Assert.NotNull(client);
Assert.Equal("XYZ", client!.Name);
Assert.Equal("XYZ", client.Name);
}

[Fact]
Expand Down
6 changes: 3 additions & 3 deletions Domain.Tests/Services/Client/ClientQueryTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -32,14 +32,14 @@ public async Task Get_Client_By_Id_Works()
public async Task Get_Clients_List_Works()
{
// GIVEN a DB with 2 clients
var client1Id = await SeedClient("Name1");
var client2Id = await SeedClient("Name2");
await SeedClient("Name1");
await SeedClient("Name2");

// WHEN get a list of clients
var clients = await ClientQueryService.GetList(new GetClientListRequest());

// THEN get 2 clients
Assert.Equal(2, clients.Length);
Assert.True(new[] {"Name1", "Name2"}.SequenceEqual<string>(clients.OrderBy(c => c.Name).Select(c=>c.Name)));
Assert.True(new[] {"Name1", "Name2"}.SequenceEqual(clients.OrderBy(c => c.Name).Select(c=>c.Name)));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ public ClientUniqueNameOnCreateUpdateTests(ITestOutputHelper output) : base(outp
public async Task Create_Client_With_Non_Unique_Name_Fails()
{
// GIVEN a DB with a client
var clientId = await SeedClient("Name");
await SeedClient("Name");

// WHEN create a new client with the same name
var (_, result) = await ClientCommandService.Create(new CreateUpdateClientRequest("Name"));
Expand Down
33 changes: 21 additions & 12 deletions Domain.Tests/TestDbBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,15 +23,12 @@ namespace AK.DbSample.Domain.Tests;
public abstract class TestDbBase : TestBase, IAsyncLifetime
{
protected DataContext DataContext => Container.GetRequiredService<DataContext>();

private readonly Checkpoint _checkPoint = new()
{
TablesToIgnore = new Table[] { "__EFMigrationHistory" }
};

protected readonly ITestOutputHelper Output;

private string _sqlConnection;
/// <summary>
/// Tables that shouldn't be touched on whipping out the DB
/// </summary>
private readonly Table[] _tablesToIgnore = { Microsoft.EntityFrameworkCore.Migrations.HistoryRepository.DefaultTableName /* "__EFMigrationsHistory" */ };

protected TestDbBase(ITestOutputHelper output)
{
Expand All @@ -43,8 +40,10 @@ protected TestDbBase(ITestOutputHelper output)
/// </summary>
protected override void ConfigureIocContainer(IServiceCollection services)
{
_sqlConnection = GetSqlConnectionStringFromConfiguration();
services.AddAndConfigureDbContext(_sqlConnection, false);
var sqlConnection = GetSqlConnectionStringFromConfiguration();

services.AddAndConfigureDbContext(sqlConnection, false);

base.ConfigureIocContainer(services);
}

Expand Down Expand Up @@ -86,13 +85,23 @@ public async Task InitializeAsync()
/// </summary>
protected async Task WipeOutDbAsync()
{
Respawner? respawn = null;
try
{
await _checkPoint.Reset(_sqlConnection);
var connectionString = DataContext.Database.GetConnectionString();
ArgumentNullException.ThrowIfNull(connectionString);

respawn = await Respawner.CreateAsync(connectionString, new RespawnerOptions { TablesToIgnore = _tablesToIgnore });
await respawn.ResetAsync(connectionString);
}
catch (ArgumentNullException ergExc)
{
Output.WriteLine(ergExc.Message);
throw;
}
catch(Exception e)
{
Output.WriteLine(e.Message +" \n"+ (_checkPoint.DeleteSql ?? "no delete SQL"));
Output.WriteLine(e.Message +" \n"+ (respawn?.DeleteSql ?? "no delete SQL"));
throw;
}
}
Expand All @@ -114,6 +123,6 @@ private string GetSqlConnectionStringFromConfiguration()
.AddUserSecrets<TestDbBase>()
.AddEnvironmentVariables()
.Build();
return settings.GetSection("ConnectionString").Value;
return settings.GetSection("ConnectionString").Value!;
}
}
4 changes: 2 additions & 2 deletions Domain/Domain.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@
</ItemGroup>

<ItemGroup>
<PackageReference Include="DomainResult.Common" Version="3.0.0" />
<PackageReference Include="Microsoft.EntityFrameworkCore.SqlServer" Version="6.0.7" />
<PackageReference Include="DomainResult.Common" Version="3.1.0" />
<PackageReference Include="Microsoft.EntityFrameworkCore.SqlServer" Version="7.0.1" />
</ItemGroup>

</Project>
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,16 +25,16 @@ See "[Pain & Gain of automated tests against SQL (MS SQL or PostgreSQL)](https:/
### Technologies

- Main project:
- [.NET 6](https://docs.microsoft.com/en-us/dotnet/core/whats-new/dotnet-6);
- [Entity Framework Core 6](https://docs.microsoft.com/en-us/ef/core/) and [dotnet-ef](https://docs.microsoft.com/en-us/ef/core/cli/dotnet) CLI.
- [.NET 7](https://docs.microsoft.com/en-us/dotnet/core/whats-new/dotnet-7);
- [Entity Framework Core 7](https://docs.microsoft.com/en-us/ef/core/) and [dotnet-ef](https://docs.microsoft.com/en-us/ef/core/cli/dotnet) CLI.
- Test project:
- [xUnit](https://xunit.net/) + [Respawn](https://github.com/jbogard/Respawn);
- [Docker](https://www.docker.com/) + [SQL Server image](https://hub.docker.com/_/microsoft-mssql-server).

## Getting Started (locally)

Firstly, check out this Git repo and install dependencies:
- [.NET SDK](https://dotnet.microsoft.com/download) v6.x;
- [.NET SDK](https://dotnet.microsoft.com/download) v7.x;
- [dotnet-ef](https://docs.microsoft.com/en-us/ef/core/cli/dotnet) CLI;
- [Docker](https://www.docker.com/).

Expand Down

0 comments on commit 63c2b03

Please sign in to comment.