public async Task PostCheckAvailability_ShouldBeAvailable() { // Arrange var context = new TestBookStoreAPIContext(); var testBook = DemoData.GetDemoBook(); context.Books.Add(testBook); var testBookDTO = DemoData.GetDTOfromBook(testBook); var cartItem = new CartItem { Book = testBookDTO, Quantity = 1 }; var cart = new Cart() { CartItems = new List <CartItem> { cartItem } }; // Act var controller = new BooksController(context); var result = await controller.PostAvailability(cart) as IHttpActionResult; var contentResult = result as OkNegotiatedContentResult <ApiResponse>; var availableBooks = contentResult.Content.Data as IEnumerable <IBookDTO>; // Assert Assert.IsNotNull(result); Assert.IsTrue(!contentResult.Content.Error); Assert.AreEqual("all available", contentResult.Content.Message); Assert.AreEqual(testBookDTO, availableBooks.ElementAt(0)); }
public async Task PostOrder_ShouldReturnError() { // Arrange var context = new TestBookStoreAPIContext(); var testBook = DemoData.GetDemoBook(); context.Books.Add(testBook); var cart = new Cart { //this item is out of stock CartItems = new List <CartItem> { new CartItem(DemoData.GetDTOfromBook(testBook), 5) } }; // Act var controller = new OrdersController(context); var result = await controller.PostOrder(cart) as IHttpActionResult; var contentResult = result as OkNegotiatedContentResult <ApiResponse>; // Assert Assert.IsNotNull(result); Assert.IsTrue(contentResult.Content.Error); }