public static void AddIdSHealthChecks <TConfigurationDbContext, TPersistedGrantDbContext, TIdentityDbContext, TDataProtectionDbContext>(this IServiceCollection services, IConfiguration configuration) where TConfigurationDbContext : DbContext, IAdminConfigurationDbContext where TPersistedGrantDbContext : DbContext, IAdminPersistedGrantDbContext where TIdentityDbContext : DbContext where TDataProtectionDbContext : DbContext, IDataProtectionKeyContext { var configurationDbConnectionString = configuration.GetConnectionString(ConfigurationConsts.ConfigurationDbConnectionStringKey); var persistedGrantsDbConnectionString = configuration.GetConnectionString(ConfigurationConsts.PersistedGrantDbConnectionStringKey); var identityDbConnectionString = configuration.GetConnectionString(ConfigurationConsts.IdentityDbConnectionStringKey); var dataProtectionDbConnectionString = configuration.GetConnectionString(ConfigurationConsts.DataProtectionDbConnectionStringKey); var healthChecksBuilder = services.AddHealthChecks() .AddDbContextCheck <TConfigurationDbContext>("ConfigurationDbContext") .AddDbContextCheck <TPersistedGrantDbContext>("PersistedGrantsDbContext") .AddDbContextCheck <TIdentityDbContext>("IdentityDbContext") .AddDbContextCheck <TDataProtectionDbContext>("DataProtectionDbContext"); var serviceProvider = services.BuildServiceProvider(); var scopeFactory = serviceProvider.GetRequiredService <IServiceScopeFactory>(); using (var scope = scopeFactory.CreateScope()) { var configurationTableName = DbContextHelpers.GetEntityTable <TConfigurationDbContext>(scope.ServiceProvider); var persistedGrantTableName = DbContextHelpers.GetEntityTable <TPersistedGrantDbContext>(scope.ServiceProvider); var identityTableName = DbContextHelpers.GetEntityTable <TIdentityDbContext>(scope.ServiceProvider); var dataProtectionTableName = DbContextHelpers.GetEntityTable <TDataProtectionDbContext>(scope.ServiceProvider); var databaseProvider = configuration.GetSection(nameof(DatabaseProviderConfiguration)).Get <DatabaseProviderConfiguration>(); switch (databaseProvider.ProviderType) { case DatabaseProviderType.SqlServer: healthChecksBuilder .AddSqlServer(configurationDbConnectionString, name: "ConfigurationDb", healthQuery: $"SELECT TOP 1 * FROM dbo.[{configurationTableName}]") .AddSqlServer(persistedGrantsDbConnectionString, name: "PersistentGrantsDb", healthQuery: $"SELECT TOP 1 * FROM dbo.[{persistedGrantTableName}]") .AddSqlServer(identityDbConnectionString, name: "IdentityDb", healthQuery: $"SELECT TOP 1 * FROM dbo.[{identityTableName}]") .AddSqlServer(dataProtectionDbConnectionString, name: "DataProtectionDb", healthQuery: $"SELECT TOP 1 * FROM dbo.[{dataProtectionTableName}]"); break; case DatabaseProviderType.PostgreSQL: healthChecksBuilder .AddNpgSql(configurationDbConnectionString, name: "ConfigurationDb", healthQuery: $"SELECT * FROM \"{configurationTableName}\" LIMIT 1") .AddNpgSql(persistedGrantsDbConnectionString, name: "PersistentGrantsDb", healthQuery: $"SELECT * FROM \"{persistedGrantTableName}\" LIMIT 1") .AddNpgSql(identityDbConnectionString, name: "IdentityDb", healthQuery: $"SELECT * FROM \"{identityTableName}\" LIMIT 1") .AddNpgSql(dataProtectionDbConnectionString, name: "DataProtectionDb", healthQuery: $"SELECT * FROM \"{dataProtectionTableName}\" LIMIT 1"); break; default: throw new NotImplementedException($"Health checks not defined for database provider {databaseProvider.ProviderType}"); } } }
public void Initialize() { DbContextHelpers contextHelpers = new DbContextHelpers(); db = contextHelpers.getDbContext(); recommender = new Recommender(db.Object); }
public static void AddIdSHealthChecks <TConfigurationDbContext, TPersistedGrantDbContext, TIdentityDbContext>(this IServiceCollection services, IConfiguration configuration) where TConfigurationDbContext : DbContext, IAdminConfigurationDbContext where TPersistedGrantDbContext : DbContext, IAdminPersistedGrantDbContext where TIdentityDbContext : DbContext { var configurationDbConnectionString = configuration.GetConnectionString(ConfigurationConsts.ConfigurationDbConnectionStringKey); var persistedGrantsDbConnectionString = configuration.GetConnectionString(ConfigurationConsts.PersistedGrantDbConnectionStringKey); var identityDbConnectionString = configuration.GetConnectionString(ConfigurationConsts.IdentityDbConnectionStringKey); var healthChecksBuilder = services.AddHealthChecks() .AddDbContextCheck <TConfigurationDbContext>("ConfigurationDbContext") .AddDbContextCheck <TPersistedGrantDbContext>("PersistedGrantsDbContext") .AddDbContextCheck <TIdentityDbContext>("IdentityDbContext"); var serviceProvider = services.BuildServiceProvider(); var scopeFactory = serviceProvider.GetRequiredService <IServiceScopeFactory>(); using (var scope = scopeFactory.CreateScope()) { var configurationTableName = DbContextHelpers.GetEntityTable <TConfigurationDbContext>(scope.ServiceProvider); var persistedGrantTableName = DbContextHelpers.GetEntityTable <TPersistedGrantDbContext>(scope.ServiceProvider); var identityTableName = DbContextHelpers.GetEntityTable <TIdentityDbContext>(scope.ServiceProvider); var databaseProvider = configuration.GetSection(nameof(DatabaseProviderConfiguration)).Get <DatabaseProviderConfiguration>(); healthChecksBuilder .AddSqlServer(configurationDbConnectionString, name: "ConfigurationDb", healthQuery: $"SELECT TOP 1 * FROM dbo.[{configurationTableName}]") .AddSqlServer(persistedGrantsDbConnectionString, name: "PersistentGrantsDb", healthQuery: $"SELECT TOP 1 * FROM dbo.[{persistedGrantTableName}]") .AddSqlServer(identityDbConnectionString, name: "IdentityDb", healthQuery: $"SELECT TOP 1 * FROM dbo.[{identityTableName}]"); } }
public void Initialize() { DbContextHelpers contextHelpers = new DbContextHelpers(); db = contextHelpers.getDbContext(); search = new WorkoutSearch(); myWorkoutsCon = new MyWorkoutsController(db.Object) { ControllerContext = MockContext.AuthenticationContext("jjones") }; myWorkoutsCon.pageSize = 10; ts = new byte[] { 0, 0, 0, 0, 0, 0, 0, 0 }; uWorkout = new user_workout() { id = 1, number_of_ex_completed = 0, workout_id = 1, user_id = 2, timestamp = ts, workout = new workout() { workout_exercise = new List <workout_exercise> { { new workout_exercise() }, { new workout_exercise() }, { new workout_exercise() }, { new workout_exercise() }, } } }; }
public async void ShouldQueueNextExecution() { var fixture = new Fixture(); var queueClient = new Mock <IQueueClient>(); var mediator = new Mock <IMediator>(); var userService = new Mock <ICurrentUserService>(); var createCommand = fixture.Create <CreateManagementJobCommand>(); using (var dbContext = DbContextHelpers.CreateDatabaseContext()) { var createCommandHandler = new CreateManagementJobCommandHandler(dbContext); var createdId = await createCommandHandler.Handle(createCommand, CancellationToken.None); // set the job to "IsActive" var startCommand = new StartManagementJobCommand { ManagementJobId = createdId }; var startCommandHandler = new StartManagementJobCommandHandler(dbContext); await startCommandHandler.Handle(startCommand, CancellationToken.None); var executeCommand = new ExecuteManagementJobCommand { ManagementJobId = createdId }; var executeCommandHandler = new ExecuteManagementJobCommandHandler(dbContext, queueClient.Object, mediator.Object, userService.Object); await executeCommandHandler.Handle(executeCommand, CancellationToken.None); // should not call queue client because job is set to inactive queueClient.Verify(x => x.EnqueueManagementJob(executeCommand), Times.Once); } }
public void Initialize() { DbContextHelpers contextHelpers = new DbContextHelpers(); db = contextHelpers.getDbContext(); controller = new WorkoutRatingController(db.Object) { ControllerContext = MockContext.AuthenticationContext("jjones") }; }
public void Initialize() { DbContextHelpers contextHelpers = new DbContextHelpers(); db = contextHelpers.getDbContext(); myProfileCon = new MyProfileController(db.Object) { ControllerContext = MockContext.AuthenticationContext("jjones") }; }
public void Initialize() { DbContextHelpers contextHelpers = new DbContextHelpers(); db = contextHelpers.getDbContext(); myAccountCon = new MyAccountController(db.Object); //{ // ControllerContext = MockContext.AuthenticationContext("jjones") //}; }
public void SlaMetricDetailsContext_WhenInitialized_ReturnsValidObject() { // ARRANGE var connectionString = DbContextHelpers.GetC3msConnectionString(); // ACT var dbContext = new SlaMetricDetailsContext(connectionString); // ASSERT Assert.NotNull(dbContext); }
public static void AddIdSHealthChecks <TConfigurationDbContext, TPersistedGrantDbContext, TIdentityDbContext, TLogDbContext, TAuditLoggingDbContext, TDataProtectionDbContext>(this IServiceCollection services, IConfiguration configuration, AdminApiConfiguration adminApiConfiguration) where TConfigurationDbContext : DbContext, IAdminConfigurationDbContext where TPersistedGrantDbContext : DbContext, IAdminPersistedGrantDbContext where TIdentityDbContext : DbContext where TLogDbContext : DbContext, IAdminLogDbContext where TAuditLoggingDbContext : DbContext, IAuditLoggingDbContext <AuditLog> where TDataProtectionDbContext : DbContext, IDataProtectionKeyContext { var configurationDbConnectionString = configuration.GetConnectionString(ConfigurationConsts.ConfigurationDbConnectionStringKey); var persistedGrantsDbConnectionString = configuration.GetConnectionString(ConfigurationConsts.PersistedGrantDbConnectionStringKey); var identityDbConnectionString = configuration.GetConnectionString(ConfigurationConsts.IdentityDbConnectionStringKey); var logDbConnectionString = configuration.GetConnectionString(ConfigurationConsts.AdminLogDbConnectionStringKey); var auditLogDbConnectionString = configuration.GetConnectionString(ConfigurationConsts.AdminAuditLogDbConnectionStringKey); var dataProtectionDbConnectionString = configuration.GetConnectionString(ConfigurationConsts.DataProtectionDbConnectionStringKey); var identityServerUri = adminApiConfiguration.IdentityServerBaseUrl; var healthChecksBuilder = services.AddHealthChecks() .AddDbContextCheck <TConfigurationDbContext>("ConfigurationDbContext") .AddDbContextCheck <TPersistedGrantDbContext>("PersistedGrantsDbContext") .AddDbContextCheck <TIdentityDbContext>("IdentityDbContext") .AddDbContextCheck <TLogDbContext>("LogDbContext") .AddDbContextCheck <TAuditLoggingDbContext>("AuditLogDbContext") .AddDbContextCheck <TDataProtectionDbContext>("DataProtectionDbContext") .AddIdentityServer(new Uri(identityServerUri), "Identity Server"); var serviceProvider = services.BuildServiceProvider(); var scopeFactory = serviceProvider.GetRequiredService <IServiceScopeFactory>(); using (var scope = scopeFactory.CreateScope()) { var configurationTableName = DbContextHelpers.GetEntityTable <TConfigurationDbContext>(scope.ServiceProvider); var persistedGrantTableName = DbContextHelpers.GetEntityTable <TPersistedGrantDbContext>(scope.ServiceProvider); var identityTableName = DbContextHelpers.GetEntityTable <TIdentityDbContext>(scope.ServiceProvider); var logTableName = DbContextHelpers.GetEntityTable <TLogDbContext>(scope.ServiceProvider); var auditLogTableName = DbContextHelpers.GetEntityTable <TAuditLoggingDbContext>(scope.ServiceProvider); var dataProtectionTableName = DbContextHelpers.GetEntityTable <TDataProtectionDbContext>(scope.ServiceProvider); healthChecksBuilder .AddNpgSql(configurationDbConnectionString, name: "ConfigurationDb", healthQuery: $"SELECT * FROM \"{configurationTableName}\" LIMIT 1") .AddNpgSql(persistedGrantsDbConnectionString, name: "PersistentGrantsDb", healthQuery: $"SELECT * FROM \"{persistedGrantTableName}\" LIMIT 1") .AddNpgSql(identityDbConnectionString, name: "IdentityDb", healthQuery: $"SELECT * FROM \"{identityTableName}\" LIMIT 1") .AddNpgSql(logDbConnectionString, name: "LogDb", healthQuery: $"SELECT * FROM \"{logTableName}\" LIMIT 1") .AddNpgSql(auditLogDbConnectionString, name: "AuditLogDb", healthQuery: $"SELECT * FROM \"{auditLogTableName}\" LIMIT 1") .AddNpgSql(dataProtectionDbConnectionString, name: "DataProtectionDb", healthQuery: $"SELECT * FROM \"{dataProtectionTableName}\" LIMIT 1"); } }
public void Initialize() { DbContextHelpers contextHelpers = new DbContextHelpers(); search = new WorkoutSearch(); db = contextHelpers.getDbContext(); controller = new HomeController(db.Object) { ControllerContext = MockContext.AuthenticationContext("jjones") }; controller.pageSize = 10; }
public InternalRepositoryTests() { data = new List<Cigar> { new Cigar {Id = 1}, new Cigar {Id = 2}, new Cigar {Id = 3} }.AsQueryable(); mockDbSet = DbContextHelpers.CreateMockDbSet(data); mockContext = DbContextHelpers.CreateMockDbContext(mockDbSet.Object); repository = new Repository<Cigar>(mockContext.Object); }
public void Initialize() { DbContextHelpers contextHelpers = new DbContextHelpers(); search = new TypeSearch(); db = contextHelpers.getDbContext(); adminCon = new AdminTypesController(db.Object) { // sign in as admin ControllerContext = MockContext.AuthenticationContext("admin") }; }
public void SlaMetricDetailsContext_WhenQueriedForMetrics_ReturnsList() { // ARRANGE var connectionString = DbContextHelpers.GetC3msConnectionString(); var dbContext = new SlaMetricDetailsContext(connectionString); // ACT var actual = dbContext.SowMetrics.ToList(); // ASSERT Assert.NotNull(actual); Assert.True(actual.Count > 0); }
public static void AddIdSHealthChecks <TConfigurationDbContext, TPersistedGrantDbContext, TIdentityDbContext, TAuditLoggingDbContext>(this IServiceCollection services, IConfiguration configuration, AdminConfiguration adminConfiguration) where TConfigurationDbContext : DbContext, IAdminConfigurationDbContext where TPersistedGrantDbContext : DbContext, IAdminPersistedGrantDbContext where TIdentityDbContext : DbContext where TAuditLoggingDbContext : DbContext, IAuditLoggingDbContext <AuditLog> { var configurationDbConnectionString = configuration.GetConnectionString(ConfigurationConsts.ConfigurationDbConnectionStringKey); var persistedGrantsDbConnectionString = configuration.GetConnectionString(ConfigurationConsts.PersistedGrantDbConnectionStringKey); var identityDbConnectionString = configuration.GetConnectionString(ConfigurationConsts.IdentityDbConnectionStringKey); var auditLogDbConnectionString = configuration.GetConnectionString(ConfigurationConsts.AdminAuditLogDbConnectionStringKey); var identityServerUri = adminConfiguration.IdentityServerBaseUrl; var healthChecksBuilder = services.AddHealthChecks() .AddDbContextCheck <TConfigurationDbContext>("ConfigurationDbContext") .AddDbContextCheck <TPersistedGrantDbContext>("PersistedGrantsDbContext") .AddDbContextCheck <TIdentityDbContext>("IdentityDbContext") .AddDbContextCheck <TAuditLoggingDbContext>("AuditLogDbContext") .AddIdentityServer(new Uri(identityServerUri), "Identity Server"); var serviceProvider = services.BuildServiceProvider(); var scopeFactory = serviceProvider.GetRequiredService <IServiceScopeFactory>(); using (var scope = scopeFactory.CreateScope()) { var configurationTableName = DbContextHelpers.GetEntityTable <TConfigurationDbContext>(scope.ServiceProvider); var persistedGrantTableName = DbContextHelpers.GetEntityTable <TPersistedGrantDbContext>(scope.ServiceProvider); var identityTableName = DbContextHelpers.GetEntityTable <TIdentityDbContext>(scope.ServiceProvider); var auditLogTableName = DbContextHelpers.GetEntityTable <TAuditLoggingDbContext>(scope.ServiceProvider); var databaseProvider = configuration.GetSection(nameof(DatabaseProviderConfiguration)).Get <DatabaseProviderConfiguration>(); switch (databaseProvider.ProviderType) { case DatabaseProviderType.PostgreSql: healthChecksBuilder .AddNpgSql(configurationDbConnectionString, name: "ConfigurationDb", healthQuery: $"SELECT * FROM {configurationTableName} LIMIT 1") .AddNpgSql(persistedGrantsDbConnectionString, name: "PersistentGrantsDb", healthQuery: $"SELECT * FROM {persistedGrantTableName} LIMIT 1") .AddNpgSql(identityDbConnectionString, name: "IdentityDb", healthQuery: $"SELECT * FROM {identityTableName} LIMIT 1") .AddNpgSql(auditLogDbConnectionString, name: "AuditLogDb", healthQuery: $"SELECT * FROM {auditLogTableName} LIMIT 1"); break; default: throw new NotImplementedException($"Health checks not defined for database provider {databaseProvider.ProviderType}"); } } }
public async void ShouldAddUser() { var fixture = new Fixture(); using (DatabaseContext dbContext = DbContextHelpers.CreateDatabaseContext()) { var command = fixture.Create <AddUserCommand>(); var handler = new AddUserCommandHandler(dbContext); await handler.Handle(command, CancellationToken.None); var created = await dbContext.Users.FindAsync(command.UserId); created.Id.Should().Be(command.UserId); } }
public async void ShouldThrowIfJobDoesNotExist() { var fixture = new Fixture(); var queueClient = new Mock <IQueueClient>(); var mediator = new Mock <IMediator>(); var userService = new Mock <ICurrentUserService>(); // id of management job will not exist in database, therefore execption will be thrown var command = fixture.Create <ExecuteManagementJobCommand>(); using (var dbContext = DbContextHelpers.CreateDatabaseContext()) { var handler = new ExecuteManagementJobCommandHandler(dbContext, queueClient.Object, mediator.Object, userService.Object); await Assert.ThrowsAsync <ManagementJobNotFoundException>(() => handler.Handle(command, CancellationToken.None)); } }
private static string GetConnectionString(Type type) { //Can't switch on type, and missing patterns from C# 7 =( if (type == typeof(C3MSEntities)) { return(DbContextHelpers.FormatC3msEfConnectionString(DbContextHelpers.GetC3msConnectionString())); } if (type == typeof(SslamEntities)) { return(DbContextHelpers.FormatSslamEfConnectionString(DbContextHelpers.GetC3msConnectionString())); } return(null); }
public virtual void Can_insert_update_delete() { DbContextHelpers.ExecuteWithStrategyInTransaction( CreateContext, UseTransaction, context => { var kiwi = new Kiwi { Species = "Apteryx owenii", Name = "Little spotted kiwi", IsFlightless = true, FoundOn = Island.North }; var nz = context.Set <Country>().Single(c => c.Id == 1); nz.Animals.Add(kiwi); context.SaveChanges(); }, context => { var kiwi = context.Set <Kiwi>().Single(k => k.Species.EndsWith("owenii")); kiwi.EagleId = "Aquila chrysaetos canadensis"; context.SaveChanges(); }, context => { var kiwi = context.Set <Kiwi>().Single(k => k.Species.EndsWith("owenii")); Assert.Equal("Aquila chrysaetos canadensis", kiwi.EagleId); context.Set <Bird>().Remove(kiwi); context.SaveChanges(); }, context => { var count = context.Set <Kiwi>().Count(k => k.Species.EndsWith("owenii")); Assert.Equal(0, count); }); }
public async void CreateManagementJobCommand_InsertsIntoDatabase() { var fixture = new Fixture(); using (DatabaseContext dbContext = DbContextHelpers.CreateDatabaseContext()) { var command = fixture.Create <CreateManagementJobCommand>(); var handler = new CreateManagementJobCommandHandler(dbContext); var result = await handler.Handle(command, CancellationToken.None); result.Should().NotBeEmpty(); var created = await dbContext.ManagementJobs.FindAsync(result); created.PlaylistId.Should().Be(command.PlaylistId); } }
protected virtual void Update <TBlog>(string navigation) where TBlog : class, IBlogAccesor, new() { DbContextHelpers.ExecuteWithStrategyInTransaction(CreateContext, UseTransaction, context => { var blogs = context.Set <TBlog>().ToList(); foreach (var blog in blogs) { context.Entry(blog).Collection(navigation).Load(); blog.AccessTitle += "Updated"; foreach (var post in blog.AccessPosts) { post.AccessTitle += "Updated"; } } AssertGraph(blogs, "Updated"); context.SaveChanges(); AssertGraph(blogs, "Updated"); }, context => { var blogs = context.Set <TBlog>().ToList(); foreach (var blog in blogs) { context.Entry(blog).Collection(navigation).Load(); } AssertGraph(blogs, "Updated"); }); }
public CigarRepositoryTests() { var data = new List <Cigar> { new Cigar { Id = 1, Name = "Test1", Country = "Finland" }, new Cigar { Id = 2, Name = "Test2", Country = "Germany" }, new Cigar { Id = 3, Name = "Temp4", Country = "France" }, new Cigar { Id = 4, Name = "Temp3", Country = "Finland" } }.AsQueryable(); var mockDbSet = DbContextHelpers.CreateMockDbSet(data); var mockContext = DbContextHelpers.CreateMockDbContext(mockDbSet.Object); cigarRepository = new CigarRepository(mockContext.Object); }
public static void AddIdSHealthChecks <TConfigurationDbContext, TPersistedGrantDbContext, TIdentityDbContext, TLogDbContext, TAuditLoggingDbContext, TDataProtectionDbContext, TAuditLog> (this IHealthChecksBuilder healthChecksBuilder, AdminConfiguration adminConfiguration, ConnectionStringsConfiguration connectionStringsConfiguration, DatabaseProviderConfiguration databaseProviderConfiguration) where TConfigurationDbContext : DbContext, IAdminConfigurationDbContext where TPersistedGrantDbContext : DbContext, IAdminPersistedGrantDbContext where TIdentityDbContext : DbContext where TLogDbContext : DbContext, IAdminLogDbContext where TAuditLoggingDbContext : DbContext, IAuditLoggingDbContext <TAuditLog> where TDataProtectionDbContext : DbContext, IDataProtectionKeyContext where TAuditLog : AuditLog { var configurationDbConnectionString = connectionStringsConfiguration.ConfigurationDbConnection; var persistedGrantsDbConnectionString = connectionStringsConfiguration.PersistedGrantDbConnection; var identityDbConnectionString = connectionStringsConfiguration.IdentityDbConnection; var logDbConnectionString = connectionStringsConfiguration.AdminLogDbConnection; var auditLogDbConnectionString = connectionStringsConfiguration.AdminAuditLogDbConnection; var dataProtectionDbConnectionString = connectionStringsConfiguration.DataProtectionDbConnection; var identityServerUri = adminConfiguration.IdentityServerBaseUrl; healthChecksBuilder = healthChecksBuilder .AddDbContextCheck <TConfigurationDbContext>("ConfigurationDbContext") .AddDbContextCheck <TPersistedGrantDbContext>("PersistedGrantsDbContext") .AddDbContextCheck <TIdentityDbContext>("IdentityDbContext") .AddDbContextCheck <TLogDbContext>("LogDbContext") .AddDbContextCheck <TAuditLoggingDbContext>("AuditLogDbContext") .AddDbContextCheck <TDataProtectionDbContext>("DataProtectionDbContext") .AddIdentityServer(new Uri(identityServerUri), "Identity Server"); var serviceProvider = healthChecksBuilder.Services.BuildServiceProvider(); var scopeFactory = serviceProvider.GetRequiredService <IServiceScopeFactory>(); using (var scope = scopeFactory.CreateScope()) { var configurationTableName = DbContextHelpers.GetEntityTable <TConfigurationDbContext>(scope.ServiceProvider); var persistedGrantTableName = DbContextHelpers.GetEntityTable <TPersistedGrantDbContext>(scope.ServiceProvider); var identityTableName = DbContextHelpers.GetEntityTable <TIdentityDbContext>(scope.ServiceProvider); var logTableName = DbContextHelpers.GetEntityTable <TLogDbContext>(scope.ServiceProvider); var auditLogTableName = DbContextHelpers.GetEntityTable <TAuditLoggingDbContext>(scope.ServiceProvider); var dataProtectionTableName = DbContextHelpers.GetEntityTable <TDataProtectionDbContext>(scope.ServiceProvider); switch (databaseProviderConfiguration.ProviderType) { case DatabaseProviderType.SqlServer: healthChecksBuilder .AddSqlServer(configurationDbConnectionString, name: "ConfigurationDb", healthQuery: $"SELECT TOP 1 * FROM dbo.[{configurationTableName}]") .AddSqlServer(persistedGrantsDbConnectionString, name: "PersistentGrantsDb", healthQuery: $"SELECT TOP 1 * FROM dbo.[{persistedGrantTableName}]") .AddSqlServer(identityDbConnectionString, name: "IdentityDb", healthQuery: $"SELECT TOP 1 * FROM dbo.[{identityTableName}]") .AddSqlServer(logDbConnectionString, name: "LogDb", healthQuery: $"SELECT TOP 1 * FROM dbo.[{logTableName}]") .AddSqlServer(auditLogDbConnectionString, name: "AuditLogDb", healthQuery: $"SELECT TOP 1 * FROM dbo.[{auditLogTableName}]") .AddSqlServer(dataProtectionDbConnectionString, name: "DataProtectionDb", healthQuery: $"SELECT TOP 1 * FROM dbo.[{dataProtectionTableName}]"); break; case DatabaseProviderType.PostgreSQL: healthChecksBuilder .AddNpgSql(configurationDbConnectionString, name: "ConfigurationDb", healthQuery: $"SELECT * FROM \"{configurationTableName}\" LIMIT 1") .AddNpgSql(persistedGrantsDbConnectionString, name: "PersistentGrantsDb", healthQuery: $"SELECT * FROM \"{persistedGrantTableName}\" LIMIT 1") .AddNpgSql(identityDbConnectionString, name: "IdentityDb", healthQuery: $"SELECT * FROM \"{identityTableName}\" LIMIT 1") .AddNpgSql(logDbConnectionString, name: "LogDb", healthQuery: $"SELECT * FROM \"{logTableName}\" LIMIT 1") .AddNpgSql(auditLogDbConnectionString, name: "AuditLogDb", healthQuery: $"SELECT * FROM \"{auditLogTableName}\" LIMIT 1") .AddNpgSql(dataProtectionDbConnectionString, name: "DataProtectionDb", healthQuery: $"SELECT * FROM \"{dataProtectionTableName}\" LIMIT 1"); break; case DatabaseProviderType.MySql: healthChecksBuilder .AddMySql(configurationDbConnectionString, name: "ConfigurationDb") .AddMySql(persistedGrantsDbConnectionString, name: "PersistentGrantsDb") .AddMySql(identityDbConnectionString, name: "IdentityDb") .AddMySql(logDbConnectionString, name: "LogDb") .AddMySql(auditLogDbConnectionString, name: "AuditLogDb") .AddMySql(dataProtectionDbConnectionString, name: "DataProtectionDb"); break; default: throw new NotImplementedException($"Health checks not defined for database provider {databaseProviderConfiguration.ProviderType}"); } } }
public void SlaMetricDetailsContext_WhenPagedSearchRepositoryExtensionUsed_ReturnsMultipleLists() { // ARRANGE var connectionString = DbContextHelpers.GetC3msConnectionString(); var dbContext = new SlaMetricDetailsContext(connectionString); var pagedSearchRequest = new PagedSearchRequest { SearchStoredProcedure = "dbo.usp_GetSlaGoalsSearchTestData_sel", SearchResultSetType = "SslamSearchResultModel", Page = 1, PageSize = 50, SortBy = "ContractID", SortDirection = "desc" }; pagedSearchRequest.Parameters.Add(new Parameter("sowMetricID", 5, DbType.Int32, false)); pagedSearchRequest.Parameters.Add(new Parameter("state", "CA", DbType.String, false)); pagedSearchRequest.Parameters.Add(new Parameter("masterID", "", DbType.String, false)); pagedSearchRequest.Parameters.Add(new Parameter("fileTypeID", "", DbType.String, false)); pagedSearchRequest.Parameters.Add(new Parameter("courtType", "", DbType.String, false)); pagedSearchRequest.Parameters.Add(new Parameter("vendorID", 0, DbType.Int32, false)); pagedSearchRequest.Parameters.Add(new Parameter("vendorIdFilter", null, DbType.String, true)); pagedSearchRequest.Parameters.Add(new Parameter("contractIdFilter", null, DbType.String, true)); pagedSearchRequest.Parameters.Add(new Parameter("supplierNameFilter", null, DbType.String, true)); pagedSearchRequest.Parameters.Add(new Parameter("courtFilter", null, DbType.String, true)); pagedSearchRequest.Parameters.Add(new Parameter("fileTypeFilter", null, DbType.String, true)); pagedSearchRequest.Parameters.Add(new Parameter("serviceFilter", null, DbType.String, true)); pagedSearchRequest.Parameters.Add(new Parameter("goalFilter", null, DbType.String, true)); pagedSearchRequest.Parameters.Add(new Parameter("thresholdFilter", null, DbType.String, true)); pagedSearchRequest.Parameters.Add(new Parameter("startDateFilter", null, DbType.String, true)); pagedSearchRequest.Parameters.Add(new Parameter("endDateFilter", null, DbType.String, true)); pagedSearchRequest.ColumnConfigurations.Add(new ColumnConfiguration { ColumnBinding = "vendorId", ColumnHeader = "Vendor", ResultSetType = "VendorModel" }); pagedSearchRequest.ColumnConfigurations.Add(new ColumnConfiguration { ColumnBinding = "contractId", ColumnHeader = "Contract", ResultSetType = "ContractModel" }); pagedSearchRequest.ColumnConfigurations.Add(new ColumnConfiguration { ColumnBinding = "supplierName", ColumnHeader = "Business Name", ResultSetType = "BusinessNameModel" }); pagedSearchRequest.ColumnConfigurations.Add(new ColumnConfiguration { ColumnBinding = "court", ColumnHeader = "Court", ResultSetType = "CourtModel" }); pagedSearchRequest.ColumnConfigurations.Add(new ColumnConfiguration { ColumnBinding = "fileType", ColumnHeader = "File Type", ResultSetType = "FileTypeModel" }); pagedSearchRequest.ColumnConfigurations.Add(new ColumnConfiguration { ColumnBinding = "service", ColumnHeader = "Product", ResultSetType = "ServiceModel" }); pagedSearchRequest.ColumnConfigurations.Add(new ColumnConfiguration { ColumnBinding = "goal", ColumnHeader = "Goal", ResultSetType = "GoalModel" }); pagedSearchRequest.ColumnConfigurations.Add(new ColumnConfiguration { ColumnBinding = "threshold", ColumnHeader = "Threshold", ResultSetType = "ThresholdModel" }); pagedSearchRequest.ColumnConfigurations.Add(new ColumnConfiguration { ColumnBinding = "startDate", ColumnHeader = "Start Date", ResultSetType = "StartDateModel" }); pagedSearchRequest.ColumnConfigurations.Add(new ColumnConfiguration { ColumnBinding = "endDate", ColumnHeader = "End Date", ResultSetType = "EndDateModel" }); // ACT var actual = dbContext.PagedResults() .WithSearchResult <SslamSearchResultModel>() .WithColumnFilterResult() .WithColumnFilterResult() .WithColumnFilterResult() .WithColumnFilterResult() .WithColumnFilterResult() .WithColumnFilterResult() .WithColumnFilterResult() .WithColumnFilterResult() .WithColumnFilterResult() .WithColumnFilterResult() .Search(pagedSearchRequest); // ASSERT Assert.NotNull(actual); Assert.True(actual.TotalResults > 0); Assert.True(actual.Page == pagedSearchRequest.Page); Assert.True(actual.PageSize == pagedSearchRequest.PageSize); Assert.True(actual.SortBy == pagedSearchRequest.SortBy); Assert.True(actual.SortDirection == pagedSearchRequest.SortDirection); Assert.NotNull(actual.SearchResults); var searchResults = actual.SearchResults as IEnumerable <SslamSearchResultModel>; Assert.True(searchResults.Count() == 50); Assert.True(actual.Columns.Count == 10); Assert.True(pagedSearchRequest.ColumnConfigurations.Count == actual.Columns.Count); Assert.True(pagedSearchRequest.ColumnConfigurations[0].ColumnBinding == actual.Columns[0].ColumnId); Assert.True((actual.Columns[0].FilterValues as IEnumerable <string>).Any()); Assert.True(pagedSearchRequest.ColumnConfigurations[1].ColumnBinding == actual.Columns[1].ColumnId); Assert.True((actual.Columns[1].FilterValues as IEnumerable <string>).Any()); Assert.True(pagedSearchRequest.ColumnConfigurations[2].ColumnBinding == actual.Columns[2].ColumnId); Assert.True((actual.Columns[2].FilterValues as IEnumerable <string>).Any()); Assert.True(pagedSearchRequest.ColumnConfigurations[3].ColumnBinding == actual.Columns[3].ColumnId); Assert.True((actual.Columns[3].FilterValues as IEnumerable <string>).Any()); Assert.True(pagedSearchRequest.ColumnConfigurations[4].ColumnBinding == actual.Columns[4].ColumnId); Assert.True((actual.Columns[4].FilterValues as IEnumerable <string>).Any()); Assert.True(pagedSearchRequest.ColumnConfigurations[5].ColumnBinding == actual.Columns[5].ColumnId); Assert.True((actual.Columns[5].FilterValues as IEnumerable <string>).Any()); Assert.True(pagedSearchRequest.ColumnConfigurations[6].ColumnBinding == actual.Columns[6].ColumnId); Assert.True((actual.Columns[6].FilterValues as IEnumerable <string>).Any()); Assert.True(pagedSearchRequest.ColumnConfigurations[7].ColumnBinding == actual.Columns[7].ColumnId); Assert.True((actual.Columns[7].FilterValues as IEnumerable <string>).Any()); Assert.True(pagedSearchRequest.ColumnConfigurations[8].ColumnBinding == actual.Columns[8].ColumnId); Assert.True((actual.Columns[8].FilterValues as IEnumerable <string>).Any()); Assert.True(pagedSearchRequest.ColumnConfigurations[9].ColumnBinding == actual.Columns[9].ColumnId); Assert.True((actual.Columns[9].FilterValues as IEnumerable <string>).Any()); var resultsJson = JsonConvert.SerializeObject(actual); var deserializedResult = JObject.Parse(resultsJson); Assert.True((deserializedResult["SearchResults"] as JArray).Count() == 50); Assert.True((deserializedResult["Columns"] as JArray).Count() == 10); Assert.True((int)deserializedResult["Page"] == pagedSearchRequest.Page); Assert.True((int)deserializedResult["PageSize"] == pagedSearchRequest.PageSize); Assert.True((string)deserializedResult["SortBy"] == pagedSearchRequest.SortBy); Assert.True((string)deserializedResult["SortDirection"] == pagedSearchRequest.SortDirection); Assert.True((int)deserializedResult["TotalResults"] == 1000); }
public void GetC3msConnectionString_WhenCalled_WillReturnTheConnectionStringWithTheFullPath() { Assert.NotEmpty(DbContextHelpers.GetC3msConnectionString()); }
protected virtual void ExecuteWithStrategyInTransaction( Action <UpdatesContext> testOperation, Action <UpdatesContext> nestedTestOperation1 = null) => DbContextHelpers.ExecuteWithStrategyInTransaction(CreateContext, UseTransaction, testOperation, nestedTestOperation1);
protected virtual Task ExecuteWithStrategyInTransactionAsync( Func <UpdatesContext, Task> testOperation, Func <UpdatesContext, Task> nestedTestOperation1 = null) => DbContextHelpers.ExecuteWithStrategyInTransactionAsync(CreateContext, UseTransaction, testOperation, nestedTestOperation1);