public void DeleteById(IDesignTimeDbContextFactory <TestDbContext> contextFactory) { // Arrange var entity = fixture.Create <TestEntity>(); using (var context = contextFactory.CreateDbContext(null)) { context.Entities.Add(entity); context.SaveChanges(); } // Act int deleteCount; using (var context = contextFactory.CreateDbContext(null)) { deleteCount = builder .CreateCommand <TestEntity>() .Delete <DeleteParams>((e, p) => e.Id == p.Id) .Log(context, output) .Create(context) .Execute(context.Database, new DeleteParams { Id = entity.Id }); } // Assert Assert.Equal(1, deleteCount); using (var context = contextFactory.CreateDbContext(null)) { var exists = context.Entities.Any(e => e.Name == entity.Name); Assert.False(exists); } }
public CommentRepository(IDesignTimeDbContextFactory <Context> contextFactory) { EntityFactory <CommentEntity> factory = new EntityFactory <CommentEntity>(() => new CommentEntity()); Func <DbContext, DbSet <CommentEntity> > getDbSet = c => ((Context)c).Comments; repo = new EntityRepository <Comment, CommentEntity>(factory, getDbSet, contextFactory); }
//TODO: Move this to Program.cs, only when app launches/re-launches public static async void UseEnsureMigrations(this IApplicationBuilder builder) { using var serviceScope = builder.ApplicationServices.GetService <IServiceScopeFactory>().CreateScope(); var tenants = await serviceScope.ServiceProvider.GetService <ITenantProvider>().GetTenants(); if (tenants.Count == 0) { return; } IDesignTimeDbContextFactory <DbContext> dbContextFactory = (IDesignTimeDbContextFactory <DbContext>) serviceScope.ServiceProvider.GetService(typeof(IDesignTimeDbContextFactory <DbContext>)); var dummyDbContext = dbContextFactory.CreateDbContext(null); var dbUpdateExist = dummyDbContext.Database.GetPendingMigrations().Any(); if (dbUpdateExist) { foreach (var tenant in tenants) { var context = dbContextFactory.CreateDbContext(new string[] { tenant.Id.ToString(), tenant.ConnectionString }); if (context != null) { await context.Database.MigrateAsync(); } } PushLatestScriptToStorage(dummyDbContext.Database.GenerateCreateScript()); } }
public void InsertOutput(IDesignTimeDbContextFactory <TestDbContext> contextFactory) { // Arrange var upsertParams = fixture.Create <UpsertParams>(); // Act InsertResult insertResult; using (var context = contextFactory.CreateDbContext(null)) { insertResult = builder .CreateCommand <TestEntity>() .Insert <UpsertParams>(p => new TestEntity { Name = p.Name, Version = p.Version }) .Output(e => new InsertResult { Id = e.Id, Version = e.Version }) .Log(context, output) .Create(context) .QueryFirst(context.Database, upsertParams); } // Assert Assert.NotNull(insertResult); Assert.Equal(upsertParams.Version, insertResult.Version); using (var context = contextFactory.CreateDbContext(null)) { var inserted = context.Entities.Single(e => e.Id == insertResult.Id); Assert.Equal(upsertParams.Name, inserted.Name); Assert.Equal(upsertParams.Version, inserted.Version); } }
public void Insert(IDesignTimeDbContextFactory <TestDbContext> contextFactory) { // Arrange var upsertParams = fixture.Create <UpsertParams>(); // Act int insertCount; using (var context = contextFactory.CreateDbContext(null)) { output.WriteLine($"####### {context.Database.ProviderName}"); insertCount = builder .CreateCommand <TestEntity>() .Insert <UpsertParams>(p => new TestEntity { Name = p.Name, Version = p.Version }) .Log(context, output) .Create(context) .Execute(context.Database, upsertParams); } // Assert Assert.Equal(1, insertCount); using (var context = contextFactory.CreateDbContext(null)) { var exists = context.Entities.Any(e => e.Name == upsertParams.Name); Assert.True(exists); } }
public TeamRepository(IDesignTimeDbContextFactory <Context> contextFactory) { EntityFactory <TeamEntity> Entityfactory = CreateEntityFactory(); Func <DbContext, DbSet <TeamEntity> > dbSet = CreateFunctionThatReturnsEntityDBSetFromContext(); repo = new EntityRepository <Team, TeamEntity>(Entityfactory, dbSet, contextFactory); }
public UserRepository(IDesignTimeDbContextFactory <Context> contextFactory) { EntityFactory <UserEntity> factory = CreateEntityFactory(); Func <DbContext, DbSet <UserEntity> > dbSet = CreateFunctionThatReturnsEntityDBSetFromContext(); repo = new EntityRepository <User, UserEntity>(factory, dbSet, contextFactory); }
public EntityRepository(EntityFactory <Entity> factory, Func <DbContext, DbSet <Entity> > getDBSetFunc, IDesignTimeDbContextFactory <DbContext> contextFactory) { this.factory = factory; this.getDBSetFunc = getDBSetFunc; this.contextFactory = contextFactory; entityUpdater = new EntityUpdater <Entity>(contextFactory); }
public LogRepository(IDesignTimeDbContextFactory <Context> contextFactory) { Func <LogEntity> createLog = () => new LogEntity(); EntityFactory <LogEntity> logFactory = new EntityFactory <LogEntity>(createLog); Func <DbContext, DbSet <LogEntity> > getDbSet = context => ((Context)context).Logs; repo = new EntityRepository <LogDTO, LogEntity>(logFactory, getDbSet, contextFactory); }
public Repository(IDesignTimeDbContextFactory <ProMassSpammerModel> modelFactory) { _massCommunicationRepository = new Lazy <IMassCommunicationRepository>(() => new MassCommunicationRepository(modelFactory)); _logRepository = new Lazy <ILogRepository>(() => new LogRepository(modelFactory)); _recipientRepository = new Lazy <IRecipientRepository>(() => new RecipientRepository(modelFactory)); }
public InstrumentService(IDesignTimeDbContextFactory <LInstContext> dbContextFactory, IEventAggregator aggregator, IDataService <LInstContext> lInstData) { _eventAggregator = aggregator; _dbContextFactory = dbContextFactory; _lInstData = lInstData; }
public UnitOfWork(IDesignTimeDbContextFactory <DatabaseContext> databaseContext) { _context = databaseContext.CreateDbContext(args: null); Posts = new PostRepository(_context); Categories = new CategoryRepository(_context); Accounts = new AccountRepository(_context); PostCategories = new PostCategoryRepository(_context); }
public void InsertOrUpdate_UpsertExistingOutput(IDesignTimeDbContextFactory <TestDbContext> contextFactory) { // Arrange var upsertParams = fixture.Create <UpsertParams>(); int existingId; using (var context = contextFactory.CreateDbContext(null)) { var entity = new TestEntity { Name = upsertParams.Name, Version = upsertParams.Version, }; context.Entities.Add(entity); context.SaveChanges(); existingId = entity.Id; } // Act UpsertParams result; using (var context = contextFactory.CreateDbContext(null)) { result = builder .CreateCommand <TestEntity>() .Insert <UpsertParams>(p => new TestEntity { Name = p.Name, Version = p.Version }) .OrUpdate( e => new { e.Name }, (e, p) => new TestEntity { Version = e.Version + 1, } ) .Output(e => new UpsertParams { Id = e.Id, Version = e.Version, }) .Log(context, output) .Create(context) .QueryFirstOrDefault(context.Database, upsertParams); } // Assert Assert.NotNull(result); using (var context = contextFactory.CreateDbContext(null)) { var inserted = context.Entities.Single(e => e.Name == upsertParams.Name); Assert.Equal(existingId, inserted.Id); Assert.Equal(upsertParams.Version + 1, inserted.Version); Assert.Equal(inserted.Id, result.Id); Assert.Equal(inserted.Version, result.Version); } }
public PluginConfigurationSource( string connectionString, IPluginConfigurationSeedData pluginConfigurationSeedData, IDesignTimeDbContextFactory <TDbContext> dbContextFactory) { _connectionString = connectionString; _pluginConfigurationSeedData = pluginConfigurationSeedData; _dbContextFactory = dbContextFactory; }
public HistorianRepository( ILoggerFactory loggerFactory, IDesignTimeDbContextFactory <HistorianDbContext> contextFactory, IStorageTransactionFactory <HistorianDbContext> storageTransactionFactory) { LoggerFactory = loggerFactory; ContextFactory = contextFactory; StorageTransactionFactory = storageTransactionFactory; }
public PluginConfigurationProvider( string connectionString, IPluginConfigurationSeedData pluginConfigurationSeedData, IDesignTimeDbContextFactory <TDbContext> dbContextFactory) { _connectionString = connectionString; _pluginConfigurationSeedData = pluginConfigurationSeedData; _dbContextFactory = dbContextFactory; ReloadDbConfigurationDelegates.ReloadDbConfigurationDelegate += ReloadPluginConfiguration; }
public void TestInit() { contextFactory = GetContextFactory(); repo = new SportRepository(contextFactory); boca = CreateBocaTeam(); river = CreateTeamThatBelongsInTheB(); futbol = CreateFutbolTeam(); rugby = CreateRugbyTeam(); repo.Add(futbol); repo.Add(rugby); }
public static IConfigurationBuilder AddPluginConfiguration <TDbContext>( this IConfigurationBuilder builder, string connectionString, IPluginConfigurationSeedData pluginConfigurationSeedData, IDesignTimeDbContextFactory <TDbContext> dbContextFactory) where TDbContext : DbContext, IPluginDbContext { return(builder.Add(new PluginConfigurationSource <TDbContext>( connectionString, pluginConfigurationSeedData, dbContextFactory))); }
public MarketRepository( ILoggerFactory loggerFactory, IIntervalFactory intervalFactory, IDesignTimeDbContextFactory <HistorianDbContext> contextFactory, IStorageTransactionFactory <HistorianDbContext> storageTransactionFactory) { IntervalFactory = intervalFactory; ContextFactory = contextFactory; StorageTransactionFactory = storageTransactionFactory; Logger = loggerFactory.CreateLogger <MarketRepository>(); }
public void InsertOrUpdate_UpsertExistingWhere(IDesignTimeDbContextFactory <TestDbContext> contextFactory) { // Arrange var upsertParams = fixture.Create <UpsertParams>(); int existingId; using (var context = contextFactory.CreateDbContext(null)) { var entity = new TestEntity { Name = upsertParams.Name, Version = upsertParams.Version, }; context.Entities.Add(entity); context.SaveChanges(); existingId = entity.Id; } // Act int rowCount; using (var context = contextFactory.CreateDbContext(null)) { rowCount = builder .CreateCommand <TestEntity>() .Insert <UpsertParams>(p => new TestEntity { Name = p.Name, Version = p.Version }) .OrUpdate( e => new { e.Name }, (e, p) => new TestEntity { Version = e.Version + 1, } ) .Where((e, p) => e.Version < 0) .Log(context, output) .Create(context) .Execute(context.Database, upsertParams); } // Assert Assert.Equal(0, rowCount); using (var context = contextFactory.CreateDbContext(null)) { var existing = context.Entities.Single(e => e.Id == existingId); Assert.Equal(upsertParams.Version, existing.Version); } }
public void TestInit() { contextFactory = GetContextFactory(); sportRepo = new SportRepository(contextFactory); teamRepo = new TeamRepository(contextFactory); futbol = CreateFutbol(); rugby = CreateRugby(); boca = CreateBocaTeam(); river = CreateTeamThatBelongsInTheB(); sportRepo.Add(new Sport("Futbol")); teamRepo.Add(new Team(boca.Name, new Sport("Futbol"))); teamRepo.Add(new Team(river.Name, new Sport("Futbol"))); login = CreateLoginServices(); }
protected void Initialize() { football = CreateFootballSport(); boca = CreateBocaTeam(); river = CreateRiverTeam(); tomba = CreateTombaTeam(); messi = CreateMessiUser(); maradona = CreateMaradonaUser(); bocaRiver = CreateRiverBocaEncounter(); riverTomba = CreateRiverTombaEncounter(); contextFactory = new InMemoryContextFactory(); encounterRepo = CreateEncounterRepo(); teamRepo = CreateTeamRepo(); }
public static IDataProcessor GetDataProcessor( IDesignTimeDbContextFactory <RiversECO.DataContext.DataContext> contextFactory, WaterObjectType objectType) { switch (objectType) { case WaterObjectType.River: return(new RiversDataProcessor(contextFactory)); case WaterObjectType.Lake: return(new LakesDataProcessor(contextFactory)); default: return(null); } }
public void InsertOrUpdate_UpdateExistingWhereOutput(IDesignTimeDbContextFactory <TestDbContext> contextFactory) { // Arrange var upsertParams = fixture.Create <UpsertParams>(); using (var context = contextFactory.CreateDbContext(null)) { context.Entities.Add(new TestEntity { Name = upsertParams.Name, Version = upsertParams.Version, }); context.SaveChanges(); } // Act IEnumerable <UpsertParams> results; using (var context = contextFactory.CreateDbContext(null)) { results = builder .CreateCommand <TestEntity>() .Update <UpsertParams>((e, p) => new TestEntity { Version = e.Version + 1, }) .Where((e, p) => e.Name == p.Name) .Output(e => new UpsertParams { Id = e.Id, Version = e.Version }) .Log(context, output) .Create(context) .Query(context.Database, upsertParams); } // Assert Assert.Single(results); using (var context = contextFactory.CreateDbContext(null)) { var inserted = context.Entities.Single(e => e.Name == upsertParams.Name); Assert.Equal(upsertParams.Version + 1, inserted.Version); var result = results.Single(); Assert.Equal(upsertParams.Version + 1, result.Version); } }
private static void Initialize() { Console.WriteLine("Initializing..."); var options = DataContextFactory.GetConfiguration(); switch (options.Provider) { case DatabaseProviders.MySql: _factory = new MySqlDataContextFactory(); break; case DatabaseProviders.MsSql: _factory = new MsSqlDataContextFactory(); break; default: throw new ArgumentOutOfRangeException(); } }
public void InsertOrUpdate_UpdateExistingWhere(IDesignTimeDbContextFactory <TestDbContext> contextFactory) { // Arrange var upsertParams = fixture.Create <UpsertParams>(); using (var context = contextFactory.CreateDbContext(null)) { context.Entities.Add(new TestEntity { Name = upsertParams.Name, Version = upsertParams.Version, }); context.SaveChanges(); } // Act int updateCount; using (var context = contextFactory.CreateDbContext(null)) { updateCount = builder .CreateCommand <TestEntity>() .Update <UpsertParams>((e, p) => new TestEntity { Version = e.Version + 1, }) .Where((e, p) => e.Name == p.Name) .Log(context, output) .Create(context) .Execute(context.Database, upsertParams); } // Assert Assert.Equal(1, updateCount); using (var context = contextFactory.CreateDbContext(null)) { var inserted = context.Entities.Single(e => e.Name == upsertParams.Name); Assert.Equal(upsertParams.Version + 1, inserted.Version); } }
public void InsertOrUpdate_UpdateWithNullable(IDesignTimeDbContextFactory <TestDbContext> contextFactory) { // Arrange var upsertParams = fixture.Create <UpsertParams>(); using (var context = contextFactory.CreateDbContext(null)) { context.Entities.Add(new TestEntity { Name = upsertParams.Name, Version = upsertParams.Version, }); context.SaveChanges(); } upsertParams.NullableVersion = null; // Act int rowCount; using (var context = contextFactory.CreateDbContext(null)) { rowCount = builder .CreateCommand <TestEntity>() .Update <UpsertParams>((e, p) => new TestEntity { Version = 1, }) .Where((e, p) => e.Version == p.NullableVersion || p.NullableVersion == null) .Log(context, output) .Create(context) .Execute(context.Database, upsertParams); } // Assert Assert.NotEqual(0, rowCount); }
public void InsertOrUpdate_UpsertNew(IDesignTimeDbContextFactory <TestDbContext> contextFactory) { // Arrange var upsertParams = fixture.Create <UpsertParams>(); // Act int rowCount; using (var context = contextFactory.CreateDbContext(null)) { rowCount = builder .CreateCommand <TestEntity>() .Insert <UpsertParams>(p => new TestEntity { Name = p.Name, Version = p.Version }) .OrUpdate( e => new { e.Name }, (e, p) => new TestEntity { Version = e.Version + 1, } ) .Log(context, output) .Create(context) .Execute(context.Database, upsertParams); } // Assert Assert.Equal(1, rowCount); using (var context = contextFactory.CreateDbContext(null)) { var inserted = context.Entities.Single(e => e.Name == upsertParams.Name); Assert.Equal(upsertParams.Version, inserted.Version); } }
/// <summary> /// This method gets called by the runtime. Use this method to configure the HTTP request pipeline. /// </summary> /// <param name="app">Injected <see cref="IApplicationBuilder"/></param> /// <param name="env">Injected <see cref="IHostingEnvironment"/></param> /// <param name="contextFactory">The application <see cref="IDesignTimeDbContextFactory{TContext}"/></param> public void Configure( IApplicationBuilder app, IHostingEnvironment env, IDesignTimeDbContextFactory <PrioritizeMeDbContext> contextFactory) { if (env.IsDevelopment()) { app.UseDeveloperExceptionPage(); } else { app.UseHsts(); // Automatically migrate the application to the latest using (PrioritizeMeDbContext migrationContext = contextFactory.CreateDbContext(new string[0])) { migrationContext.Database.Migrate(); } } app.UseCors(MyAllowSpecificOrigins); app.UseHttpsRedirection(); app.UseMvc(); app.UseSwagger(c => { c.PreSerializeFilters.Add((swagger, httpReq) => swagger.Host = httpReq.Host.Value); }); app.UseSwaggerUI( c => { c.SwaggerEndpoint("/swagger/v1/swagger.json", "v1"); }); }
public KmStandViewRepository(IDesignTimeDbContextFactory <ReadModelDbContext> contextFactory) { _contextFactory = contextFactory; _context = contextFactory.CreateDbContext(Array.Empty <string>()); }