public static IUnitOfWorkFactory BuildEFSessionFactory(IncDbContext dbContext, bool reloadDb = true) { try { if (reloadDb) { Database.SetInitializer(new CreateDatabaseIfNotExists <IncDbContext>()); dbContext.Database.CreateIfNotExists(); } else { Database.SetInitializer(new NullDatabaseInitializer <IncDbContext>()); } return(new EntityFrameworkUnitOfWorkFactory(new EntityFrameworkSessionFactory(() => dbContext))); } ////ncrunch: no coverage start catch (Exception e) { Clipboard.SetText("Exception in build configuration {0}".F(e)); return(null); } ////ncrunch: no coverage end }
public static IRepository BuildEFRepository(IncDbContext dbContext, bool reloadDb = true) { try { if (reloadDb) { Database.SetInitializer(new CreateDatabaseIfNotExists <IncDbContext>()); dbContext.Database.CreateIfNotExists(); } else { Database.SetInitializer(new NullDatabaseInitializer <IncDbContext>()); } var entityFrameworkRepository = new EntityFrameworkRepository(/*Pleasure.MockStrictAsObject<IEntityFrameworkSessionFactory>(mock => mock.Setup(r => r.GetCurrent()).Returns(dbContext))*/); entityFrameworkRepository.SetProvider(new Lazy <DbContext>(() => dbContext)); return(entityFrameworkRepository); } ////ncrunch: no coverage start catch (Exception e) { Clipboard.SetText("Exception in build configuration {0}".F(e)); return(null); } ////ncrunch: no coverage end }
protected static IRepository GetRepository() { var dbContext = new IncDbContext("IncRealEFDb", typeof(DbEntity).Assembly); dbContext.Configuration.ValidateOnSaveEnabled = false; dbContext.Configuration.LazyLoadingEnabled = true; var entityFrameworkRepository = new EntityFrameworkRepository(/*Pleasure.MockStrictAsObject<IEntityFrameworkSessionFactory>(mock => mock.Setup(r => r.GetCurrent()).Returns(dbContext))*/); entityFrameworkRepository.SetProvider(new Lazy <DbContext>(() => dbContext)); return(entityFrameworkRepository); }
public static void StartEF(IncDbContext dbContext, bool reloadDb = true) { Factory = new Lazy <IUnitOfWorkFactory>(() => BuildEFSessionFactory(dbContext, reloadDb)); }
public static void StartEF(IncDbContext dbContext, bool reloadDb = true) { SpecWithRepository.Repository = BuildEFRepository(dbContext, reloadDb); }