示例#1
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);
        }
示例#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);
        }
示例#3
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");
        }