public async Task <ReturnBookCommandResponseViewModel> Handle(ReturnBookCommand request, CancellationToken cancellationToken) { ReturnBookCommandResponseViewModel response = new ReturnBookCommandResponseViewModel(); if (!request.ValidateBookLoanGuid()) { return(response); } BookLoan bookLoan = await _bookLoanRepository.GetByLoanId(Guid.Parse(request.LoanId), true); if (!request.ValidateBookLoanExists(bookLoan)) { return(response); } if (!bookLoan.ReturnBook()) { return(response); } _bookLoanRepository.Update(bookLoan); return(response); }
public void ValidateBookLoan_Return_ShouldReturnNoErrors() { //arrage BookLoan bookLoan = new BookLoan(Guid.NewGuid(), BookFactory.ReturnBook().WithBookSituation(BookSituationEnum.Lent), PersonFactory.ReturnPerson()); //act bookLoan.ReturnBook(); //assert DomainNotifications.GetAll().Should().BeEmpty(); bookLoan.Book.BookSituation.Value.Should().Be(BookSituationEnum.Awaiting.Value); }
public void ValidateBookLoadn_Return_ShouldReturnBookNotLent() { //arrange Book book = BookFactory.ReturnBook().WithBookSituation(BookSituationEnum.Awaiting); BookLoan bookLoan = new BookLoan(Guid.NewGuid(), book, PersonFactory.ReturnPerson()); //act bookLoan.ReturnBook(); //assert DomainNotifications.GetAll().Should().HaveCount(1) .And.Contain(x => x == Messages.BookLoan_BookIsNotLent); }