Exemplo n.º 1
0
        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);
        }
Exemplo n.º 2
0
        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);
        }
Exemplo n.º 3
0
        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);
        }