public async Task CheckoutBookReturnsBookNotFoundWhenBookIsNotInRepository() { var bookRepositoryMock = new Mock<IBookRepository>(); bookRepositoryMock.Setup(b => b.GetBook(It.IsAny<int>())) .ReturnsAsync(null); var userServiceMock = new Mock<IUserService>(); userServiceMock.Setup(s => s.UserId).Returns("test"); userServiceMock.Setup(s => s.UserName).Returns("test"); var bookService = new BooksService(bookRepositoryMock.Object, userServiceMock.Object); var result = await bookService.CheckOutBook(1); Assert.AreEqual(CheckedOutBookState.BookNotFound, result.State); }
public async Task CheckoutBookReturnsSuccess() { var bookDTO = new BookDTO() { Author = "test", Available = true, BookId = 1, Title = "test" }; bookDTO.PhysicalBooks = new List<PhysicalBook>() { new PhysicalBook() { BookId = bookDTO.BookId, Id=1, UserId = null} }; var bookRepositoryMock = new Mock<IBookRepository>(); bookRepositoryMock.Setup(b => b.GetBook(It.IsAny<int>())) .ReturnsAsync(bookDTO); bookRepositoryMock.Setup(b => b.GetCheckedOutBooks(It.IsAny<string>())) .ReturnsAsync(new List<CheckedOutBookDTO>() { new CheckedOutBookDTO(), new CheckedOutBookDTO() }); var userServiceMock = new Mock<IUserService>(); userServiceMock.Setup(s => s.UserId).Returns("test"); userServiceMock.Setup(s => s.UserName).Returns("test"); var bookService = new BooksService(bookRepositoryMock.Object, userServiceMock.Object); var result = await bookService.CheckOutBook(1); Assert.AreEqual(CheckedOutBookState.Success, result.State); }