public void PutProduct_ShouldFail_WhenDifferentID()
        {
            var controller = new ProductsController(GetTestContext());
            var item = GetDemoProduct();

            var badresult = controller.PutProduct(999, item);
            Assert.IsInstanceOfType(badresult, typeof(BadRequestResult));
        }
        public void GetProduct_ShouldReturnCorrectProduct()
        {
            var context = GetTestContext();
            var controller = new ProductsController(context);

            var result = controller.GetProduct(2) as OkNegotiatedContentResult<Product>;

            Assert.IsNotNull(result);
            Assert.AreEqual(2, result.Content.Id);
        }
        public void GetProducts_ShouldReturnAllProducts()
        {
            var context = GetTestContext();

            var controller = new ProductsController(context);
            var result = controller.GetProducts() as TestProductDbSet;

            Assert.IsNotNull(result);
            Assert.AreEqual(3, result.Local.Count);
        }
        public void PutProduct_ShouldReturnStatusCode()
        {
            var context = GetTestContext();
            var controller = new ProductsController(context);
            var product = context.Products.Find(2);
            product.Name = "Product2 updated";

            var result = controller.PutProduct(2, product) as StatusCodeResult;
            Assert.IsNotNull(result);
            Assert.IsInstanceOfType(result, typeof(StatusCodeResult));
            Assert.AreEqual(HttpStatusCode.NoContent, result.StatusCode);
        }
        public void PostProduct_ShouldReturnPathToNewProduct()
        {
            var context = GetTestContext();
            var controller = new ProductsController(context);
            var item = GetDemoProduct();

            var result = controller.PostProduct(item) as CreatedAtRouteNegotiatedContentResult<Product>;

            Assert.IsNotNull(result);
            Assert.AreEqual(result.RouteName, "DefaultApi");
            Assert.AreEqual(result.RouteValues["id"], result.Content.Id);
            Assert.AreEqual(result.Content.Name, item.Name);
        }
        public void DeleteProduct_ShouldReturnOk()
        {
            var context = GetTestContext();
            var item = GetDemoProduct();
            context.Products.Add(item);

            var controller = new ProductsController(context);

            var result = controller.DeleteProduct(4) as OkNegotiatedContentResult<Product>;

            Assert.IsNotNull(result);
            Assert.AreEqual(item.Id, result.Content.Id);
        }