diff --git a/.husky/pre-commit b/.husky/pre-commit new file mode 100644 index 0000000..fd85d23 --- /dev/null +++ b/.husky/pre-commit @@ -0,0 +1,22 @@ +#!/bin/sh +. "$(dirname "$0")/_/husky.sh" + +## husky task runner examples ------------------- +## Note : for local installation use 'dotnet' prefix. e.g. 'dotnet husky' + +## run all tasks +#husky run + +### run all tasks with group: 'group-name' +#husky run --group group-name + +## run task with name: 'task-name' +#husky run --name task-name + +## pass hook arguments to task +#husky run --args "$1" "$2" + +## or put your custom commands ------------------- +#echo 'Husky.Net is awesome!' + +dotnet husky run diff --git a/README.md b/README.md index 8b06836..649effe 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,6 @@ # .NET 8 Clean Architecture Template -.NET 8 Clean Architecture + DDD + CQRS + Specifications + Domain Events + Testing + Identity + Redis +.NET 8 Clean Architecture + DDD + CQRS + Specifications + AutoMapper + Domain Events + Testing + Identity + Redis ## Docker diff --git a/src/Application/Application.csproj b/src/Application/Application.csproj index a952d65..0c95a2b 100644 --- a/src/Application/Application.csproj +++ b/src/Application/Application.csproj @@ -1,4 +1,5 @@  + net8.0 enable @@ -7,6 +8,7 @@ + @@ -16,4 +18,5 @@ + diff --git a/src/Application/Extensions/ApplicationExtensions.cs b/src/Application/Extensions/ApplicationExtensions.cs index 4c56b01..1650ec9 100644 --- a/src/Application/Extensions/ApplicationExtensions.cs +++ b/src/Application/Extensions/ApplicationExtensions.cs @@ -8,5 +8,6 @@ public static void AddApplicationDependencies(this IServiceCollection services) services.AddMediatR(configuration => configuration.RegisterServicesFromAssembly(assembly)); services.AddValidatorsFromAssembly(assembly); + services.AddAutoMapper(assembly); } } diff --git a/src/Application/Features/Commands/PatchCategoryCommand.cs b/src/Application/Features/Commands/PatchCategoryCommand.cs index 4d78024..bc0dfb9 100644 --- a/src/Application/Features/Commands/PatchCategoryCommand.cs +++ b/src/Application/Features/Commands/PatchCategoryCommand.cs @@ -5,18 +5,21 @@ public sealed record PatchCategoryCommand(Guid Id, string Name, string Descripti public sealed class PatchCategoryCommandHandler : IRequestHandler { private readonly IValidator _validator; + private readonly IMapper _mapper; private readonly ICategoriesRepository _repository; private readonly IUnitOfWork _uow; private readonly IEventBus _eventBus; public PatchCategoryCommandHandler( IValidator validator, + IMapper mapper, ICategoriesRepository repository, IUnitOfWork uow, IEventBus eventBus ) { _validator = validator; + _mapper = mapper; _repository = repository; _uow = uow; _eventBus = eventBus; @@ -28,21 +31,12 @@ public async Task Handle(PatchCategoryCommand request, CancellationToken cancell if (!results.IsValid) throw new ValidationException(results.ToString().Replace("\r\n", " ")); - var categoryToPatch = new Category - { - Id = request.Id, - Name = request.Name, - Description = request.Description, - }; + var categoryToPatch = _mapper.Map(request); await _repository.PatchAsync(categoryToPatch, cancellationToken); await _uow.SaveChangesAsync(cancellationToken); await _eventBus.PublishAsync( - new PatchedCategoryEvent( - categoryToPatch.Id, - categoryToPatch.Name, - categoryToPatch.Description - ), + _mapper.Map(categoryToPatch), cancellationToken ); } diff --git a/src/Application/Features/Commands/PatchExpenseCommand.cs b/src/Application/Features/Commands/PatchExpenseCommand.cs index 0eedbde..8ef9d76 100644 --- a/src/Application/Features/Commands/PatchExpenseCommand.cs +++ b/src/Application/Features/Commands/PatchExpenseCommand.cs @@ -11,18 +11,21 @@ Guid CategoryId public sealed class PatchExpenseCommandHandler : IRequestHandler { private readonly IValidator _validator; + private readonly IMapper _mapper; private readonly IExpensesRepository _repository; private readonly IUnitOfWork _uow; private readonly IEventBus _eventBus; public PatchExpenseCommandHandler( IValidator validator, + IMapper mapper, IExpensesRepository repository, IUnitOfWork uow, IEventBus eventBus ) { _validator = validator; + _mapper = mapper; _repository = repository; _uow = uow; _eventBus = eventBus; @@ -34,25 +37,12 @@ public async Task Handle(PatchExpenseCommand request, CancellationToken cancella if (!results.IsValid) throw new ValidationException(results.ToString().Replace("\r\n", " ")); - var expenseToPatch = new Expense - { - Id = request.Id, - Name = request.Name, - Description = request.Description, - Value = request.Value, - CategoryId = request.CategoryId, - }; + var expenseToPatch = _mapper.Map(request); await _repository.PatchAsync(expenseToPatch, cancellationToken); await _uow.SaveChangesAsync(cancellationToken); await _eventBus.PublishAsync( - new PatchedExpenseEvent( - expenseToPatch.Id, - expenseToPatch.Name, - expenseToPatch.Description, - expenseToPatch.Value, - expenseToPatch.CategoryId - ), + _mapper.Map(expenseToPatch), cancellationToken ); } diff --git a/src/Application/Features/Commands/PostCategoryCommand.cs b/src/Application/Features/Commands/PostCategoryCommand.cs index 50d5b2f..ebd22e8 100644 --- a/src/Application/Features/Commands/PostCategoryCommand.cs +++ b/src/Application/Features/Commands/PostCategoryCommand.cs @@ -5,18 +5,21 @@ public sealed record PostCategoryCommand(string Name, string Description) : IReq public sealed class PostCategoryCommandHandler : IRequestHandler { private readonly IValidator _validator; + private readonly IMapper _mapper; private readonly ICategoriesRepository _repository; private readonly IUnitOfWork _uow; private readonly IEventBus _eventBus; public PostCategoryCommandHandler( IValidator validator, + IMapper mapper, ICategoriesRepository repository, IUnitOfWork uow, IEventBus eventBus ) { _validator = validator; + _mapper = mapper; _repository = repository; _uow = uow; _eventBus = eventBus; @@ -28,21 +31,12 @@ public async Task Handle(PostCategoryCommand request, CancellationToken cancella if (!results.IsValid) throw new ValidationException(results.ToString().Replace("\r\n", " ")); - var categoryToPost = new Category - { - Id = Guid.NewGuid(), - Name = request.Name, - Description = request.Description, - }; + var categoryToPost = _mapper.Map(request); await _repository.PostAsync(categoryToPost, cancellationToken); await _uow.SaveChangesAsync(cancellationToken); await _eventBus.PublishAsync( - new PostedCategoryEvent( - categoryToPost.Id, - categoryToPost.Name, - categoryToPost.Description - ), + _mapper.Map(categoryToPost), cancellationToken ); } diff --git a/src/Application/Features/Commands/PostExpenseCommand.cs b/src/Application/Features/Commands/PostExpenseCommand.cs index b1ccd37..d98ffc7 100644 --- a/src/Application/Features/Commands/PostExpenseCommand.cs +++ b/src/Application/Features/Commands/PostExpenseCommand.cs @@ -10,18 +10,21 @@ Guid CategoryId public sealed class PostExpenseCommandHandler : IRequestHandler { private readonly IValidator _validator; + private readonly IMapper _mapper; private readonly IExpensesRepository _repository; private readonly IUnitOfWork _uow; private readonly IEventBus _eventBus; public PostExpenseCommandHandler( IValidator validator, + IMapper mapper, IExpensesRepository repository, IUnitOfWork uow, IEventBus eventBus ) { _validator = validator; + _mapper = mapper; _repository = repository; _uow = uow; _eventBus = eventBus; @@ -33,25 +36,12 @@ public async Task Handle(PostExpenseCommand request, CancellationToken cancellat if (!results.IsValid) throw new ValidationException(results.ToString().Replace("\r\n", " ")); - var expenseToPost = new Expense - { - Id = Guid.NewGuid(), - Name = request.Name, - Description = request.Description, - Value = request.Value, - CategoryId = request.CategoryId, - }; + var expenseToPost = _mapper.Map(request); await _repository.PostAsync(expenseToPost, cancellationToken); await _uow.SaveChangesAsync(cancellationToken); await _eventBus.PublishAsync( - new PostedExpenseEvent( - expenseToPost.Id, - expenseToPost.Name, - expenseToPost.Description, - expenseToPost.Value, - expenseToPost.CategoryId - ), + _mapper.Map(expenseToPost), cancellationToken ); } diff --git a/src/Application/Features/Queries/GetAllCategoriesQuery.cs b/src/Application/Features/Queries/GetAllCategoriesQuery.cs index 9c7faea..a0e76e9 100644 --- a/src/Application/Features/Queries/GetAllCategoriesQuery.cs +++ b/src/Application/Features/Queries/GetAllCategoriesQuery.cs @@ -9,14 +9,17 @@ public sealed class GetAllCategoriesQueryHandler : IRequestHandler> { private readonly ICategoriesRepository _repository; + private readonly IMapper _mapper; private readonly IRedisCache _redisCache; public GetAllCategoriesQueryHandler( ICategoriesRepository repository, + IMapper mapper, IRedisCache redisCache ) { _repository = repository; + _mapper = mapper; _redisCache = redisCache; } @@ -39,7 +42,7 @@ CancellationToken cancellationToken containedWord: request.ContainedWord ) ) - .Select(c => new CategoryDTO(c.Id, c.Name, c.Description, c.Expenses)) + .Select(c => _mapper.Map(c)) .ToPagedListAsync(request.Page, request.PageSize, cancellationToken); await _redisCache.SetCachedData>( diff --git a/src/Application/Features/Queries/GetAllExpensesQuery.cs b/src/Application/Features/Queries/GetAllExpensesQuery.cs index c5203ea..f219513 100644 --- a/src/Application/Features/Queries/GetAllExpensesQuery.cs +++ b/src/Application/Features/Queries/GetAllExpensesQuery.cs @@ -10,11 +10,17 @@ public sealed class GetAllExpensesQueryHandler : IRequestHandler> { private readonly IExpensesRepository _repository; + private readonly IMapper _mapper; private readonly IRedisCache _redisCache; - public GetAllExpensesQueryHandler(IExpensesRepository repository, IRedisCache redisCache) + public GetAllExpensesQueryHandler( + IExpensesRepository repository, + IMapper mapper, + IRedisCache redisCache + ) { _repository = repository; + _mapper = mapper; _redisCache = redisCache; } @@ -38,7 +44,7 @@ CancellationToken cancellationToken categoryId: request.CategoryId ) ) - .Select(x => new ExpenseDTO(x.Id, x.Name, x.Description, x.Value, x.CategoryId)) + .Select(e => _mapper.Map(e)) .ToPagedListAsync(request.Page, request.PageSize, cancellationToken); await _redisCache.SetCachedData>( diff --git a/src/Application/Features/Queries/GetCategoryQuery.cs b/src/Application/Features/Queries/GetCategoryQuery.cs index 5a8ec6b..513d6c1 100644 --- a/src/Application/Features/Queries/GetCategoryQuery.cs +++ b/src/Application/Features/Queries/GetCategoryQuery.cs @@ -5,10 +5,12 @@ public sealed record GetCategoryQuery(Guid Id) : IRequest public class GetCategoryQueryHandler : IRequestHandler { private readonly ICategoriesRepository _repository; + private readonly IMapper _mapper; - public GetCategoryQueryHandler(ICategoriesRepository repository) + public GetCategoryQueryHandler(ICategoriesRepository repository, IMapper mapper) { _repository = repository; + _mapper = mapper; } public async Task Handle( @@ -22,12 +24,7 @@ await _repository.GetBySpecAsync( cancellationToken ) ?? throw new NotFoundException(request.Id); - return new CategoryDTO( - category.Id, - category.Name, - category.Description, - category.Expenses - ); + return _mapper.Map(category); } } diff --git a/src/Application/Features/Queries/GetExpenseQuery.cs b/src/Application/Features/Queries/GetExpenseQuery.cs index 5717fae..0d8f664 100644 --- a/src/Application/Features/Queries/GetExpenseQuery.cs +++ b/src/Application/Features/Queries/GetExpenseQuery.cs @@ -5,10 +5,12 @@ public sealed record GetExpenseQuery(Guid Id) : IRequest public sealed class GetExpenseQueryHandler : IRequestHandler { private readonly IExpensesRepository _repository; + private readonly IMapper _mapper; - public GetExpenseQueryHandler(IExpensesRepository repository) + public GetExpenseQueryHandler(IExpensesRepository repository, IMapper mapper) { _repository = repository; + _mapper = mapper; } public async Task Handle( @@ -22,13 +24,7 @@ await _repository.GetBySpecAsync( cancellationToken ) ?? throw new NotFoundException(request.Id); - return new ExpenseDTO( - expense.Id, - expense.Name, - expense.Description, - expense.Value, - expense.CategoryId - ); + return _mapper.Map(expense); } } diff --git a/src/Application/Features/Shared/CategoryDTO.cs b/src/Application/Features/Shared/CategoryDTO.cs index bed93ca..357fc2f 100644 --- a/src/Application/Features/Shared/CategoryDTO.cs +++ b/src/Application/Features/Shared/CategoryDTO.cs @@ -1,3 +1,3 @@ namespace Application.Features.Shared; -public record CategoryDTO(Guid Id, string Name, string Description, List Expenses); +public record CategoryDTO(Guid Id, string Name, string Description, List Expenses); diff --git a/src/Application/GlobalUsings.cs b/src/Application/GlobalUsings.cs index 6aea2e4..db25908 100644 --- a/src/Application/GlobalUsings.cs +++ b/src/Application/GlobalUsings.cs @@ -1,11 +1,12 @@ global using Application.Abstractions; -global using Application.Contexts; +global using Application.Features.Commands; global using Application.Features.DomainEvents; global using Application.Features.Shared; global using Application.Messages; global using Application.Repositories; global using Application.Requests; global using Ardalis.Specification; +global using AutoMapper; global using Domain.Cache; global using Domain.Entities; global using Domain.Exceptions; diff --git a/src/Application/Profiles/CategoriesProfile.cs b/src/Application/Profiles/CategoriesProfile.cs new file mode 100644 index 0000000..0598b37 --- /dev/null +++ b/src/Application/Profiles/CategoriesProfile.cs @@ -0,0 +1,13 @@ +namespace Application.Profiles; + +public class CategoriesProfile : Profile +{ + public CategoriesProfile() + { + CreateMap(); + CreateMap(); + CreateMap(); + CreateMap(); + CreateMap(); + } +} diff --git a/src/Application/Profiles/ExpensesProfile.cs b/src/Application/Profiles/ExpensesProfile.cs new file mode 100644 index 0000000..ad30593 --- /dev/null +++ b/src/Application/Profiles/ExpensesProfile.cs @@ -0,0 +1,13 @@ +namespace Application.Profiles; + +public class ExpensesProfile : Profile +{ + public ExpensesProfile() + { + CreateMap(); + CreateMap(); + CreateMap(); + CreateMap(); + CreateMap(); + } +} diff --git a/src/Infrastructure/Infrastructure.csproj b/src/Infrastructure/Infrastructure.csproj index 7cb2bdd..83fbe87 100644 --- a/src/Infrastructure/Infrastructure.csproj +++ b/src/Infrastructure/Infrastructure.csproj @@ -1,9 +1,10 @@  - - - - + + net8.0 + enable + enable + @@ -20,10 +21,9 @@ - - net8.0 - enable - enable - + + + + diff --git a/src/Presentation/Presentation.csproj b/src/Presentation/Presentation.csproj index b9ce553..06275d4 100644 --- a/src/Presentation/Presentation.csproj +++ b/src/Presentation/Presentation.csproj @@ -7,8 +7,8 @@ + - diff --git a/src/WebApi/WebApi.csproj b/src/WebApi/WebApi.csproj index 7af33f0..5be52b8 100644 --- a/src/WebApi/WebApi.csproj +++ b/src/WebApi/WebApi.csproj @@ -2,8 +2,8 @@ net8.0 - enable enable + enable diff --git a/tests/UnitTests/Features/Commands/PatchCategoryCommandHandlerTests.cs b/tests/UnitTests/Features/Commands/PatchCategoryCommandHandlerTests.cs index 9c655bc..d3fde21 100644 --- a/tests/UnitTests/Features/Commands/PatchCategoryCommandHandlerTests.cs +++ b/tests/UnitTests/Features/Commands/PatchCategoryCommandHandlerTests.cs @@ -4,6 +4,7 @@ public sealed class PatchCategoryCommandHandlerTests { private readonly CancellationToken _cancellationToken; private readonly Mock> _validator; + private readonly IMapper _mapper; private readonly Mock _repository; private readonly Mock _uow; private readonly Mock _eventBus; @@ -13,12 +14,14 @@ public PatchCategoryCommandHandlerTests() { _cancellationToken = new(); _validator = new(); + _mapper = new MapperConfiguration(c => c.AddProfile()).CreateMapper(); _repository = new(); _uow = new(); _eventBus = new(); _handler = new PatchCategoryCommandHandler( _validator.Object, + _mapper, _repository.Object, _uow.Object, _eventBus.Object diff --git a/tests/UnitTests/Features/Commands/PatchExpenseCommandHandlerTests.cs b/tests/UnitTests/Features/Commands/PatchExpenseCommandHandlerTests.cs index c89181c..06a1d48 100644 --- a/tests/UnitTests/Features/Commands/PatchExpenseCommandHandlerTests.cs +++ b/tests/UnitTests/Features/Commands/PatchExpenseCommandHandlerTests.cs @@ -4,6 +4,7 @@ public sealed class PatchExpenseCommandHandlerTests { private readonly CancellationToken _cancellationToken; private readonly Mock> _validator; + private readonly IMapper _mapper; private readonly Mock _repository; private readonly Mock _uow; private readonly Mock _eventBus; @@ -13,12 +14,14 @@ public PatchExpenseCommandHandlerTests() { _cancellationToken = new(); _validator = new(); + _mapper = new MapperConfiguration(c => c.AddProfile()).CreateMapper(); _repository = new(); _uow = new(); _eventBus = new(); _handler = new PatchExpenseCommandHandler( _validator.Object, + _mapper, _repository.Object, _uow.Object, _eventBus.Object diff --git a/tests/UnitTests/Features/Commands/PostCategoryCommandHandlerTests.cs b/tests/UnitTests/Features/Commands/PostCategoryCommandHandlerTests.cs index 9a1621e..f7c7a8e 100644 --- a/tests/UnitTests/Features/Commands/PostCategoryCommandHandlerTests.cs +++ b/tests/UnitTests/Features/Commands/PostCategoryCommandHandlerTests.cs @@ -4,6 +4,7 @@ public sealed class PostCategoryCommandHandlerTests { private readonly CancellationToken _cancellationToken; private readonly Mock> _validator; + private readonly IMapper _mapper; private readonly Mock _repository; private readonly Mock _uow; private readonly Mock _eventBus; @@ -13,12 +14,14 @@ public PostCategoryCommandHandlerTests() { _cancellationToken = new(); _validator = new(); + _mapper = new MapperConfiguration(c => c.AddProfile()).CreateMapper(); _repository = new(); _uow = new(); _eventBus = new(); _handler = new PostCategoryCommandHandler( _validator.Object, + _mapper, _repository.Object, _uow.Object, _eventBus.Object diff --git a/tests/UnitTests/Features/Commands/PostExpenseCommandHandlerTests.cs b/tests/UnitTests/Features/Commands/PostExpenseCommandHandlerTests.cs index f311892..21468bc 100644 --- a/tests/UnitTests/Features/Commands/PostExpenseCommandHandlerTests.cs +++ b/tests/UnitTests/Features/Commands/PostExpenseCommandHandlerTests.cs @@ -4,6 +4,7 @@ public sealed class PostExpenseCommandHandlerTests { private readonly CancellationToken _cancellationToken; private readonly Mock> _validator; + private readonly IMapper _mapper; private readonly Mock _repository; private readonly Mock _uow; private readonly Mock _eventBus; @@ -13,12 +14,14 @@ public PostExpenseCommandHandlerTests() { _cancellationToken = new(); _validator = new(); + _mapper = new MapperConfiguration(c => c.AddProfile()).CreateMapper(); _repository = new(); _uow = new(); _eventBus = new(); _handler = new PostExpenseCommandHandler( _validator.Object, + _mapper, _repository.Object, _uow.Object, _eventBus.Object diff --git a/tests/UnitTests/Features/Queries/GetAllCategoriesQueryHandlerTests.cs b/tests/UnitTests/Features/Queries/GetAllCategoriesQueryHandlerTests.cs index 8bf385c..41ecfe4 100644 --- a/tests/UnitTests/Features/Queries/GetAllCategoriesQueryHandlerTests.cs +++ b/tests/UnitTests/Features/Queries/GetAllCategoriesQueryHandlerTests.cs @@ -1,8 +1,11 @@ +using Application.Profiles; + namespace UnitTests.Features.Queries; public sealed class GetAllCategoriesQueryHandlerTests { private readonly CancellationToken _cancellationToken; + private readonly IMapper _mapper; private readonly Mock _repository; private readonly Mock _redisCache; private readonly GetAllCategoriesQueryHandler _handler; @@ -10,10 +13,15 @@ public sealed class GetAllCategoriesQueryHandlerTests public GetAllCategoriesQueryHandlerTests() { _cancellationToken = new(); + _mapper = new MapperConfiguration(c => c.AddProfile()).CreateMapper(); _repository = new(); _redisCache = new(); - _handler = new GetAllCategoriesQueryHandler(_repository.Object, _redisCache.Object); + _handler = new GetAllCategoriesQueryHandler( + _repository.Object, + _mapper, + _redisCache.Object + ); } [Fact] diff --git a/tests/UnitTests/Features/Queries/GetAllExpensesQueryHandlerTests.cs b/tests/UnitTests/Features/Queries/GetAllExpensesQueryHandlerTests.cs index c53a80f..51e610c 100644 --- a/tests/UnitTests/Features/Queries/GetAllExpensesQueryHandlerTests.cs +++ b/tests/UnitTests/Features/Queries/GetAllExpensesQueryHandlerTests.cs @@ -3,6 +3,7 @@ namespace UnitTests.Features.Queries; public sealed class GetAllExpensesQueryHandlerTests { private readonly CancellationToken _cancellationToken; + private readonly IMapper _mapper; private readonly Mock _repository; private readonly Mock _redisCache; private readonly GetAllExpensesQueryHandler _handler; @@ -10,10 +11,11 @@ public sealed class GetAllExpensesQueryHandlerTests public GetAllExpensesQueryHandlerTests() { _cancellationToken = new(); + _mapper = new MapperConfiguration(c => c.AddProfile()).CreateMapper(); _repository = new(); _redisCache = new(); - _handler = new GetAllExpensesQueryHandler(_repository.Object, _redisCache.Object); + _handler = new GetAllExpensesQueryHandler(_repository.Object, _mapper, _redisCache.Object); } [Fact] diff --git a/tests/UnitTests/Features/Queries/GetCategoryQueryHandlerTests.cs b/tests/UnitTests/Features/Queries/GetCategoryQueryHandlerTests.cs index 798a332..bb60837 100644 --- a/tests/UnitTests/Features/Queries/GetCategoryQueryHandlerTests.cs +++ b/tests/UnitTests/Features/Queries/GetCategoryQueryHandlerTests.cs @@ -3,15 +3,17 @@ namespace Application.UnitTests.Categories.GetAsync; public sealed class GetCategoryQueryHandlerTests { private readonly CancellationToken _cancellationToken; + private readonly IMapper _mapper; private readonly Mock _repository; private readonly GetCategoryQueryHandler _handler; public GetCategoryQueryHandlerTests() { _cancellationToken = new(); + _mapper = new MapperConfiguration(c => c.AddProfile()).CreateMapper(); _repository = new(); - _handler = new GetCategoryQueryHandler(_repository.Object); + _handler = new GetCategoryQueryHandler(_repository.Object, _mapper); } [Fact] diff --git a/tests/UnitTests/Features/Queries/GetExpenseQueryHandlerTests.cs b/tests/UnitTests/Features/Queries/GetExpenseQueryHandlerTests.cs index 1098458..08727f9 100644 --- a/tests/UnitTests/Features/Queries/GetExpenseQueryHandlerTests.cs +++ b/tests/UnitTests/Features/Queries/GetExpenseQueryHandlerTests.cs @@ -3,15 +3,16 @@ namespace Application.UnitTests.Expenses.GetAsync; public sealed class GetExpenseQueryHandlerTests { private readonly CancellationToken _cancellationToken; + private readonly IMapper _mapper; private readonly Mock _repository; private readonly GetExpenseQueryHandler _handler; public GetExpenseQueryHandlerTests() { _cancellationToken = new(); + _mapper = new MapperConfiguration(c => c.AddProfile()).CreateMapper(); _repository = new(); - - _handler = new GetExpenseQueryHandler(_repository.Object); + _handler = new GetExpenseQueryHandler(_repository.Object, _mapper); } [Fact] diff --git a/tests/UnitTests/GlobalUsings.cs b/tests/UnitTests/GlobalUsings.cs index bc189c1..c7bcc34 100644 --- a/tests/UnitTests/GlobalUsings.cs +++ b/tests/UnitTests/GlobalUsings.cs @@ -14,7 +14,9 @@ global using static Application.Features.Queries.GetCategoryQuery; global using static Application.Features.Queries.GetExpenseQuery; global using Application.Features.Shared; +global using Application.Profiles; global using Application.Repositories; +global using AutoMapper; global using Domain.Cache; global using Domain.Entities; global using static Domain.Extensions.Collections.Collections; diff --git a/tests/UnitTests/UnitTests.csproj b/tests/UnitTests/UnitTests.csproj index c592f94..85f5904 100644 --- a/tests/UnitTests/UnitTests.csproj +++ b/tests/UnitTests/UnitTests.csproj @@ -4,12 +4,12 @@ net8.0 enable enable - false true + @@ -21,12 +21,12 @@ - + + - - + diff --git a/tests/UnitTests/Validators/TODO.cs b/tests/UnitTests/Validators/TODO.cs new file mode 100644 index 0000000..0501c79 --- /dev/null +++ b/tests/UnitTests/Validators/TODO.cs @@ -0,0 +1 @@ +/*TODO: add validators*/