public async Task <IActionResult> BorrowBook(long bookId, BorrowBookCommand command)
        {
            command.BookId = bookId;

            await Mediator.Send(command);

            return(Accepted());
        }
Exemple #2
0
        public void BorrowBookToUser(Guid userAggregateRootId, Guid bookAggregateRootId)
        {
            BorrowBookCommand command = new BorrowBookCommand
            {
                UserAggregateRootId = userAggregateRootId,
                BookAggregateRootId = bookAggregateRootId
            };

            CommitCommand(command);
        }
Exemple #3
0
        public void HandleCommand(BorrowBookCommand command)
        {
            User user = DomainRepository.Get <User>(command.UserAggregateRootId);
            Book book = DomainRepository.Get <Book>(command.BookAggregateRootId);

            user.BorrowBook(book);
            book.IssueStock(1);
            DomainRepository.Save(user);
            DomainRepository.Save(book);
            DomainRepository.Commit();
        }
        public void Throw_If_ParamethersCount_IsInvalid()
        {
            var parameters = new List <string>()
            {
                "Fname", "Mname", "Lname"
            };
            var userServiceMock = new Mock <IUsersServices>();
            var command         = new BorrowBookCommand(userServiceMock.Object);

            command.Execute(parameters);
        }
Exemple #5
0
        void WHEN_User_borrows_book()
        {
            command = BorrowBookCommand.With
                      .ReaderCardId(cardId)
                      .BookIsbn(isbn)
                      .StartDate(startDate)
                      .BorrowingDuration(duration)
                      .Get;

            useCase.Handle(command);
        }
        public void BorrowBook(string cardId, string isbn)
        {
            BorrowBookCommand command
                = BorrowBookCommand.With
                  .ReaderCardId(cardId)
                  .BookIsbn(isbn)
                  .StartDate(DateTime.Now)
                  .BorrowingDuration(5)
                  .Get;

            UseCase.Handle(command);
        }
 public bool Handle(BorrowBookCommand message)
 {
     using (IDomainRepository domainRepository = this.GetDomainRepository())
     {
         UserAccount userAccount = domainRepository.Get <UserAccount>(message.UserAccountAggregateRootId);
         Book        book        = domainRepository.Get <Book>(message.BookAggregateRootId);
         IUserAccountBookTransferService bookTransService = this.GetBookTransferService();
         bookTransService.BorrowBookToUser(userAccount, book);
         domainRepository.Save(userAccount);
         domainRepository.Save(book);
         domainRepository.Commit();
         return(domainRepository.Committed);
     }
 }
Exemple #8
0
        public void ShouldBorrowBookToRepository()
        {
            var userRepository = new UserRepository();
            var firstName      = "Kinga";
            var surName        = "Sadowska";

            var bookRepository = new BookRepository();
            var title          = "A Game of Thrones";
            var author         = "George R. R. Martin";

            var quantity = 1;

            var consoleOperator = new Mock <IConsoleOperator>();

            consoleOperator.Setup(x => x.GetUser()).Returns((firstName, surName, true));
            consoleOperator.Setup(x => x.WriteLine(It.IsAny <string>()));
            consoleOperator.Setup(x => x.GetBookDescription()).Returns((title, author, true));
            consoleOperator.Setup(x => x.GetBookDescriptionWithQuantity()).Returns((title, author, (uint)quantity, true));

            var addUserCommand = new AddUserCommand(userRepository, consoleOperator.Object);

            addUserCommand.Execute();

            var addBookCommand = new AddBookCommand(bookRepository, consoleOperator.Object);

            addBookCommand.Execute();

            Assert.Single(userRepository.Users);
            Assert.Single(bookRepository.Book);

            var borrowBookCommand = new BorrowBookCommand(bookRepository, userRepository, consoleOperator.Object);

            borrowBookCommand.Execute();

            Book first = null;

            foreach (var book in bookRepository.Book)
            {
                first = book;
                break;
            }

            Assert.Equal(first.CurrentBorrowing.User.FirstName, firstName);
            Assert.Equal(bookRepository.Book.FirstOrDefault().CurrentBorrowing.User.LastName, surName);
            Assert.True(bookRepository.Book.FirstOrDefault().IsCurrentBorrowed);
        }
        public void Call_UserService()
        {
            var parameters = new List <string>()
            {
                "Fname", "Mname", "Lname", "BookTitle"
            };
            string fullName        = parameters[0] + ' ' + parameters[1] + ' ' + parameters[2];
            var    userServiceMock = new Mock <IUsersServices>();
            var    command         = new BorrowBookCommand(userServiceMock.Object);

            userServiceMock.Setup(u => u.BorrowBook(It.IsAny <string>(), It.IsAny <string>(), It.IsAny <string>(), It.IsAny <string>()))
            .Returns(new UserViewModel()
            {
                FullName = fullName
            });

            command.Execute(parameters);

            userServiceMock.Verify(u => u.BorrowBook(parameters[0], parameters[1], parameters[2], parameters[3]), Times.Once);
        }
 public void BorrowBookToUser(long bookId, long userAccountId)
 {
     try
     {
         BorrowBookCommand command = new BorrowBookCommand
         {
             BookAggregateRootId        = bookId,
             UserAccountAggregateRootId = userAccountId
         };
         this.CommitCommand(command);
     }
     catch (DomainException ex)
     {
         WCFServiceFault sf = new WCFServiceFault
         {
             Message    = ex.Message,
             StackTrace = ex.StackTrace
         };
         throw new FaultException <WCFServiceFault>(sf, new FaultReason(sf.Message));
     }
 }
        public void Return_SuccessMessage()
        {
            var parameters = new List <string>()
            {
                "Fname", "Mname", "Lname", "BookTitle"
            };
            string fullName        = parameters[0] + ' ' + parameters[1] + ' ' + parameters[2];
            var    userServiceMock = new Mock <IUsersServices>();
            var    command         = new BorrowBookCommand(userServiceMock.Object);

            userServiceMock.Setup(u => u.BorrowBook(It.IsAny <string>(), It.IsAny <string>(), It.IsAny <string>(), It.IsAny <string>()))
            .Returns(new UserViewModel()
            {
                FullName = fullName
            });

            string message = command.Execute(parameters);


            Assert.AreEqual($"User {fullName} borrow the book {parameters[3]}", message);
        }
Exemple #12
0
        public void Handle(BorrowBookCommand command)
        {
            Reader reader = repository.FindReader(command.ReaderCardId);

            Book book = repository.FindBook(command.BookIsbn);

            Borrowing borrowing = create.Borrowing(reader, book,
                                                   command.StartDate,
                                                   command.BorrowingDuration);

            repository.Store(borrowing);

            BorrowingConfirmation confirmation
                = BorrowingConfirmation.With
                  .Title(book.Title)
                  .Author(book.Author)
                  .ReaderFullname(reader.Fullname)
                  .BorrowingDuration(command.BorrowingDuration)
                  .Get;

            _presenter.ConfirmBorrowing(confirmation);
        }