public void Persistence_1_and_2() { BuilderSettings builderSettings = new BuilderSettings(); // Not identical, but enough to know they're ok var productRepository = new ProductRepository(); builderSettings.SetCreatePersistenceMethod <Models.Product>(productRepository.Create); builderSettings.SetCreatePersistenceMethod <IList <Models.Product> >(productRepository.CreateAll); new Builder(builderSettings).CreateNew <Product>().Persist(); }
private static void SetPersistenceMethod <T>(BuilderSettings builderSettings) where T : class { builderSettings.SetCreatePersistenceMethod <T>((item) => { using (var db = new ProductsDbContext()) { db.Set <T>().Attach(item); db.Set <T>().Add(item); db.SaveChanges(); } }); builderSettings.SetCreatePersistenceMethod <IList <T> >((items) => { using (var db = new ProductsDbContext()) { foreach (var item in items) { db.Set <T>().Attach(item); db.Set <T>().Add(item); } db.SaveChanges(); } }); builderSettings.SetUpdatePersistenceMethod <T>(item => { using (var db = new ProductsDbContext()) { db.Set <T>().Attach(item); db.Entry(item).State = EntityState.Modified; db.SaveChanges(); } }); builderSettings.SetUpdatePersistenceMethod <IList <T> >((items) => { using (var db = new ProductsDbContext()) { foreach (var item in items) { db.Set <T>().Attach(item); db.Entry(item).State = EntityState.Modified; db.Set <T>().Add(item); } db.SaveChanges(); } }); }
public void ShouldBeAbleToSetCreatePersistenceMethod() { Action <MyClass> func = x => repository.Save(x); builderSettings.SetCreatePersistenceMethod <MyClass>(func); persistenceService.Received().SetPersistenceCreateMethod(func); }
public void ShouldBeAbleToSetCreatePersistenceMethod() { Action <MyClass> func = x => repository.Save(x); using (mocks.Record()) { persistenceService.Expect(x => x.SetPersistenceCreateMethod(func)); } builderSettings.SetCreatePersistenceMethod <MyClass>(func); }
public BuilderSettings DoSetup() { BuilderSettings builderSettings = new BuilderSettings(); if (_setup) { return(builderSettings); } _setup = true; builderSettings.SetCreatePersistenceMethod <Product>(Products.Create); builderSettings.SetCreatePersistenceMethod <IList <Product> >(Products.CreateAll); builderSettings.SetCreatePersistenceMethod <TaxType>(TaxTypes.Create); builderSettings.SetCreatePersistenceMethod <IList <TaxType> >(TaxTypes.CreateAll); builderSettings.SetCreatePersistenceMethod <Category>(Categories.Create); builderSettings.SetCreatePersistenceMethod <IList <Category> >(Categories.CreateAll); builderSettings.SetUpdatePersistenceMethod <Category>(Categories.Save); builderSettings.SetUpdatePersistenceMethod <IList <Category> >(Categories.SaveAll); return(builderSettings); }
public BuilderSettings DoSetup() { DbConfiguration.SetConfiguration(new IntegrationTestConfiguration()); using (var db = new ProductsDbContext()) { db.Database.Delete(); } BuilderSettings builderSettings = new BuilderSettings(); if (_setup) return builderSettings; _setup = true; var productRepository = Dependency.Resolve<IProductRepository>(); var taxTypeRepository = Dependency.Resolve<ITaxTypeRepository>(); var categoryRepository = Dependency.Resolve<ICategoryRepository>(); builderSettings.SetCreatePersistenceMethod<Product>(productRepository.Create); builderSettings.SetCreatePersistenceMethod<IList<Product>>(productRepository.CreateAll); builderSettings.SetCreatePersistenceMethod<TaxType>(taxTypeRepository.Create); builderSettings.SetCreatePersistenceMethod<IList<TaxType>>(taxTypeRepository.CreateAll); builderSettings.SetCreatePersistenceMethod<Category>(categoryRepository.Create); builderSettings.SetCreatePersistenceMethod<IList<Category>>(categoryRepository.CreateAll); builderSettings.SetUpdatePersistenceMethod<Category>(categoryRepository.Save); builderSettings.SetUpdatePersistenceMethod<IList<Category>>(categoryRepository.SaveAll); return builderSettings; }
public BuilderSettings DoSetup() { DbConfiguration.SetConfiguration(new IntegrationTestConfiguration()); using (var db = new ProductsDbContext()) { db.Database.Delete(); } BuilderSettings builderSettings = new BuilderSettings(); if (_setup) { return(builderSettings); } _setup = true; var productRepository = Dependency.Resolve <IProductRepository>(); var taxTypeRepository = Dependency.Resolve <ITaxTypeRepository>(); var categoryRepository = Dependency.Resolve <ICategoryRepository>(); builderSettings.SetCreatePersistenceMethod <Product>(productRepository.Create); builderSettings.SetCreatePersistenceMethod <IList <Product> >(productRepository.CreateAll); builderSettings.SetCreatePersistenceMethod <TaxType>(taxTypeRepository.Create); builderSettings.SetCreatePersistenceMethod <IList <TaxType> >(taxTypeRepository.CreateAll); builderSettings.SetCreatePersistenceMethod <Category>(categoryRepository.Create); builderSettings.SetCreatePersistenceMethod <IList <Category> >(categoryRepository.CreateAll); builderSettings.SetUpdatePersistenceMethod <Category>(categoryRepository.Save); builderSettings.SetUpdatePersistenceMethod <IList <Category> >(categoryRepository.SaveAll); return(builderSettings); }