diff --git a/Domain.Tests/TestDbBase.cs b/Domain.Tests/TestDbBase.cs index a0e543b..2e41c32 100644 --- a/Domain.Tests/TestDbBase.cs +++ b/Domain.Tests/TestDbBase.cs @@ -1,6 +1,6 @@ using AK.DbSample.Database; +using AK.DbSample.Database.Configuration; using AK.DbSample.Database.Entities; -using AK.DbSample.Domain.Configuration; using Microsoft.EntityFrameworkCore; using Microsoft.Extensions.Configuration; @@ -20,21 +20,16 @@ namespace AK.DbSample.Domain.Tests; /// Base test class with a DI container and DB connection. /// Derive from it when need DI and DB connection /// -public abstract class TestDbBase : TestBase, IAsyncLifetime +public abstract class TestDbBase(ITestOutputHelper output) : TestBase, IAsyncLifetime { protected DataContext DataContext => Container.GetRequiredService(); - protected readonly ITestOutputHelper Output; + protected readonly ITestOutputHelper Output = output; /// /// Tables that shouldn't be touched on whipping out the DB /// - private readonly Table[] _tablesToIgnore = { Microsoft.EntityFrameworkCore.Migrations.HistoryRepository.DefaultTableName /* "__EFMigrationsHistory" */ }; + private readonly Table[] _tablesToIgnore = [Microsoft.EntityFrameworkCore.Migrations.HistoryRepository.DefaultTableName /* "__EFMigrationsHistory" */]; - protected TestDbBase(ITestOutputHelper output) - { - Output = output; - } - /// /// Configure the DI container /// @@ -83,7 +78,7 @@ public async Task InitializeAsync() /// /// Wipe out all data in the database /// - protected async Task WipeOutDbAsync() + private async Task WipeOutDbAsync() { Respawner? respawn = null; try diff --git a/Domain/Services/BaseService.cs b/Domain/Services/BaseService.cs index 531887a..b05b170 100644 --- a/Domain/Services/BaseService.cs +++ b/Domain/Services/BaseService.cs @@ -2,12 +2,7 @@ namespace AK.DbSample.Domain.Services; -public abstract class BaseService +public abstract class BaseService(DataContext dataContext) { - protected readonly DataContext DataContext; - - protected BaseService(DataContext dataContext) - { - DataContext = dataContext; - } + protected readonly DataContext DataContext = dataContext; } \ No newline at end of file diff --git a/Domain/Services/Client/ClientCommandService.cs b/Domain/Services/Client/ClientCommandService.cs index 21c66f9..d00533b 100644 --- a/Domain/Services/Client/ClientCommandService.cs +++ b/Domain/Services/Client/ClientCommandService.cs @@ -14,10 +14,8 @@ public interface IClientCommandService Task Delete(long id); } -public class ClientCommandService: BaseService, IClientCommandService +public class ClientCommandService(DataContext dataContext) : BaseService(dataContext), IClientCommandService { - public ClientCommandService(DataContext dataContext) : base(dataContext) {} - public async Task<(long, IDomainResult)> Create(CreateUpdateClientRequest dto) { var nameCheckResult = await UniqueNameCheck(null, dto.Name); diff --git a/Domain/Services/Client/ClientQueryService.cs b/Domain/Services/Client/ClientQueryService.cs index 266ee85..c8b0ac2 100644 --- a/Domain/Services/Client/ClientQueryService.cs +++ b/Domain/Services/Client/ClientQueryService.cs @@ -13,10 +13,8 @@ public interface IClientQueryService Task GetList(GetClientListRequest filter); } -public class ClientQueryService: BaseService, IClientQueryService +public class ClientQueryService(DataContext dataContext) : BaseService(dataContext), IClientQueryService { - public ClientQueryService(DataContext dataContext) : base(dataContext) {} - public async Task<(GetClientByIdResponse, IDomainResult)> GetById(long clientId) { var client = await DataContext.Clients diff --git a/Domain/Services/Client/DTOs/ClientQueryDtos.cs b/Domain/Services/Client/DTOs/ClientQueryDtos.cs index 48fff19..3e8e06f 100644 --- a/Domain/Services/Client/DTOs/ClientQueryDtos.cs +++ b/Domain/Services/Client/DTOs/ClientQueryDtos.cs @@ -1,3 +1,4 @@ +// ReSharper disable NotAccessedPositionalProperty.Global namespace AK.DbSample.Domain.Services.Client.DTOs; public record GetClientListRequest(string? Name = null); diff --git a/Domain/Services/Invoice/DTOs/InvoiceQueryDtos.cs b/Domain/Services/Invoice/DTOs/InvoiceQueryDtos.cs index 5e5d623..3b2d9b6 100644 --- a/Domain/Services/Invoice/DTOs/InvoiceQueryDtos.cs +++ b/Domain/Services/Invoice/DTOs/InvoiceQueryDtos.cs @@ -1,3 +1,4 @@ +// ReSharper disable NotAccessedPositionalProperty.Global namespace AK.DbSample.Domain.Services.Invoice.DTOs; public record GetInvoiceListRequest(long? ClientId = null); diff --git a/Domain/Services/Invoice/InvoiceCommandService.cs b/Domain/Services/Invoice/InvoiceCommandService.cs index 447d4bc..78eae73 100644 --- a/Domain/Services/Invoice/InvoiceCommandService.cs +++ b/Domain/Services/Invoice/InvoiceCommandService.cs @@ -14,10 +14,8 @@ public interface IInvoiceCommandService Task Delete(string number); } -public class InvoiceCommandService: BaseService, IInvoiceCommandService +public class InvoiceCommandService(DataContext dataContext) : BaseService(dataContext), IInvoiceCommandService { - public InvoiceCommandService(DataContext dataContext) : base(dataContext) {} - public async Task<(string, IDomainResult)> Create(CreateInvoiceRequest dto) { var numberCheckResult = await UniqueNumberCheck(dto.Number, true); diff --git a/Domain/Services/Invoice/InvoiceQueryService.cs b/Domain/Services/Invoice/InvoiceQueryService.cs index 0b28d62..2deb5fe 100644 --- a/Domain/Services/Invoice/InvoiceQueryService.cs +++ b/Domain/Services/Invoice/InvoiceQueryService.cs @@ -13,10 +13,8 @@ public interface IInvoiceQueryService Task GetList(GetInvoiceListRequest filter); } -public class InvoiceQueryService: BaseService, IInvoiceQueryService +public class InvoiceQueryService(DataContext dataContext) : BaseService(dataContext), IInvoiceQueryService { - public InvoiceQueryService(DataContext dataContext) : base(dataContext) {} - public async Task<(GetInvoiceByNumberResponse, IDomainResult)> GetByNumber(string number) { var invoice = await DataContext.Invoices