From c3f3d4d3ed437b30368831108fa20d61e6a398a0 Mon Sep 17 00:00:00 2001 From: Enis Mulic Date: Sat, 13 Apr 2024 23:16:42 +0200 Subject: [PATCH] chore: bump project to .NET 8 --- .editorconfig | 3 +++ ...crosoftEntraSwaggerConfigurationOptions.cs | 9 ++------- src/Api/Services/CurrentUserService.cs | 9 ++------- .../Common/Behaviours/LoggingBehaviour.cs | 12 +++-------- .../Common/Behaviours/PerformanceBehaviour.cs | 20 ++++++------------- .../Common/Behaviours/ValidationBehaviour.cs | 9 ++------- src/Application/Common/Models/OpenApiTags.cs | 2 +- .../Common/Models/PaginatedList.cs | 18 +++++------------ src/Application/Domain/Entities/TodoItem.cs | 2 +- .../Domain/Events/TodoItemCompletedEvent.cs | 8 ++------ .../Domain/Events/TodoItemCreatedEvent.cs | 8 ++------ .../Domain/Events/TodoItemDeletedEvent.cs | 8 ++------ .../Exceptions/UnsupportedColourException.cs | 6 +----- .../Features/Todos/CompleteTodoItem.cs | 11 +++------- .../Features/Todos/CreateTodoItem.cs | 11 +++------- .../Features/Todos/CreateTodoList.cs | 9 ++------- .../Features/Todos/DeleteTodoItem.cs | 11 +++------- .../Features/Todos/DeleteTodoList.cs | 9 ++------- src/Application/Features/Todos/GetTodos.cs | 12 +++-------- .../Todos/TodoItemCompletedEventHandler.cs | 9 ++------- .../Todos/TodoItemCreatedEventHandler.cs | 9 ++------- .../Todos/TodoItemDeletedEventHandler.cs | 9 ++------- .../Persistance/ApplicationDbContext.cs | 6 +----- .../AuditableEntityInterceptor.cs | 16 +++++---------- .../DispatchDomainEventsInterceptor.cs | 9 ++------- .../SqlServerTestDatabase.cs | 2 +- .../TestContainersDatabase.cs | 2 +- .../TestingWebApplicationFactory.cs | 9 ++------- .../Exceptions/ValidationExceptionTests.cs | 16 +++++++-------- 29 files changed, 74 insertions(+), 190 deletions(-) diff --git a/.editorconfig b/.editorconfig index 2926a95..57e8ac4 100644 --- a/.editorconfig +++ b/.editorconfig @@ -389,3 +389,6 @@ csharp_style_namespace_declarations = block_scoped:silent csharp_style_prefer_method_group_conversion = true:silent csharp_style_prefer_top_level_statements = true:silent csharp_style_prefer_primary_constructors = true:suggestion + +# Primary constructor +dotnet_diagnostic.IDE0290.severity = none diff --git a/src/Api/Options/MicrosoftEntraSwaggerConfigurationOptions.cs b/src/Api/Options/MicrosoftEntraSwaggerConfigurationOptions.cs index 68963da..ff9feec 100644 --- a/src/Api/Options/MicrosoftEntraSwaggerConfigurationOptions.cs +++ b/src/Api/Options/MicrosoftEntraSwaggerConfigurationOptions.cs @@ -7,14 +7,9 @@ namespace Api.Options; -public class MicrosoftEntraSwaggerConfigurationOptions : IConfigureOptions +public class MicrosoftEntraSwaggerConfigurationOptions(IOptions options) : IConfigureOptions { - private readonly MicrosoftEntraOptions _options; - - public MicrosoftEntraSwaggerConfigurationOptions(IOptions options) - { - _options = options.Value; - } + private readonly MicrosoftEntraOptions _options = options.Value; public void Configure(SwaggerGenOptions options) { diff --git a/src/Api/Services/CurrentUserService.cs b/src/Api/Services/CurrentUserService.cs index 625a4ef..3bb66ed 100644 --- a/src/Api/Services/CurrentUserService.cs +++ b/src/Api/Services/CurrentUserService.cs @@ -4,14 +4,9 @@ namespace Api.Services; -public class CurrentUserService : ICurrentUserService +public class CurrentUserService(IHttpContextAccessor httpContextAccessor) : ICurrentUserService { - private readonly IHttpContextAccessor _httpContextAccessor; - - public CurrentUserService(IHttpContextAccessor httpContextAccessor) - { - _httpContextAccessor = httpContextAccessor; - } + private readonly IHttpContextAccessor _httpContextAccessor = httpContextAccessor; public string? Email => _httpContextAccessor.HttpContext?.User?.FindFirstValue(ClaimTypes.Name); } \ No newline at end of file diff --git a/src/Application/Common/Behaviours/LoggingBehaviour.cs b/src/Application/Common/Behaviours/LoggingBehaviour.cs index a14865c..15d472b 100644 --- a/src/Application/Common/Behaviours/LoggingBehaviour.cs +++ b/src/Application/Common/Behaviours/LoggingBehaviour.cs @@ -6,16 +6,10 @@ namespace Application.Common.Behaviours { - public class LoggingBehaviour : IRequestPreProcessor where TRequest : notnull + public class LoggingBehaviour(ILogger logger, ICurrentUserService currentUserService) : IRequestPreProcessor where TRequest : notnull { - private readonly ILogger _logger; - private readonly ICurrentUserService _currentUserService; - - public LoggingBehaviour(ILogger logger, ICurrentUserService currentUserService) - { - _logger = logger; - _currentUserService = currentUserService; - } + private readonly ILogger _logger = logger; + private readonly ICurrentUserService _currentUserService = currentUserService; public Task Process(TRequest request, CancellationToken cancellationToken) { diff --git a/src/Application/Common/Behaviours/PerformanceBehaviour.cs b/src/Application/Common/Behaviours/PerformanceBehaviour.cs index bd8a799..1028551 100644 --- a/src/Application/Common/Behaviours/PerformanceBehaviour.cs +++ b/src/Application/Common/Behaviours/PerformanceBehaviour.cs @@ -14,21 +14,13 @@ namespace Application.Common.Behaviours; /// /// /// -public class PerformanceBehaviour : IPipelineBehavior where TRequest : IRequest +public class PerformanceBehaviour( + ILogger logger, + ICurrentUserService currentUserService) : IPipelineBehavior where TRequest : IRequest { - private readonly Stopwatch _timer; - private readonly ILogger _logger; - private readonly ICurrentUserService _currentUserService; - - public PerformanceBehaviour( - ILogger logger, - ICurrentUserService currentUserService) - { - _timer = new Stopwatch(); - - _logger = logger; - _currentUserService = currentUserService; - } + private readonly Stopwatch _timer = new(); + private readonly ILogger _logger = logger; + private readonly ICurrentUserService _currentUserService = currentUserService; public async Task Handle(TRequest request, RequestHandlerDelegate next, CancellationToken cancellationToken) { diff --git a/src/Application/Common/Behaviours/ValidationBehaviour.cs b/src/Application/Common/Behaviours/ValidationBehaviour.cs index 65d9e3c..73a3e55 100644 --- a/src/Application/Common/Behaviours/ValidationBehaviour.cs +++ b/src/Application/Common/Behaviours/ValidationBehaviour.cs @@ -6,15 +6,10 @@ namespace Application.Common.Behaviours; -public class ValidationBehaviour : IPipelineBehavior +public class ValidationBehaviour(IEnumerable> validators) : IPipelineBehavior where TRequest : IRequest { - private readonly IEnumerable> _validators; - - public ValidationBehaviour(IEnumerable> validators) - { - _validators = validators; - } + private readonly IEnumerable> _validators = validators; public async Task Handle(TRequest request, RequestHandlerDelegate next, CancellationToken cancellationToken) { diff --git a/src/Application/Common/Models/OpenApiTags.cs b/src/Application/Common/Models/OpenApiTags.cs index 7a00d7c..1c7b25d 100644 --- a/src/Application/Common/Models/OpenApiTags.cs +++ b/src/Application/Common/Models/OpenApiTags.cs @@ -4,5 +4,5 @@ namespace Application.Common.Models; public static class OpenApiTags { - public static List TodoList { get; } = new() { new OpenApiTag { Name = "Todo Lists" } }; + public static List TodoList { get; } = [new OpenApiTag { Name = "Todo Lists" }]; } \ No newline at end of file diff --git a/src/Application/Common/Models/PaginatedList.cs b/src/Application/Common/Models/PaginatedList.cs index 307a585..7fc8863 100644 --- a/src/Application/Common/Models/PaginatedList.cs +++ b/src/Application/Common/Models/PaginatedList.cs @@ -4,20 +4,12 @@ namespace Application.Common.Models; -public class PaginatedList +public class PaginatedList(List items, int count, int pageNumber, int pageSize) { - public List Items { get; } - public int PageNumber { get; } - public int TotalPages { get; } - public int TotalCount { get; } - - public PaginatedList(List items, int count, int pageNumber, int pageSize) - { - PageNumber = pageNumber; - TotalPages = (int)Math.Ceiling(count / (double)pageSize); - TotalCount = count; - Items = items; - } + public List Items { get; } = items; + public int PageNumber { get; } = pageNumber; + public int TotalPages { get; } = (int)Math.Ceiling(count / (double)pageSize); + public int TotalCount { get; } = count; public bool HasPreviousPage => PageNumber > 1; diff --git a/src/Application/Domain/Entities/TodoItem.cs b/src/Application/Domain/Entities/TodoItem.cs index 5012b43..56e1da2 100644 --- a/src/Application/Domain/Entities/TodoItem.cs +++ b/src/Application/Domain/Entities/TodoItem.cs @@ -15,7 +15,7 @@ public class TodoItem : BaseAuditableEntity, IHasDomainEvent, ISoftDelete public int TodoListId { get; private set; } public TodoList TodoList { get; private set; } = null!; - public List DomainEvents { get; private set; } = new List(); + public List DomainEvents { get; private set; } = []; private TodoItem() { } diff --git a/src/Application/Domain/Events/TodoItemCompletedEvent.cs b/src/Application/Domain/Events/TodoItemCompletedEvent.cs index 9ae591a..4048f2d 100644 --- a/src/Application/Domain/Events/TodoItemCompletedEvent.cs +++ b/src/Application/Domain/Events/TodoItemCompletedEvent.cs @@ -3,11 +3,7 @@ namespace Application.Domain.Events; -public class TodoItemCompletedEvent : DomainEvent +public class TodoItemCompletedEvent(TodoItem item) : DomainEvent { - public TodoItem Item { get; } - public TodoItemCompletedEvent(TodoItem item) - { - Item = item; - } + public TodoItem Item { get; } = item; } \ No newline at end of file diff --git a/src/Application/Domain/Events/TodoItemCreatedEvent.cs b/src/Application/Domain/Events/TodoItemCreatedEvent.cs index b44fd40..9821389 100644 --- a/src/Application/Domain/Events/TodoItemCreatedEvent.cs +++ b/src/Application/Domain/Events/TodoItemCreatedEvent.cs @@ -3,11 +3,7 @@ namespace Application.Domain.Events; -public class TodoItemCreatedEvent : DomainEvent +public class TodoItemCreatedEvent(TodoItem item) : DomainEvent { - public TodoItem Item { get; } - public TodoItemCreatedEvent(TodoItem item) - { - Item = item; - } + public TodoItem Item { get; } = item; } \ No newline at end of file diff --git a/src/Application/Domain/Events/TodoItemDeletedEvent.cs b/src/Application/Domain/Events/TodoItemDeletedEvent.cs index fc0fc8c..c331e66 100644 --- a/src/Application/Domain/Events/TodoItemDeletedEvent.cs +++ b/src/Application/Domain/Events/TodoItemDeletedEvent.cs @@ -2,11 +2,7 @@ using Application.Domain.Entities; namespace Application.Domain.Events; -public class TodoItemDeletedEvent : DomainEvent +public class TodoItemDeletedEvent(TodoItem item) : DomainEvent { - public TodoItem Item { get; } - public TodoItemDeletedEvent(TodoItem item) - { - Item = item; - } + public TodoItem Item { get; } = item; } \ No newline at end of file diff --git a/src/Application/Domain/Exceptions/UnsupportedColourException.cs b/src/Application/Domain/Exceptions/UnsupportedColourException.cs index 8fb11c3..f397895 100644 --- a/src/Application/Domain/Exceptions/UnsupportedColourException.cs +++ b/src/Application/Domain/Exceptions/UnsupportedColourException.cs @@ -1,9 +1,5 @@ namespace Application.Domain.Exceptions; -public class UnsupportedColourException : Exception +public class UnsupportedColourException(string code) : Exception($"Colour \"{code}\" is unsupported.") { - public UnsupportedColourException(string code) - : base($"Colour \"{code}\" is unsupported.") - { - } } \ No newline at end of file diff --git a/src/Application/Features/Todos/CompleteTodoItem.cs b/src/Application/Features/Todos/CompleteTodoItem.cs index 33f9996..b1e0406 100644 --- a/src/Application/Features/Todos/CompleteTodoItem.cs +++ b/src/Application/Features/Todos/CompleteTodoItem.cs @@ -35,18 +35,13 @@ public void AddRoutes(IEndpointRouteBuilder app) public record CompleteTodoCommand(int Id) : IRequest; -public class CompleteTodoCommandHandler : IRequestHandler +public class CompleteTodoCommandHandler(ApplicationDbContext context) : IRequestHandler { - private readonly ApplicationDbContext _context; - - public CompleteTodoCommandHandler(ApplicationDbContext context) - { - _context = context; - } + private readonly ApplicationDbContext _context = context; public async Task Handle(CompleteTodoCommand request, CancellationToken cancellationToken) { - var item = await _context.TodoItems.FindAsync(new object?[] { request.Id }, cancellationToken: cancellationToken) + var item = await _context.TodoItems.FindAsync([request.Id], cancellationToken: cancellationToken) ?? throw new NotFoundException(nameof(TodoItem), request.Id); if (!item.Done) diff --git a/src/Application/Features/Todos/CreateTodoItem.cs b/src/Application/Features/Todos/CreateTodoItem.cs index 700ce02..6c69304 100644 --- a/src/Application/Features/Todos/CreateTodoItem.cs +++ b/src/Application/Features/Todos/CreateTodoItem.cs @@ -57,18 +57,13 @@ public CreeateTodoItemCommandValidator(IDateTime dateTime) } } -public class CreeateTodoItemCommandHandler : IRequestHandler +public class CreeateTodoItemCommandHandler(ApplicationDbContext context) : IRequestHandler { - private readonly ApplicationDbContext _context; - - public CreeateTodoItemCommandHandler(ApplicationDbContext context) - { - _context = context; - } + private readonly ApplicationDbContext _context = context; public async Task Handle(CreeateTodoItemCommand request, CancellationToken cancellationToken) { - var todoList = await _context.TodoLists.FindAsync(new object?[] { request.Id }, cancellationToken) + var todoList = await _context.TodoLists.FindAsync([request.Id], cancellationToken) ?? throw new NotFoundException(nameof(TodoList), request.Id); var todoItem = TodoItem.Create(request.Item.Title, diff --git a/src/Application/Features/Todos/CreateTodoList.cs b/src/Application/Features/Todos/CreateTodoList.cs index 4a5fc0d..e7607cd 100644 --- a/src/Application/Features/Todos/CreateTodoList.cs +++ b/src/Application/Features/Todos/CreateTodoList.cs @@ -46,14 +46,9 @@ public CreateTodoListCommandValidator() } } -public class CreateTodoListCommandHandler : IRequestHandler +public class CreateTodoListCommandHandler(ApplicationDbContext context) : IRequestHandler { - private readonly ApplicationDbContext _context; - - public CreateTodoListCommandHandler(ApplicationDbContext context) - { - _context = context; - } + private readonly ApplicationDbContext _context = context; public async Task Handle(CreateTodoListCommand request, CancellationToken cancellationToken) { diff --git a/src/Application/Features/Todos/DeleteTodoItem.cs b/src/Application/Features/Todos/DeleteTodoItem.cs index 28eac34..1bbc250 100644 --- a/src/Application/Features/Todos/DeleteTodoItem.cs +++ b/src/Application/Features/Todos/DeleteTodoItem.cs @@ -37,18 +37,13 @@ public void AddRoutes(IEndpointRouteBuilder app) public record DeleteTodoItemCommand(int Id) : IRequest; -public class DeleteTodoItemCommandHandler : IRequestHandler +public class DeleteTodoItemCommandHandler(ApplicationDbContext context) : IRequestHandler { - private readonly ApplicationDbContext _context; - - public DeleteTodoItemCommandHandler(ApplicationDbContext context) - { - _context = context; - } + private readonly ApplicationDbContext _context = context; public async Task Handle(DeleteTodoItemCommand request, CancellationToken cancellationToken) { - var item = await _context.TodoItems.FindAsync(new object?[] { request.Id }, cancellationToken: cancellationToken) + var item = await _context.TodoItems.FindAsync([request.Id], cancellationToken: cancellationToken) ?? throw new NotFoundException(nameof(TodoItem), request.Id); _context.TodoItems.Remove(item); diff --git a/src/Application/Features/Todos/DeleteTodoList.cs b/src/Application/Features/Todos/DeleteTodoList.cs index 7457b4b..1fa167f 100644 --- a/src/Application/Features/Todos/DeleteTodoList.cs +++ b/src/Application/Features/Todos/DeleteTodoList.cs @@ -37,14 +37,9 @@ public void AddRoutes(IEndpointRouteBuilder app) public record DeleteTodoListCommand(int Id) : IRequest; -public class DeleteTodoListCommandHandler : IRequestHandler +public class DeleteTodoListCommandHandler(ApplicationDbContext context) : IRequestHandler { - private readonly ApplicationDbContext _context; - - public DeleteTodoListCommandHandler(ApplicationDbContext context) - { - _context = context; - } + private readonly ApplicationDbContext _context = context; public async Task Handle(DeleteTodoListCommand request, CancellationToken cancellationToken) { diff --git a/src/Application/Features/Todos/GetTodos.cs b/src/Application/Features/Todos/GetTodos.cs index 83b3033..6b30cc3 100644 --- a/src/Application/Features/Todos/GetTodos.cs +++ b/src/Application/Features/Todos/GetTodos.cs @@ -38,16 +38,10 @@ public void AddRoutes(IEndpointRouteBuilder app) public record GetTodosQuery : IRequest>; -public class GetTodosQueryHandler : IRequestHandler> +public class GetTodosQueryHandler(ApplicationDbContext context, IMapper mapper) : IRequestHandler> { - private readonly ApplicationDbContext _context; - private readonly IMapper _mapper; - - public GetTodosQueryHandler(ApplicationDbContext context, IMapper mapper) - { - _context = context; - _mapper = mapper; - } + private readonly ApplicationDbContext _context = context; + private readonly IMapper _mapper = mapper; public async Task> Handle(GetTodosQuery request, CancellationToken cancellationToken) { diff --git a/src/Application/Features/Todos/TodoItemCompletedEventHandler.cs b/src/Application/Features/Todos/TodoItemCompletedEventHandler.cs index 2a18851..167d28a 100644 --- a/src/Application/Features/Todos/TodoItemCompletedEventHandler.cs +++ b/src/Application/Features/Todos/TodoItemCompletedEventHandler.cs @@ -7,14 +7,9 @@ namespace Application.Features.Todos; -public class TodoItemCompletedHandler : INotificationHandler +public class TodoItemCompletedHandler(ILogger logger) : INotificationHandler { - private readonly ILogger _logger; - - public TodoItemCompletedHandler(ILogger logger) - { - _logger = logger; - } + private readonly ILogger _logger = logger; public Task Handle(TodoItemCompletedEvent notification, CancellationToken cancellationToken) { diff --git a/src/Application/Features/Todos/TodoItemCreatedEventHandler.cs b/src/Application/Features/Todos/TodoItemCreatedEventHandler.cs index 8778b7b..bd29876 100644 --- a/src/Application/Features/Todos/TodoItemCreatedEventHandler.cs +++ b/src/Application/Features/Todos/TodoItemCreatedEventHandler.cs @@ -8,14 +8,9 @@ namespace Application.Features.Todos; -public class TodoItemCreatedHandler : INotificationHandler +public class TodoItemCreatedHandler(ILogger logger) : INotificationHandler { - private readonly ILogger _logger; - - public TodoItemCreatedHandler(ILogger logger) - { - _logger = logger; - } + private readonly ILogger _logger = logger; public Task Handle(TodoItemCreatedEvent notification, CancellationToken cancellationToken) { diff --git a/src/Application/Features/Todos/TodoItemDeletedEventHandler.cs b/src/Application/Features/Todos/TodoItemDeletedEventHandler.cs index 7082ad6..b7e96f1 100644 --- a/src/Application/Features/Todos/TodoItemDeletedEventHandler.cs +++ b/src/Application/Features/Todos/TodoItemDeletedEventHandler.cs @@ -7,14 +7,9 @@ namespace Application.Features.Todos; -public class TodoItemDeletedHandler : INotificationHandler +public class TodoItemDeletedHandler(ILogger logger) : INotificationHandler { - private readonly ILogger _logger; - - public TodoItemDeletedHandler(ILogger logger) - { - _logger = logger; - } + private readonly ILogger _logger = logger; public Task Handle(TodoItemDeletedEvent notification, CancellationToken cancellationToken) { diff --git a/src/Application/Infrastructure/Persistance/ApplicationDbContext.cs b/src/Application/Infrastructure/Persistance/ApplicationDbContext.cs index 4c141b1..a30a34a 100644 --- a/src/Application/Infrastructure/Persistance/ApplicationDbContext.cs +++ b/src/Application/Infrastructure/Persistance/ApplicationDbContext.cs @@ -6,12 +6,8 @@ namespace Application.Infrastructure.Persistance; -public class ApplicationDbContext : DbContext +public class ApplicationDbContext(DbContextOptions options) : DbContext(options) { - public ApplicationDbContext(DbContextOptions options) : base(options) - { - } - public DbSet TodoLists => Set(); public DbSet TodoItems => Set(); diff --git a/src/Application/Infrastructure/Persistance/Interceptors/AuditableEntityInterceptor.cs b/src/Application/Infrastructure/Persistance/Interceptors/AuditableEntityInterceptor.cs index 65837b5..e95b8bc 100644 --- a/src/Application/Infrastructure/Persistance/Interceptors/AuditableEntityInterceptor.cs +++ b/src/Application/Infrastructure/Persistance/Interceptors/AuditableEntityInterceptor.cs @@ -7,18 +7,12 @@ namespace Application.Infrastructure.Persistance.Interceptors; -public class AuditableEntityInterceptor : SaveChangesInterceptor +public class AuditableEntityInterceptor( + ICurrentUserService currentUserService, + IDateTime dateTime) : SaveChangesInterceptor { - private readonly ICurrentUserService _currentUserService; - private readonly IDateTime _dateTime; - - public AuditableEntityInterceptor( - ICurrentUserService currentUserService, - IDateTime dateTime) - { - _currentUserService = currentUserService; - _dateTime = dateTime; - } + private readonly ICurrentUserService _currentUserService = currentUserService; + private readonly IDateTime _dateTime = dateTime; public override InterceptionResult SavingChanges(DbContextEventData eventData, InterceptionResult result) { diff --git a/src/Application/Infrastructure/Persistance/Interceptors/DispatchDomainEventsInterceptor.cs b/src/Application/Infrastructure/Persistance/Interceptors/DispatchDomainEventsInterceptor.cs index 105a81f..b32d1a3 100644 --- a/src/Application/Infrastructure/Persistance/Interceptors/DispatchDomainEventsInterceptor.cs +++ b/src/Application/Infrastructure/Persistance/Interceptors/DispatchDomainEventsInterceptor.cs @@ -7,14 +7,9 @@ namespace Application.Infrastructure.Persistance.Interceptors; -public class DispatchDomainEventsInterceptor : SaveChangesInterceptor +public class DispatchDomainEventsInterceptor(IMediator mediator) : SaveChangesInterceptor { - private readonly IMediator _mediator; - - public DispatchDomainEventsInterceptor(IMediator mediator) - { - _mediator = mediator; - } + private readonly IMediator _mediator = mediator; public override InterceptionResult SavingChanges(DbContextEventData eventData, InterceptionResult result) { diff --git a/tests/Application.IntegrationTests/SqlServerTestDatabase.cs b/tests/Application.IntegrationTests/SqlServerTestDatabase.cs index 12a9cc6..078bf33 100644 --- a/tests/Application.IntegrationTests/SqlServerTestDatabase.cs +++ b/tests/Application.IntegrationTests/SqlServerTestDatabase.cs @@ -42,7 +42,7 @@ public async Task InitialiseAsync() _respawner = await Respawner.CreateAsync(_connectionString, new RespawnerOptions { - TablesToIgnore = new Respawn.Graph.Table[] { "__EFMigrationsHistory" } + TablesToIgnore = ["__EFMigrationsHistory"] }); } diff --git a/tests/Application.IntegrationTests/TestContainersDatabase.cs b/tests/Application.IntegrationTests/TestContainersDatabase.cs index 20d741b..7ed7e0f 100644 --- a/tests/Application.IntegrationTests/TestContainersDatabase.cs +++ b/tests/Application.IntegrationTests/TestContainersDatabase.cs @@ -58,7 +58,7 @@ public async Task InitialiseAsync() _respawner = await Respawner.CreateAsync(_connectionString, new RespawnerOptions { - TablesToIgnore = new Respawn.Graph.Table[] { "__EFMigrationsHistory" } + TablesToIgnore = ["__EFMigrationsHistory"] }); } diff --git a/tests/Application.IntegrationTests/TestingWebApplicationFactory.cs b/tests/Application.IntegrationTests/TestingWebApplicationFactory.cs index b6572cd..98e7428 100644 --- a/tests/Application.IntegrationTests/TestingWebApplicationFactory.cs +++ b/tests/Application.IntegrationTests/TestingWebApplicationFactory.cs @@ -12,14 +12,9 @@ namespace Application.IntegrationTests; -public class TestingWebApplicationFactory : WebApplicationFactory +public class TestingWebApplicationFactory(DbConnection connection) : WebApplicationFactory { - private readonly DbConnection _connection; - - public TestingWebApplicationFactory(DbConnection connection) - { - _connection = connection; - } + private readonly DbConnection _connection = connection; [System.Diagnostics.CodeAnalysis.SuppressMessage("Style", "IDE0053:Use expression body for lambda expression", Justification = "")] protected override void ConfigureWebHost(IWebHostBuilder builder) diff --git a/tests/Application.UnitTests/Common/Exceptions/ValidationExceptionTests.cs b/tests/Application.UnitTests/Common/Exceptions/ValidationExceptionTests.cs index 4dba4e2..c3b9e9b 100644 --- a/tests/Application.UnitTests/Common/Exceptions/ValidationExceptionTests.cs +++ b/tests/Application.UnitTests/Common/Exceptions/ValidationExceptionTests.cs @@ -13,7 +13,7 @@ public void DefaultConstructorCreatesAnEmptyErrorDictionary() { var actual = new ValidationException().Errors; - actual.Keys.Should().BeEquivalentTo(Array.Empty()); + actual.Keys.Should().BeEquivalentTo([]); } [Test] @@ -21,7 +21,7 @@ public void SingleValidationFailureCreatesASingleElementErrorDictionary() { var failures = new List { - new ValidationFailure("Age", "must be over 18"), + new("Age", "must be over 18"), }; var actual = new ValidationException(failures).Errors; @@ -35,12 +35,12 @@ public void MultipleValidationFailureForMultiplePropertiesCreatesAMultipleElemen { var failures = new List { - new ValidationFailure("Age", "must be 18 or older"), - new ValidationFailure("Age", "must be 25 or younger"), - new ValidationFailure("Password", "must contain at least 8 characters"), - new ValidationFailure("Password", "must contain a digit"), - new ValidationFailure("Password", "must contain upper case letter"), - new ValidationFailure("Password", "must contain lower case letter"), + new("Age", "must be 18 or older"), + new("Age", "must be 25 or younger"), + new("Password", "must contain at least 8 characters"), + new("Password", "must contain a digit"), + new("Password", "must contain upper case letter"), + new("Password", "must contain lower case letter"), }; var actual = new ValidationException(failures).Errors;