public void DatabaseConnectionString_ReturnsCorrectly() { var connectionString = DbConfiguration.DatabaseConnectionString(_mockEnv.Object); connectionString.Should().Be("Host=host.com;" + "Database=database;" + "Username=username2;" + "Password=password2;" + "Port=1234;" + "SSL Mode=Require;" + "Trust Server Certificate=True"); }
// This method gets called by the runtime. Use this method to add services to the container. public void ConfigureServices(IServiceCollection services) { var env = new Env(); ConfigureRateLimiting(services); if (env.IsDevelopment) { DotEnv.Config(true, ".env.development"); } services.AddSingleton <CdsServiceClientWrapper, CdsServiceClientWrapper>(); services.AddTransient <IOrganizationService>(sp => sp.GetService <CdsServiceClientWrapper>().CdsServiceClient?.Clone()); services.AddTransient <IOrganizationServiceAdapter, OrganizationServiceAdapter>(); services.AddTransient <ICrmService, CrmService>(); services.AddScoped <IStore, Store>(); services.AddScoped <DbConfiguration, DbConfiguration>(); services.AddSingleton <IMetricService, MetricService>(); services.AddSingleton <INotificationClientAdapter, NotificationClientAdapter>(); services.AddSingleton <IGeocodeClientAdapter, GeocodeClientAdapter>(); services.AddSingleton <ICandidateAccessTokenService, CandidateAccessTokenService>(); services.AddSingleton <ICandidateMagicLinkTokenService, CandidateMagicLinkTokenService>(); services.AddSingleton <INotifyService, NotifyService>(); services.AddSingleton <IClientManager, ClientManager>(); services.AddSingleton <IHangfireService, HangfireService>(); services.AddSingleton <IRedisService, RedisService>(); services.AddSingleton <IPerformContextAdapter, PerformContextAdapter>(); services.AddSingleton <ICallbackBookingService, CallbackBookingService>(); services.AddSingleton <IEnv>(env); var connectionString = DbConfiguration.DatabaseConnectionString(env); services.AddDbContext <GetIntoTeachingDbContext>(b => DbConfiguration.ConfigPostgres(connectionString, b)); services.AddAuthentication("ApiClientHandler") .AddScheme <ApiClientSchemaOptions, ApiClientHandler>("ApiClientHandler", op => { }); services.AddControllers(o => { o.ModelBinderProviders.Insert(0, new TrimStringModelBinderProvider()); }) .AddFluentValidation(c => { c.RegisterValidatorsFromAssemblyContaining <Startup>(); }) .AddJsonOptions(o => { o.JsonSerializerOptions.Converters.Add(new JsonStringEnumConverter()); o.JsonSerializerOptions.Converters.Add(new TrimStringJsonConverter()); o.JsonSerializerOptions.Converters.Add(new EmptyStringToNullJsonConverter()); }); services.Configure <KestrelServerOptions>(options => { // Workaround for https://github.com/dotnet/aspnetcore/issues/8302 // caused by Prometheus.HttpMetrics.HttpRequestDurationMiddleware options.AllowSynchronousIO = true; }); services.AddSwaggerGen(c => { c.SwaggerDoc( "v1", new OpenApiInfo { Title = "Get into Teaching API - V1", Version = "v1", Description = @" Provides a RESTful API for integrating with the Get into Teaching CRM. The Get into Teaching (GIT) API sits in front of the GIT CRM, which uses the [Microsoft Dynamics365](https://docs.microsoft.com/en-us/dynamics365/) platform (the [Customer Engagement](https://docs.microsoft.com/en-us/dynamics365/customerengagement/on-premises/developer/overview) module is used for storing Candidate information and the [Marketing](https://docs.microsoft.com/en-us/dynamics365/marketing/developer/using-events-api) module for managing Events). The GIT API aims to provide: * Simple, task-based RESTful APIs. * Message queueing (while the GIT CRM is offline for updates). * Validation to ensure consistency across services writing to the GIT CRM. ", License = new OpenApiLicense { Name = "MIT License", Url = new Uri("https://opensource.org/licenses/MIT"), }, }); c.AddSecurityDefinition("apiKey", new OpenApiSecurityScheme { Type = SecuritySchemeType.ApiKey, Name = "Authorization", In = ParameterLocation.Header, }); c.OperationFilter <AuthOperationFilter>(); c.EnableAnnotations(); c.AddFluentValidationRules(); }); services.AddHangfire((provider, config) => { var automaticRetry = new AutomaticRetryAttribute { Attempts = JobConfiguration.Attempts(env), DelaysInSeconds = new[] { JobConfiguration.RetryIntervalInSeconds(env) }, OnAttemptsExceeded = AttemptsExceededAction.Delete, }; config .SetDataCompatibilityLevel(CompatibilityLevel.Version_170) .UseSimpleAssemblyNameTypeSerializer() .UseRecommendedSerializerSettings() .UseFilter(automaticRetry); if (env.IsTest) { config.UseMemoryStorage().WithJobExpirationTimeout(JobConfiguration.ExpirationTimeout); } else { config.UsePostgreSqlStorage(DbConfiguration.HangfireConnectionString(env)); } }); }