Exemplo n.º 1
0
        public async Task TryLoanBook_BookInStock_BookLoaned()
        {
            // 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");

            context.Books.Add(book);
            context.SaveChanges();

            var bookLoan = new BookLoan(book.Id, user.Id);

            context.BookLoans.Add(bookLoan);

            _userRepositoryMock.Setup(x => x.GetAsync(user.Id)).ReturnsAsync(user);
            _bookRepositoryMock.Setup(x => x.GetAsync(book.Id)).ReturnsAsync(book);

            // Act
            var result = await _sut.TryLoanBook(bookLoan);

            // Assert
            result.Should().BeTrue();
            bookLoan.IsBorrowed.Should().BeTrue();
            book.InStock.Should().BeFalse();
        }
Exemplo n.º 2
0
        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();
        }
Exemplo n.º 3
0
        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 BookLoanFinishedEventHandlerTests()
        {
            _bookLoanServiceMock = new Mock <IBookLoanService>();
            _userRepositoryMock  = new Mock <IUserRepository>();
            _unitOfWorkMock      = new Mock <IUnitOfWork>();

            var context = _libraryContextFactory.Create();
            var user    = new User("FirstName", "LastName", new Email("*****@*****.**"), UserRolesConsts.Reader);

            context.Users.Add(user);
            context.SaveChanges();

            var bookLoan = new BookLoan(1, user.Id);

            context.BookLoans.Add(bookLoan);

            _userRepositoryMock.Setup(x => x.GetAsync(It.IsAny <int>()))
            .ReturnsAsync(user);
            _userRepositoryMock.SetupGet(x => x.UnitOfWork)
            .Returns(_unitOfWorkMock.Object);
        }
Exemplo n.º 5
0
        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);
        }
 public GetReaderDetailsQueryHandlerTests()
 {
     _mapper = new UserMapper();
     _libraryContextFactory = new InMemoryLibraryContextFactory();
     _libraryContext        = _libraryContextFactory.Create();
 }
Exemplo n.º 7
0
 public GetBookListQueryHandlerTests()
 {
     _mapper = new BookListMapper();
     _libraryContextFactory = new InMemoryLibraryContextFactory();
     _libraryContext        = _libraryContextFactory.Create();
 }