public async Task CheckOutBooksRetunsBadRequestWithABadBookId() { var bookService = new Mock<IBooksService>(); var controller = new BooksController(bookService.Object); var result = await controller.CheckoutBook(null) as BadRequestErrorMessageResult; Assert.AreEqual("Invalid bookId", result.Message); }
public async Task CheckedOutBooksReturnsBookNotFound() { var bookServiceMock = new Mock<IBooksService>(); bookServiceMock.Setup(bs => bs.CheckOutBook(It.IsAny<int>())) .ReturnsAsync(new CheckedOutBookDTO { State = CheckedOutBookState.BookNotFound }); var controller = new BooksController(bookServiceMock.Object); var result = await controller.CheckoutBook(1) as BadRequestErrorMessageResult; Assert.AreEqual("This book does not exist at this library", result.Message); }
public async Task CheckedOutBooksReturnsTooManyBooksCheckedOut() { var bookServiceMock = new Mock<IBooksService>(); bookServiceMock.Setup(bs => bs.CheckOutBook(It.IsAny<int>())) .ReturnsAsync(new CheckedOutBookDTO { State = CheckedOutBookState.TooManyBooksCheckedOut }); var controller = new BooksController(bookServiceMock.Object); var result = await controller.CheckoutBook(1) as BadRequestErrorMessageResult; Assert.AreEqual("User has too many books checked out", result.Message); }
public async Task CheckedOutBooksReturnsBookIsNotAvailable() { var bookServiceMock = new Mock<IBooksService>(); var userServiceMock = new Mock<IUserService>(); bookServiceMock.Setup(bs => bs.CheckOutBook(It.IsAny<int>())) .ReturnsAsync(new CheckedOutBookDTO { State = CheckedOutBookState.BookIsNotAvailable }); var controller = new BooksController(bookServiceMock.Object); var result = await controller.CheckoutBook(1) as BadRequestErrorMessageResult; Assert.AreEqual("This book has no more copies to check out", result.Message); }
public async Task CheckedOutBooksReturnsSuccess() { var bookServiceMock = new Mock<IBooksService>(); var checkedOutBook = new CheckedOutBookDTO { State = CheckedOutBookState.Success }; bookServiceMock.Setup(bs => bs.CheckOutBook(It.IsAny<int>())) .ReturnsAsync(checkedOutBook); var controller = new BooksController(bookServiceMock.Object); var result = await controller.CheckoutBook(1) as OkResult; Assert.IsNotNull(result); }