public async Task Handle_GivenInvalidId_ThrowsNotFoundException() { var invalidId = Guid.NewGuid(); var command = new DeleteTeamCommand { Id = invalidId.ToString() }; await Assert.ThrowsAsync <NotFoundException>(() => _sut.Handle(command, CancellationToken.None)); }
public async Task DeleteTeamCommand_Can_Delete_Team() { using (var dbContext = GetDbContext("DeleteTeamCommand_Can_Delete_Team")) { var fakeRepo = new TeamRepository(dbContext); await fakeRepo.AddAsync(new Domain.Entities.Team { Name = "TestTeamName" }); } using (var dbContext = GetDbContext("DeleteTeamCommand_Can_Delete_Team")) { var fakeRepo = new TeamRepository(dbContext); var fakeLogger = new Mock <ILogger <DeleteTeamCommandHandler> >(); var handler = new DeleteTeamCommandHandler(fakeRepo, GetMapper(), fakeLogger.Object); var command = new DeleteTeamCommand { Id = 1, }; var result = await handler.Handle(command, default); Assert.False(result.Notifications.HasErrors()); Assert.Equal(command.Id, result.TeamDeleteModel.Id); Assert.Equal(Domain.Enumerations.EnumBag.DataState.Inactive, result.TeamDeleteModel.DataState); } }
async void ButtonSupprimerClicked(object sender, EventArgs e) { string NomEquipe = KTContext.Db.Teams.Where(eq => eq.Id == equipeId).Select(m => m.Name).First(); bool reponse = await DisplayAlert(Translate.Supprimer, Translate.EtesVousSur + " \"" + NomEquipe + "\" ?", Translate.Oui, Translate.Non); if (reponse) { var handler = new DeleteTeamCommandHandler(); handler.Handle(new DeleteTeamCommand(equipeId)); await Navigation.PopAsync(); } }
public async Task Handle_GivenValidId_UserIsNotLeader_ThrowsNotOwnedException() { // Login user is member var currentUserServiceMock = new Mock <ICurrentUserService>(); currentUserServiceMock.Setup(m => m.UserId) .Returns(memberId.ToString()); var sut = new DeleteTeamCommandHandler(_context, currentUserServiceMock.Object); var command = new DeleteTeamCommand { Id = validId.ToString() }; await Assert.ThrowsAsync <NotOwnedException>(() => sut.Handle(command, CancellationToken.None)); }
public async Task HandleShouldReturnOk() { // Arrange var id = Guid.NewGuid(); var version = 1; var teamWriteRepositoryMock = new Mock <ITeamWriteRepository>(); teamWriteRepositoryMock.Setup(x => x.DeleteAsync(id, version)).Returns(Task.CompletedTask); var teamWriteRepository = teamWriteRepositoryMock.Object; var command = new DeleteTeamCommand(id, version); var handler = new DeleteTeamCommandHandler(teamWriteRepository); // Act var result = await handler.Handle(command, CancellationToken.None); // Assert result.IsFailure.Should().BeFalse(); result.Should().BeOfType(typeof(Result)); }
public async Task HandleShouldReturnFailWhenDatabaseSpecificErrorOccurs() { // Arrange var id = Guid.NewGuid(); var version = 1; var teamWriteRepositoryMock = new Mock <ITeamWriteRepository>(); teamWriteRepositoryMock.Setup(x => x.DeleteAsync(id, version)).Throws <SomeDatabaseSpecificException>(); var teamWriteRepository = teamWriteRepositoryMock.Object; var command = new DeleteTeamCommand(id, version); var handler = new DeleteTeamCommandHandler(teamWriteRepository); // Act var result = await handler.Handle(command, CancellationToken.None); // Assert result.IsFailure.Should().BeTrue(); result.Failures.Should().OnlyContain(x => x.Message == CustomFailures.DeleteTeamFailure); }
public async Task HandleShouldReturnFailWhenOutdatedVersion() { // Arrange var id = Guid.NewGuid(); var version = 1; var teamWriteRepositoryMock = new Mock <ITeamWriteRepository>(); teamWriteRepositoryMock.Setup(x => x.DeleteAsync(id, version)).Throws <EntityVersionDbException>(); var teamWriteRepository = teamWriteRepositoryMock.Object; var command = new DeleteTeamCommand(id, version); var handler = new DeleteTeamCommandHandler(teamWriteRepository); // Act var result = await handler.Handle(command, CancellationToken.None); // Assert result.IsFailure.Should().BeTrue(); result.Failures.Should().OnlyContain(x => x.Code == HandlerFaultCode.NotMet.Name && x.Message == HandlerFailures.NotMet && x.Target == "version"); }