public async Task <Result <Book> > Handle(UpdateBookCommand command) { var author = await _unitOfWork.AuthorRepository.FindAsync(command.AuthorId); if (author is null) { return(Result.Failure <Book>("Author not found")); } Result <Title> titleResult = Entities.Books.Title.Create(command.Title); if (titleResult.IsFailure) { return(Result.Failure <Book>(titleResult.Error)); } Result <Description> descriptionResult = RequiredDescription.Create(command.Description); if (descriptionResult.IsFailure) { return(Result.Failure <Book>(descriptionResult.Error)); } var book = await _unitOfWork.BookRepository.FindAsync(command.BookId); book.EditBook(titleResult.Value, descriptionResult.Value, author); _unitOfWork.BookRepository.Update(book); await _unitOfWork.SaveChangesAsync(); return(Result.Success(book)); }
public void Create_RequiredDescription_Should_Fail_For_EmptyValue() { //Arrange var requiredDescription = string.Empty; //Act var result = RequiredDescription.Create(requiredDescription); //Assert result.IsFailure.Should().BeTrue(); result.Error.Should().Be("Description is required."); }
public void Create_RequiredDescription_Should_Create_For_ValidValue() { //Arrange var fixture = new Fixture(); var requiredDescription = fixture.Create <string>(); //Act var result = RequiredDescription.Create(requiredDescription); //Assert result.IsSuccess.Should().BeTrue(); result.Value.Value.Should().Be(requiredDescription.Trim()); }
public void Create_RequiredDescription_Should_Fail_For_MoreThan1500CharacterValue() { //Arrange var fixture = new Fixture(); var requiredDescription = string.Join(string.Empty, fixture.CreateMany <string>(100)); //Act var result = RequiredDescription.Create(requiredDescription); //Assert result.IsFailure.Should().BeTrue(); result.Error.Should().Be("Description is too long."); }