public async void TestGetallProducts() { DbContextOptions <CreaturesDbcontext> options = new DbContextOptionsBuilder <CreaturesDbcontext>().UseInMemoryDatabase("GetProducts").Options; using (CreaturesDbcontext context = new CreaturesDbcontext(options)) { Product p = new Product(); p.ID = 1; Product pp = new Product(); pp.ID = 2; ProductManagementService Service = new ProductManagementService(context); await Service.Create(p); await Service.Create(pp); var res = await Service.GetAllProducts(); Assert.Equal(2, res.Count); } }
public async void TestdeleteProduct() { DbContextOptions <CreaturesDbcontext> options = new DbContextOptionsBuilder <CreaturesDbcontext>().UseInMemoryDatabase("DeleteProduct").Options; using (CreaturesDbcontext context = new CreaturesDbcontext(options)) { Product p = new Product(); p.ID = 1; Product pp = new Product(); pp.ID = 2; ProductManagementService Service = new ProductManagementService(context); await Service.Create(p); await Service.Create(pp); await Service.DeleteProduct(1); var expect = await context.Products.FirstOrDefaultAsync(c => c.ID == 1); Assert.Null(expect); } }
public async void TestCreateOrder() { DbContextOptions <CreaturesDbcontext> options = new DbContextOptionsBuilder <CreaturesDbcontext>().UseInMemoryDatabase("CreateProduct").Options; using (CreaturesDbcontext context = new CreaturesDbcontext(options)) { Product p = new Product(); p.ID = 1; ProductManagementService Service = new ProductManagementService(context); await Service.Create(p); var r = await context.Products.FirstOrDefaultAsync(c => c.ID == p.ID); Assert.Equal(p, r); } }
public async void TestupdateProduct() { DbContextOptions <CreaturesDbcontext> options = new DbContextOptionsBuilder <CreaturesDbcontext>().UseInMemoryDatabase("updateProduct").Options; using (CreaturesDbcontext context = new CreaturesDbcontext(options)) { Product p = new Product(); p.ID = 1; p.Name = "unicorn"; ProductManagementService Service = new ProductManagementService(context); await Service.Create(p); p.Name = "test"; await Service.UpdateProduct(p); var expect = await context.Products.FirstOrDefaultAsync(c => c.ID == 1); Assert.Equal("test", expect.Name); } }