public void TestInitialize() { _repository = new MockRepository(); _controller = new OrdersController(_repository); MockUser.CurrentUser(_controller); MockHttpConfiguration.HttpConfiguration(_controller); }
public void ProductPost_Product_HttpOk() { // Arrange var productType = new ProductType { Id = 1, Description = "Donic" }; Product newProduct = new Product() { Id = 9, Description = "lorem ipsum test", Name = "Product Test Name", Price = 1.99m, Type = productType }; MockHttpConfiguration.HttpPost(_controller); // Act IHttpActionResult response = _controller.Post(newProduct); // Assert Assert.IsInstanceOfType(response, typeof(OkResult)); }
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); }
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); } }
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)); }
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)); }
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)); }
public void OrderPost_Order_HttpOk() { // Arrange PurchaseOrder newOrder = new PurchaseOrder() { ProductId = 105, Quantity = 1, TotalPrice = 100, UserId = 1 }; MockHttpConfiguration.HttpPost(_controller); // Act IHttpActionResult response = _controller.Post(newOrder); // Assert Assert.IsInstanceOfType(response, typeof(OkResult)); }
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)); }