Ejemplo n.º 1
0
        public void ValidateBookLoan_Lend_ShouldReturnNoErrors()
        {
            //arrage
            Book     book     = BookFactory.ReturnBook().WithBookSituation(BookSituationEnum.Awaiting);
            BookLoan bookLoan = new BookLoan(Guid.NewGuid(), book, PersonFactory.ReturnPerson());

            //act
            bookLoan.LendBook();
            //assert
            DomainNotifications.GetAll().Should().BeEmpty();
        }
Ejemplo n.º 2
0
        public void ValidateBookLoan_Lend_ShouldReturnAlreadyLent()
        {
            //arrange
            Book     book     = BookFactory.ReturnBook().WithBookSituation(BookSituationEnum.Lent);
            BookLoan bookLoan = new BookLoan(Guid.NewGuid(), book, PersonFactory.ReturnPerson());

            //act
            bookLoan.LendBook();

            //assert
            DomainNotifications.GetAll().Should().HaveCount(1)
            .And.Contain(x => x == Messages.BookLoan_BookIsAlreadyLent);
        }
        public async Task <RequestLoanCommandResponseViewModel> Handle(RequestLoanCommand request, CancellationToken cancellationToken)
        {
            RequestLoanCommandResponseViewModel response = new RequestLoanCommandResponseViewModel();

            if (!request.ValidateBookGuid())
            {
                return(response);
            }

            Person person = await _personRepository.GetByDocument(request.PersonDocument, true);

            if (!request.ValidatePersonNotNul(person))
            {
                return(response);
            }

            Book book = await _bookRepository.GetById(Guid.Parse(request.BookId));

            if (!request.ValidateBookNotNul(book))
            {
                return(response);
            }

            BookLoan bookLoan = new BookLoan(Guid.NewGuid(), book, person);

            if (!bookLoan.Validate())
            {
                return(response);
            }

            if (!bookLoan.LendBook())
            {
                return(response);
            }

            await _bookLoanRepository.Add(bookLoan);

            response.LoanId             = bookLoan.BookLoanId;
            response.ExpectedReturnDate = bookLoan.ExpectedReturnDate;

            LoanEffetivatedEvent loanEvent = new LoanEffetivatedEvent(person.Name, person.PhoneNumbers?.FirstOrDefault()?.PhoneNumber, book.Title, "", bookLoan.ExpectedReturnDate);

            _eventDispatcher.AddAfterCommitEvent(loanEvent);

            return(response);
        }