Exemple #1
0
        public void OrderGet_Id_OrderMatchId()
        {
            // Arrange
            int id = 1;

            MockHttpConfiguration.HttpGet(_controller);

            // Act
            IHttpActionResult response = _controller.Get(id);
            var result = response as OkNegotiatedContentResult <PurchaseOrder>;

            // Assert
            Assert.IsNotNull(result);
            Assert.IsNotNull(result.Content);
            Assert.AreEqual(id, result.Content.Id);
        }
Exemple #2
0
        public void OrdersGet_Null_AllOrdersMatchId()
        {
            // Arrange
            MockHttpConfiguration.HttpGet(_controller);
            var expectedOrders = _repository.Orders.GetAllOrders();

            // Act
            var          response       = _controller.Get();
            Type         responseType   = response.GetType();
            PropertyInfo ordersProperty = responseType.GetProperty("Orders"); // getting the Orders array inside json result
            IEnumerable  results        = ordersProperty.GetValue(response, null) as IEnumerable;

            // Assert
            foreach (PurchaseOrder order in results)
            {
                Assert.IsTrue(expectedOrders.Where(x => x.Id == order.Id).First() != null);
            }
        }
Exemple #3
0
        public void OrderDelete_Order_HttpOk()
        {
            // Arrange
            int id = 1;

            MockHttpConfiguration.HttpGet(_controller);
            IHttpActionResult response = _controller.Get(id);
            var result        = response as OkNegotiatedContentResult <PurchaseOrder>;
            var existingOrder = result.Content;

            MockHttpConfiguration.HttpDelete(_controller);

            // Act
            response = _controller.Delete(existingOrder);

            // Assert
            Assert.IsInstanceOfType(response, typeof(OkResult));
        }
Exemple #4
0
        public void ProductDelete_Product_HttpOk()
        {
            // Arrange
            int id = 100;

            MockHttpConfiguration.HttpGet(_controller);
            IHttpActionResult response = _controller.Get(id);
            var result          = response as OkNegotiatedContentResult <Product>;
            var existingProduct = result.Content;

            MockHttpConfiguration.HttpDelete(_controller);

            // Act
            response = _controller.Delete(existingProduct);

            // Assert
            Assert.IsInstanceOfType(response, typeof(OkResult));
        }
Exemple #5
0
        public void OrderPut_Order_HttpOk()
        {
            // Arrange
            int id = 2;

            MockHttpConfiguration.HttpGet(_controller);
            IHttpActionResult response = _controller.Get(id);
            var result        = response as OkNegotiatedContentResult <PurchaseOrder>;
            var existingOrder = result.Content;

            existingOrder.Quantity = 999; // Changing value for update
            MockHttpConfiguration.HttpPut(_controller);

            // Act
            response = _controller.Put(existingOrder);

            // Assert
            Assert.IsInstanceOfType(response, typeof(OkResult));
        }
Exemple #6
0
        public void ProductPut_Product_HttpOk()
        {
            // Arrange
            int id = 100;

            MockHttpConfiguration.HttpGet(_controller);
            IHttpActionResult response = _controller.Get(id);
            var result          = response as OkNegotiatedContentResult <Product>;
            var existingProduct = result.Content;

            existingProduct.Price = 99.99m; // Changing value for update
            MockHttpConfiguration.HttpPut(_controller);

            // Act
            response = _controller.Put(existingProduct);

            // Assert
            Assert.IsInstanceOfType(response, typeof(OkResult));
        }