Ejemplo n.º 1
0
        public void TestProductNotFoundById()
        {
            var option = new DbContextOptionsBuilder <ApidbContext>()
                         .UseInMemoryDatabase(databaseName: "webAPIdb")
                         .Options;

            // Run the test against one instance of the context
            var context = new ApidbContext(option);
            var service = new WebApiProductController(context);

            service.Seed(context);
            var Testresult = context.ProductItems.FindAsync(100);

            Assert.IsNull(Testresult.Result);
        }
Ejemplo n.º 2
0
        public void TestGetProductbyId()
        {
            var option = new DbContextOptionsBuilder <ApidbContext>()
                         .UseInMemoryDatabase(databaseName: "webAPIdb")
                         .Options;

            // Run the test against one instance of the context
            var context = new ApidbContext(option);
            var service = new WebApiProductController(context);

            service.Seed(context);
            var Testresult = context.ProductItems.FindAsync(6);
            var getData    = service.GetProductbyId(6);

            Assert.AreEqual(Testresult.Result.Name, getData.Name);
        }
Ejemplo n.º 3
0
        public void TestDeleteProductById()
        {
            var option = new DbContextOptionsBuilder <ApidbContext>()
                         .UseInMemoryDatabase(databaseName: "webAPIdb")
                         .Options;

            // Run the test against one instance of the context
            var context = new ApidbContext(option);
            var service = new WebApiProductController(context);

            service.Seed(context);
            var     isDeleted = service.DeleteProductById(5);
            Product getData   = service.GetProductbyId(5);

            Assert.IsNull(getData);
        }
Ejemplo n.º 4
0
        public void TestPageNotFoundOnPage()
        {
            var option = new DbContextOptionsBuilder <ApidbContext>()
                         .UseInMemoryDatabase(databaseName: "webAPIdb")
                         .Options;

            // Run the test against one instance of the context
            var context = new ApidbContext(option);
            var service = new WebApiProductController(context);

            service.Seed(context);
            var pageData     = service.GetPageList(10, 5);
            var model        = JsonConvert.DeserializeObject <ProductPage>(pageData);
            var productItems = model.Product_Items;

            Assert.AreEqual(productItems.Count, 0);
        }
Ejemplo n.º 5
0
        public void TestUpdateProductById()
        {
            var option = new DbContextOptionsBuilder <ApidbContext>()
                         .UseInMemoryDatabase(databaseName: "webAPIdb")
                         .Options;

            // Run the test against one instance of the context
            var context = new ApidbContext(option);
            var service = new WebApiProductController(context);

            service.Seed(context);
            Product prod = new Product();

            prod.Id          = 2;
            prod.Name        = "UpdatedProduct";
            prod.Description = "Description";
            service.UpdateProduct(2, prod);
            var getUpdatedProduct = service.GetProductbyId(2);

            Assert.AreEqual(getUpdatedProduct.Name, "UpdatedProduct");
        }