public async Task Delete_Author_Should_Fail_For_Null_Author() { //Arrange var fixture = new Fixture(); var command = fixture.Create <DeleteAuthorCommand>(); var mockUnitOfWork = new Mock <IUnitOfWork>(); var mockAuthorRepository = new Mock <IAsyncRepository <Author> >(); mockAuthorRepository.Setup(x => x.FindAsync(It.IsAny <long>())).ReturnsAsync(It.IsAny <Author>()); mockUnitOfWork.Setup(x => x.AuthorRepository).Returns(mockAuthorRepository.Object); var removeAuthorHandler = new RemoveCommandHandler(mockUnitOfWork.Object); //Act var result = await removeAuthorHandler.Handle(command); //Assert result.IsFailure.Should().BeTrue(); result.Error.Should().Be($"No Author found for Id {command.Id}."); }
public async Task Delete_Author_Should_Call_Remove_Method_And_SaveChanges_Once() { //Arrange var fixture = new Fixture(); var command = fixture.Create <DeleteAuthorCommand>(); fixture.Customize(new AuthorCustomization()); var author = fixture.Create <Author>(); var mockUnitOfWork = new Mock <IUnitOfWork>(); var mockAuthorRepository = new Mock <IAsyncRepository <Author> >(); mockAuthorRepository.Setup(x => x.FindAsync(It.IsAny <long>())).ReturnsAsync(author); mockUnitOfWork.Setup(x => x.AuthorRepository).Returns(mockAuthorRepository.Object); var removeAuthorHandler = new RemoveCommandHandler(mockUnitOfWork.Object); //Act var result = await removeAuthorHandler.Handle(command); //Assert mockAuthorRepository.Verify(x => x.Remove(It.IsAny <Author>()), Times.Once); mockUnitOfWork.Verify(x => x.SaveChangesAsync(), Times.Once); result.IsSuccess.Should().BeTrue(); }