diff --git a/.github/workflows/dotnet.yml b/.github/workflows/dotnet.yml index c7c4468..d75de9d 100644 --- a/.github/workflows/dotnet.yml +++ b/.github/workflows/dotnet.yml @@ -19,7 +19,7 @@ jobs: - name: Setup .NET uses: actions/setup-dotnet@v3 with: - dotnet-version: 6.0.x + dotnet-version: 8.0.x - name: Restore dependencies run: dotnet restore ./MicroserviceTemplate/MicroserviceTemplate.sln - name: Build diff --git a/MicroserviceTemplate/src/Domain/MicroserviceTemplate.Application/MicroserviceTemplate.Application.csproj b/MicroserviceTemplate/src/Domain/MicroserviceTemplate.Application/MicroserviceTemplate.Application.csproj index 10be41d..030fbe3 100644 --- a/MicroserviceTemplate/src/Domain/MicroserviceTemplate.Application/MicroserviceTemplate.Application.csproj +++ b/MicroserviceTemplate/src/Domain/MicroserviceTemplate.Application/MicroserviceTemplate.Application.csproj @@ -1,14 +1,14 @@  - net7.0 + net8.0 enable - - - + + + diff --git a/MicroserviceTemplate/src/Domain/MicroserviceTemplate.Application/ToDo/Commands/CreateToDo/CreateToDoCommandHandler.cs b/MicroserviceTemplate/src/Domain/MicroserviceTemplate.Application/ToDo/Commands/CreateToDo/CreateToDoCommandHandler.cs index b337ab6..783cdcf 100644 --- a/MicroserviceTemplate/src/Domain/MicroserviceTemplate.Application/ToDo/Commands/CreateToDo/CreateToDoCommandHandler.cs +++ b/MicroserviceTemplate/src/Domain/MicroserviceTemplate.Application/ToDo/Commands/CreateToDo/CreateToDoCommandHandler.cs @@ -16,13 +16,11 @@ public CreateToDoCommandHandler(IToDoCommandRepository commandRepository, IMedia _mediator = mediator; } - public async Task Handle(CreateToDoCommand request, CancellationToken cancellationToken) + public async Task Handle(CreateToDoCommand request, CancellationToken cancellationToken) { var toDo = new ToDoItem(request.Id, request.Description, request.Username); await _commandRepository.CreateToDo(toDo); await _mediator.Publish(new TaskCreatedEvent(toDo.Username, toDo.Description, toDo.Status), cancellationToken); - - return Unit.Value; } } } diff --git a/MicroserviceTemplate/src/Domain/MicroserviceTemplate.Domain/MicroserviceTemplate.Domain.csproj b/MicroserviceTemplate/src/Domain/MicroserviceTemplate.Domain/MicroserviceTemplate.Domain.csproj index b9cfbf3..20ebbe3 100644 --- a/MicroserviceTemplate/src/Domain/MicroserviceTemplate.Domain/MicroserviceTemplate.Domain.csproj +++ b/MicroserviceTemplate/src/Domain/MicroserviceTemplate.Domain/MicroserviceTemplate.Domain.csproj @@ -1,7 +1,7 @@  - net7.0 + net8.0 enable enable diff --git a/MicroserviceTemplate/src/Infrastructure/MicroserviceTemplate.Persistence/MicroserviceTemplate.Persistence.csproj b/MicroserviceTemplate/src/Infrastructure/MicroserviceTemplate.Persistence/MicroserviceTemplate.Persistence.csproj index 3f64bce..dfb68c2 100644 --- a/MicroserviceTemplate/src/Infrastructure/MicroserviceTemplate.Persistence/MicroserviceTemplate.Persistence.csproj +++ b/MicroserviceTemplate/src/Infrastructure/MicroserviceTemplate.Persistence/MicroserviceTemplate.Persistence.csproj @@ -1,14 +1,14 @@  - net7.0 + net8.0 enable enable - - + + all runtime; build; native; contentfiles; analyzers; buildtransitive diff --git a/MicroserviceTemplate/src/Presentation/MicroserviceTemplate.Server.REST/MicroserviceTemplate.Server.REST.csproj b/MicroserviceTemplate/src/Presentation/MicroserviceTemplate.Server.REST/MicroserviceTemplate.Server.REST.csproj index d9ff4a6..aae1f80 100644 --- a/MicroserviceTemplate/src/Presentation/MicroserviceTemplate.Server.REST/MicroserviceTemplate.Server.REST.csproj +++ b/MicroserviceTemplate/src/Presentation/MicroserviceTemplate.Server.REST/MicroserviceTemplate.Server.REST.csproj @@ -1,7 +1,7 @@  - net7.0 + net8.0 enable enable @@ -11,20 +11,19 @@ - - - - - - - + + + + + + all runtime; build; native; contentfiles; analyzers; buildtransitive - - - - + + + + diff --git a/MicroserviceTemplate/src/Presentation/MicroserviceTemplate.Server.REST/Startup.cs b/MicroserviceTemplate/src/Presentation/MicroserviceTemplate.Server.REST/Startup.cs index 5d554f8..ec32e8c 100644 --- a/MicroserviceTemplate/src/Presentation/MicroserviceTemplate.Server.REST/Startup.cs +++ b/MicroserviceTemplate/src/Presentation/MicroserviceTemplate.Server.REST/Startup.cs @@ -24,7 +24,7 @@ public void ConfigureServices(IServiceCollection services) { services.AddControllers(); services.AddDbContext(options => options.UseSqlServer(_configuration.GetConnectionString("ToDoDataConnection"))); - services.AddMediatR(typeof(GetToDoListQuery).GetTypeInfo().Assembly); + services.AddMediatR(cfg => cfg.RegisterServicesFromAssemblies(typeof(GetToDoListQuery).GetTypeInfo().Assembly)); services.AddValidatorsFromAssembly(typeof(GetToDoListQuery).GetTypeInfo().Assembly); services.AddTransient(typeof(IPipelineBehavior<,>), typeof(RequestValidationHandler<,>)); services.AddTransient(typeof(IPipelineBehavior<,>), typeof(RequestPerformanceHandler<,>)); diff --git a/MicroserviceTemplate/tests/MicroserviceTemplate.UnitTest/Application/ToDo/CreateToDoCommandHandlerShould.cs b/MicroserviceTemplate/tests/MicroserviceTemplate.UnitTest/Application/ToDo/CreateToDoCommandHandlerShould.cs index 4575880..80d82b1 100644 --- a/MicroserviceTemplate/tests/MicroserviceTemplate.UnitTest/Application/ToDo/CreateToDoCommandHandlerShould.cs +++ b/MicroserviceTemplate/tests/MicroserviceTemplate.UnitTest/Application/ToDo/CreateToDoCommandHandlerShould.cs @@ -1,11 +1,14 @@ using AutoFixture.Xunit2; -using FluentAssertions; + using MediatR; + using MicroserviceTemplate.Application.Interfaces; using MicroserviceTemplate.Application.ToDo.Commands.CreateToDo; using MicroserviceTemplate.Application.ToDo.Events.TaskCreatedEvent; using MicroserviceTemplate.Domain.Entities; + using Moq; + using Xunit; namespace MicroserviceTemplate.UnitTests.Application.ToDo @@ -20,13 +23,12 @@ public async Task ReturnUnitValueWhenSuccessful( [Frozen] Mock mediator, CreateToDoCommandHandler sut) { - var result = await sut.Handle(command, CancellationToken.None); + await sut.Handle(command, CancellationToken.None); todoCommandRepositoryMock.Verify(call => call.CreateToDo( It.Is(x => x.Id.Equals(command.Id) && x.Description.Equals(command.Description) && x.Username.Equals(command.Username))), Times.Once); mediator.Verify(call => call.Publish(It.IsAny(), CancellationToken.None), Times.Once); - result.Should().Be(Unit.Value); } } } diff --git a/MicroserviceTemplate/tests/MicroserviceTemplate.UnitTest/MicroserviceTemplate.UnitTests.csproj b/MicroserviceTemplate/tests/MicroserviceTemplate.UnitTest/MicroserviceTemplate.UnitTests.csproj index a7ae224..8c8afdd 100644 --- a/MicroserviceTemplate/tests/MicroserviceTemplate.UnitTest/MicroserviceTemplate.UnitTests.csproj +++ b/MicroserviceTemplate/tests/MicroserviceTemplate.UnitTest/MicroserviceTemplate.UnitTests.csproj @@ -1,20 +1,20 @@ - net7.0 + net8.0 enable enable false - - - - - - - + + + + + + + all runtime; build; native; contentfiles; analyzers; buildtransitive diff --git a/README.md b/README.md index 8717057..e9fa616 100644 --- a/README.md +++ b/README.md @@ -1,7 +1,7 @@ [![.NET](https://github.com/iongritco/CleanArchitecture-MicroserviceTemplate/actions/workflows/dotnet.yml/badge.svg)](https://github.com/iongritco/CleanArchitecture-MicroserviceTemplate/actions/workflows/dotnet.yml) # CleanArchitecture microservice template -A template for creating a new microservice with Clean Architecture - DDD, CQRS, MediatR, .NET 7, Entity Framework Core +A template for creating a new microservice with Clean Architecture - DDD, CQRS, MediatR, .NET 8, Entity Framework Core **Installation and usage**