public async Task Create_MissingName_BadRequestException(string name) { await ExecuteWithDb((db) => { var handler = new CreateGroupCommandHandler( MockMediator.Object, db, Mapper, MockAuthorizationService.Object); var dto = SeedHelper.CreateValidNewGroupDto(db, Mapper); dto.Name = name; return(handler.Handle(new CreateGroupCommand() { Group = dto }, default)); }); }
public async Task Create_NameAlreadyUsed_BadRequestException() { await ExecuteWithDb((db) => { var handler = new CreateGroupCommandHandler( MockMediator.Object, db, Mapper, MockAuthorizationService.Object); var existingGroup = SeedHelper.GetRandomGroup(db); var dto = SeedHelper.CreateValidNewGroupDto(db, Mapper, existingGroup.Name); return(handler.Handle(new CreateGroupCommand() { Group = dto }, default)); }); }
public async Task Update_IdNotFound_EntityNotFoundException() { await ExecuteWithDb((db) => { var handler = new UpdateGroupCommandHandler( MockMediator.Object, db, Mapper, MockAuthorizationService.Object); var dto = SeedHelper.CreateValidNewGroupDto(db, Mapper); dto.Id = int.MaxValue; return(handler.Handle(new UpdateGroupCommand() { Group = dto }, default(CancellationToken))); }); }
public async Task Create_Valid_PublishesGroupCreatedDomainEvent() { await ExecuteWithDb((db) => { var handler = new CreateGroupCommandHandler( MockMediator.Object, db, Mapper, MockAuthorizationService.Object); var dto = SeedHelper.CreateValidNewGroupDto(db, Mapper); return(handler.Handle(new CreateGroupCommand() { Group = dto }, default)); }, (result, db) => { MockMediator.Verify(x => x.Publish(It.IsAny <GroupCreatedDomainEvent>(), It.IsAny <CancellationToken>()), Times.Once); }); }