Ejemplo n.º 1
0
        public void GetProduct_ShouldReturnProductWithSameID()
        {
            var context = new TestStoreAppContext();

            context.Products.Add(GetDemoProduct());

            var controller = new ProductController(context);
            var result     = controller.GetProduct(3) as OkNegotiatedContentResult <Product>;

            Assert.IsNotNull(result);
            Assert.AreEqual(3, result.Content.Id);
        }
Ejemplo n.º 2
0
        public void DeleteProduct_ShouldReturnOK()
        {
            var context = new TestStoreAppContext();
            var item    = GetDemoProduct();

            context.Products.Add(item);

            var controller = new ProductController(context);
            var result     = controller.DeleteProduct(3) as OkNegotiatedContentResult <Product>;

            Assert.IsNotNull(result);
            Assert.AreEqual(item.Id, result.Content.Id);
        }
Ejemplo n.º 3
0
        public void GetProducts_ShouldReturnAllProducts()
        {
            var context = new TestStoreAppContext();

            context.Products.Add(new Product {
                Id = 1, Name = "Demo1", Price = 20
            });
            context.Products.Add(new Product {
                Id = 2, Name = "Demo2", Price = 30
            });
            context.Products.Add(new Product {
                Id = 3, Name = "Demo3", Price = 40
            });

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

            Assert.IsNotNull(result);
            Assert.AreEqual(3, result.Local.Count);
        }