Exemplo n.º 1
0
        //[ExpectedException(typeof(Al))]
        public void AddUserBookLoanByBookId_ValidId()
        {
            // Arrange:
            int uid       = 1;
            int bid       = 2;
            var prevCount = _usersService.GetUserBookLoans(uid).Count();

            // Act:
            _usersService.AddUserBookLoanByBookId(uid, bid);

            // Assert:

            // Ensure that a new entity object has been created:
            var currentCount = _usersService.GetUserBookLoans(uid).Count();

            Assert.AreEqual(prevCount + 1, currentCount);

            // Get access to the entity object and assert that
            // the properties have been set:
            var newEntity = _usersService.GetUserBookLoans(uid).Last();

            Assert.AreEqual("C++ fyrir dummies", newEntity.BookTitle);
            Assert.IsNull(newEntity.DateOfReturn);
        }
Exemplo n.º 2
0
 public IActionResult AddUserBookLoanByBookId(int userId, int bookId)
 {
     try
     {
         var bookLoan = _usersService.AddUserBookLoanByBookId(userId, bookId);
         return(Ok(bookLoan));
     }
     catch (UserNotFoundException e)
     {
         return(NotFound(e.Message));
     }
     catch (BookNotFoundException e)
     {
         return(NotFound(e.Message));
     }
     catch (AlreadyBorrowedByUserException e)
     {
         return(NotFound(e.Message));
     }
 }