public async Task Handle_ValidId_EntityShouldNotDeletedBecauseRelatedEntities() { _fixture.RepeatCount = 1; //Create entity to inserted and delete it var temProject = _fixture.Create <Project>(); // Arrange var project = await ContextOperation.CreateEntity(_context, temProject); var sut = new DeleteProjectCommandHandler(_context); // Assert await Assert.ThrowsAsync <DeleteFailureException>(() => sut.Handle(new DeleteProjectCommand { Id = project.Id, OwnerId = project.OwnerId }, CancellationToken.None)); }
public async Task Handle_ValidId_EntityShoulDeletedSuccessfully() { _fixture.RepeatCount = 0; //Create entity to inserted and delete it var temproject = _fixture.Create <Project>(); // Arrange var project = await ContextOperation.CreateEntity(_context, temproject); var sut = new DeleteProjectCommandHandler(_context); // Act await sut.Handle(new DeleteProjectCommand { Id = project.Id, OwnerId = project.OwnerId }, CancellationToken.None); // Assert _context.Projects.Count().ShouldBe(0); }
public async Task ProjectStatusInProgress_Executed_CancelProject() { //Arrange var project = new Project("Nome projeto 1", "descrição do projeto 1", 1, 2, 4000); var projectRepositoryMock = new Mock <IProjectRepository>(); var id = 999999; var deleteProjectCommand = new DeleteProjectCommand(id); var deleteProjectCommandHandler = new DeleteProjectCommandHandler(projectRepositoryMock.Object); projectRepositoryMock.Setup(p => p.GetByIdAsync(id).Result).Returns(project); //Act await deleteProjectCommandHandler.Handle(deleteProjectCommand, new CancellationToken()); //Assert projectRepositoryMock.Verify(p => p.SaveChangesAsync(), Times.Once); }