public async void FindProductKeyAsync() { using (IDbContext northwindFakeContext = new NorthwindFakeContext()) using (IUnitOfWork unitOfWork = new UnitOfWork(northwindFakeContext)) { unitOfWork.Repository <Product>().Insert(new Product { ProductID = 2, Discontinued = true }); unitOfWork.Save(); var product = await unitOfWork.Repository <Product>().FindAsync(2); Assert.AreEqual(product.ProductID, 2); } }
public void DeepLoadProductWithSupplier() { using (IDataContextAsync northwindFakeContext = new NorthwindFakeContext()) using (IUnitOfWork unitOfWork = new UnitOfWork(northwindFakeContext)) { unitOfWork.Repository <Supplier>().Insert(new Supplier { SupplierID = 1, CompanyName = "Nokia", City = "Tampere", Country = "Finland", ContactName = "Stephen Elop", ContactTitle = "CEO", ObjectState = ObjectState.Added }); unitOfWork.Repository <Product>().Insert(new Product { ProductID = 2, Discontinued = true, ProductName = "Nokia Lumia 1520", SupplierID = 1, ObjectState = ObjectState.Added }); unitOfWork.SaveChanges(); var product = unitOfWork.Repository <Product>().Find(2); Assert.IsNotNull(product); } }
public void DeleteProductById() { using (IDataContextAsync northwindFakeContext = new NorthwindFakeContext()) using (IUnitOfWorkAsync unitOfWork = new UnitOfWork(northwindFakeContext)) { unitOfWork.Repository <Product>().Insert(new Product { ProductID = 2, Discontinued = true, ObjectState = ObjectState.Added }); unitOfWork.SaveChanges(); unitOfWork.Repository <Product>().Delete(2); unitOfWork.SaveChanges(); var product = unitOfWork.Repository <Product>().Find(2); Assert.IsNull(product); } }
public void GetProductsThatHaveBeenDiscontinued() { using (IDataContextAsync northwindFakeContext = new NorthwindFakeContext()) using (IUnitOfWork unitOfWork = new UnitOfWork(northwindFakeContext)) { unitOfWork.Repository <Product>().Insert(new Product { ProductID = 1, Discontinued = false, ObjectState = ObjectState.Added }); unitOfWork.Repository <Product>().Insert(new Product { ProductID = 2, Discontinued = true, ObjectState = ObjectState.Added }); unitOfWork.Repository <Product>().Insert(new Product { ProductID = 3, Discontinued = true, ObjectState = ObjectState.Added }); unitOfWork.SaveChanges(); var discontinuedProducts = unitOfWork.Repository <Product>().Query(t => t.Discontinued).Select(); Assert.AreEqual(2, discontinuedProducts.Count()); } }
public void InsertProduct() { using (IDataContextAsync northwindFakeContext = new NorthwindFakeContext()) using (IUnitOfWork unitOfWork = new UnitOfWork(northwindFakeContext)) { unitOfWork.Repository <Product>().Insert(new Product { ProductID = 1, Discontinued = false, ObjectState = ObjectState.Added }); unitOfWork.Repository <Product>().Insert(new Product { ProductID = 2, Discontinued = true, ObjectState = ObjectState.Added }); unitOfWork.Repository <Product>().Insert(new Product { ProductID = 3, Discontinued = true, ObjectState = ObjectState.Added }); unitOfWork.SaveChanges(); var product = unitOfWork.Repository <Product>().Find(2); Assert.IsNotNull(product); Assert.AreEqual(2, product.ProductID); } }
public void FindProductById() { using (IDataContextAsync northwindFakeContext = new NorthwindFakeContext()) using (IUnitOfWork unitOfWork = new UnitOfWork(northwindFakeContext, _repositoryProvider)) { unitOfWork.Repository <Product>().Insert(new Product { ProductID = 1, Discontinued = false }); unitOfWork.Repository <Product>().Insert(new Product { ProductID = 2, Discontinued = true }); unitOfWork.Repository <Product>().Insert(new Product { ProductID = 3, Discontinued = true }); unitOfWork.SaveChanges(); var product = unitOfWork.Repository <Product>().Find(2); Assert.IsNotNull(product); Assert.AreEqual(2, product.ProductID); } }
public void UpdateProduct() { using (IDataContextAsync northwindFakeContext = new NorthwindFakeContext()) using (IUnitOfWork unitOfWork = new UnitOfWork(northwindFakeContext)) { unitOfWork.Repository <Product>().Insert(new Product { ProductID = 2, Discontinued = true, ObjectState = ObjectState.Added }); unitOfWork.SaveChanges(); var product = unitOfWork.Repository <Product>().Find(2); Assert.AreEqual(product.Discontinued, true, "Assert we are able to find the inserted Product."); product.Discontinued = false; product.ObjectState = ObjectState.Modified; unitOfWork.Repository <Product>().Update(product); unitOfWork.SaveChanges(); Assert.AreEqual(product.Discontinued, false, "Assert that our changes were saved."); } }
public void DeleteProductByProduct() { using (IDbContext northwindFakeContext = new NorthwindFakeContext()) using (IUnitOfWork unitOfWork = new UnitOfWork(northwindFakeContext)) { unitOfWork.Repository <Product>().Insert(new Product { ProductID = 2, Discontinued = true, ObjectState = ObjectState.Added }); unitOfWork.Save(); var product = unitOfWork.Repository <Product>().Find(2); product.ObjectState = ObjectState.Deleted; unitOfWork.Repository <Product>().Delete(product); unitOfWork.Save(); var productDeleted = unitOfWork.Repository <Product>().Find(2); Assert.IsNull(productDeleted); } }