public async Task ReturnBook_BorrowedBook_BookReturned() { // Arrange var context = _inMemoryLibraryContextFactory.Create(); var user = new User("FirstName", "LastName", new Email("*****@*****.**"), UserRolesConsts.Reader); context.Users.Add(user); context.SaveChanges(); var book = new Book("Title", new Author("FirstName", "LastName"), 2020, "Description"); book.Borrow(); context.Books.Add(book); context.SaveChanges(); var bookLoan = new BookLoan(book.Id, user.Id); context.BookLoans.Add(bookLoan); bookLoan.SetBookBorrowed(); _userRepositoryMock.Setup(x => x.GetAsync(user.Id)).ReturnsAsync(user); _bookRepositoryMock.Setup(x => x.GetAsync(book.Id)).ReturnsAsync(book); _bookRepositoryMock.SetupGet(x => x.UnitOfWork).Returns(_unitOfWorkMock.Object); // Act await _sut.ReturnBook(user.Id, book.Id); // Assert bookLoan.IsReturned.Should().BeTrue(); book.InStock.Should().BeTrue(); }
public void ReturnDueDate_BorrowedBookLoan_CorrectReturnDueDate() { var bookLoan = new BookLoan(1, 1); bookLoan.SetBookBorrowed(); bookLoan.ReturnDueDate.Should().Be(bookLoan.BorrowedDate.Value.AddDays(BookLoan.LoanDaysLimit)); }
public void SetBookBorrowed_BookLoan_BookLoanInBorrowedState() { var bookLoan = new BookLoan(1, 1); bookLoan.SetBookBorrowed(); bookLoan.IsPending.Should().BeFalse(); bookLoan.IsBorrowed.Should().BeTrue(); bookLoan.IsReturned.Should().BeFalse(); }
public async Task <bool> TryLoanBook(BookLoan bookLoan) { var user = await _userRepository.GetAsync(bookLoan.UserId); var book = await _bookRepository.GetAsync(bookLoan.BookId); if (CanBeLoaned(book, user)) { book.Borrow(); bookLoan.SetBookBorrowed(); return(true); } return(false); }
public void GetReturnDueDate_BorrowedBook_ReturnDueDate() { // Arrange var context = _libraryContextFactory.Create(); var book = GetValidBook(); context.Books.Add(book); context.SaveChanges(); var bookLoan = new BookLoan(book.Id, 1); bookLoan.SetBookBorrowed(); context.BookLoans.Add(bookLoan); // Act book = context.Books.First(); // Assert book.GetReturnDueDate().Should().Be(bookLoan.ReturnDueDate); }
public void GetBooksInHandsCount_UserWithBorrowedBook_CorrectNumberOfBooks() { // Arrange var context = _libraryContextFactory.Create(); var user = GetValidUser(); context.Users.Add(user); context.SaveChanges(); var bookLoan = new BookLoan(1, user.Id); bookLoan.SetBookBorrowed(); context.BookLoans.Add(bookLoan); // Act var userBooksInHandCount = user.GetBooksInHandsCount(); var userHasAnyBookInHands = user.HasAnyBookInHands(); // Assert userHasAnyBookInHands.Should().BeTrue(); userBooksInHandCount.Should().Be(1); }