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);
        }
        public void GetBooks_ShouldReturnAllBooks()
        {
            // Arrange
            var context = new TestBookStoreAPIContext();

            context.Books.Add(DemoData.GetDemoBook());

            // Act
            var controller    = new BooksController(context);
            var result        = controller.GetBooks() as IHttpActionResult;
            var contentResult = result as OkNegotiatedContentResult <ApiResponse>;
            var books         = contentResult.Content.Data as IQueryable <IBookDTO>;

            // Assert
            Assert.IsNotNull(result);
            Assert.IsTrue(!contentResult.Content.Error);
            Assert.AreEqual(1, books.Count());
        }
        public async Task GetBook_ShouldReturnBookDetails()
        {
            // Arrange
            var context = new TestBookStoreAPIContext();

            context.Books.Add(DemoData.GetDemoBook());

            // Act
            var controller = new BooksController(context);
            var result     = await controller.GetBook("id1") as IHttpActionResult;

            var contentResult = result as OkNegotiatedContentResult <ApiResponse>;
            var book          = contentResult.Content.Data as IBookDTO;

            // Assert
            Assert.IsNotNull(result);
            Assert.IsTrue(!contentResult.Content.Error);
            Assert.AreEqual("id1", book.Id);
        }