test domain events (#2)

* test domain events

* cleanup
This commit is contained in:
2022-10-10 12:06:08 +03:00
committed by GitHub
parent 9076dcc542
commit 8d68f1b7a1
13 changed files with 140 additions and 20 deletions
@@ -1,6 +1,9 @@
using MapsterMapper;
using Mapster;
using MapsterMapper;
using MediatR;
using Microsoft.Extensions.DependencyInjection;
using PracticeCalendar.Application.PracticeEvents.Queries;
using PracticeCalendar.Domain.Entities;
using System.Reflection;
namespace PracticeCalendar.Application
@@ -9,10 +12,25 @@ namespace PracticeCalendar.Application
{
public static IServiceCollection AddApplicationServices(this IServiceCollection services)
{
services.AddSingleton<IMapper>(new Mapper(new Mapster.TypeAdapterConfig()));
services.AddMapsterMappings();
services.AddMediatR(Assembly.GetExecutingAssembly());
return services;
}
private static IServiceCollection AddMapsterMappings(this IServiceCollection services)
{
TypeAdapterConfig.GlobalSettings.Default.MapToConstructor(true);
TypeAdapterConfig.GlobalSettings.NewConfig<PracticeEventDto, PracticeEvent>()
.ConstructUsing(src => new PracticeEvent(src.Title, src.Description, src.StartTime, src.EndTime));
var mapsterConfig = new TypeAdapterConfig();
mapsterConfig.NewConfig<PracticeEventDto, PracticeEvent>()
.MapToConstructor(true)
.ConstructUsing(src => new PracticeEvent(src.Title, src.Description, src.StartTime, src.EndTime));
services.AddSingleton<IMapper>(new Mapper(mapsterConfig));
return services;
}
}
}
@@ -28,7 +28,7 @@ namespace PracticeCalendar.Application.PracticeEvents.Commands
public async Task<PracticeEventDto> Handle(CreatePracticeEventCommand request, CancellationToken cancellationToken)
{
var input = request.Event;
var practiceEvent = new PracticeEvent(input.Title, input.Description);
var practiceEvent = new PracticeEvent(input.Title, input.Description, input.StartTime, input.EndTime);
foreach (var att in input.Attendees)
{
practiceEvent.AddAttendee(new Attendee(att.Name, att.EmailAddress));