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); }
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); }
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); }
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); }
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"); }