public async Task BeforeEachTest() { const string connectionStringEnvironmentVariable = "ASPNETCORE_FootballBanter_IntegrationTests_ConnectionString"; ConnectionString = Environment.GetEnvironmentVariable(connectionStringEnvironmentVariable, EnvironmentVariableTarget.Machine); if (ConnectionString == null) { throw new ApplicationException( $"Define connection string to integration tests database using environment variable: {connectionStringEnvironmentVariable}"); } using (var sqlConnection = new SqlConnection(ConnectionString)) { await ClearDatabase(sqlConnection); } Logger = Substitute.For <ILogger>(); EmailSender = Substitute.For <IEmailSender>(); UserAccessStartup.Initialize( ConnectionString, new ExecutionContextMock(Guid.NewGuid()), Logger, new EmailsConfiguration("*****@*****.**", "sendGridUser", "sendGridKey"), "key", EmailSender, null); UserAccessModule = new UserAccessModule(); }
// This method gets called by the runtime. Use this method to configure the HTTP request pipeline. public void Configure(IApplicationBuilder app, IWebHostEnvironment env, IServiceProvider serviceProvider) { if (env.IsDevelopment()) { app.UseDeveloperExceptionPage(); } var httpContextAccessor = serviceProvider.GetService <IHttpContextAccessor>(); var logger = new LoggerConfiguration() .Enrich.FromLogContext() .WriteTo.Console( outputTemplate: "[{Timestamp:HH:mm:ss} {Level:u3}] [{Module}] [{Context}] {Message:lj}{NewLine}{Exception}") .WriteTo.ApplicationInsights(Configuration["ApplicationInsightKey"], TelemetryConverter.Traces) .CreateLogger(); UserAccessStartup.AddUserAccessModule(Configuration, logger); BetStartup.AddBetModule(Configuration, httpContextAccessor, logger); app.UseSwagger(); app.UseSwaggerUI(c => c.SwaggerEndpoint("/swagger/v1/swagger.json", "BetFriend.WebApi v1")); app.UseHttpsRedirection(); app.UseRouting(); app.UseAuthorization(); app.UseAuthentication(); app.UseEndpoints(endpoints => { endpoints.MapControllers(); }); }
private IServiceProvider CreateAutofacServiceProvider(IServiceCollection services) { var containerBuilder = new ContainerBuilder(); containerBuilder.Populate(services); containerBuilder.RegisterModule(new MeetingsAutofacModule()); containerBuilder.RegisterModule(new AdministrationAutofacModule()); containerBuilder.RegisterModule(new UserAccessAutofacModule()); containerBuilder.RegisterModule(new PaymentsAutofacModule()); var container = containerBuilder.Build(); var httpContextAccessor = container.Resolve <IHttpContextAccessor>(); var executionContextAccessor = new ExecutionContextAccessor(httpContextAccessor); var emailsConfiguration = new EmailsConfiguration(_configuration["EmailsConfiguration:FromEmail"]); MeetingsStartup.Initialize(this._configuration[MeetingsConnectionString], executionContextAccessor, _logger, emailsConfiguration); AdministrationStartup.Initialize(this._configuration[MeetingsConnectionString], executionContextAccessor, _logger); UserAccessStartup.Initialize( this._configuration[MeetingsConnectionString], executionContextAccessor, _logger, emailsConfiguration, this._configuration["Security:TextEncryptionKey"], null); PaymentsStartup.Initialize( this._configuration[MeetingsConnectionString], executionContextAccessor, _logger, null); return(new AutofacServiceProvider(container)); }
private void InitializeModules(ILifetimeScope container) { var httpContextAccessor = container.Resolve <IHttpContextAccessor>(); var executionContextAccessor = new ExecutionContextAccessor(httpContextAccessor); var emailsConfiguration = new EmailsConfiguration(_configuration["EmailsConfiguration:FromEmail"]); MeetingsStartup.Initialize( _configuration[MeetingsConnectionString], executionContextAccessor, _logger, emailsConfiguration, null); AdministrationStartup.Initialize( _configuration[MeetingsConnectionString], executionContextAccessor, _logger, null); UserAccessStartup.Initialize( _configuration[MeetingsConnectionString], executionContextAccessor, _logger, emailsConfiguration, _configuration["Security:TextEncryptionKey"], null); PaymentsStartup.Initialize( _configuration[MeetingsConnectionString], executionContextAccessor, _logger, emailsConfiguration, null); }
public async Task BeforeEachTest() { const string connectionStringEnvironmentVariable = "ASPNETCORE_MyMeetings_IntegrationTests_ConnectionString"; ConnectionString = "Server=.\\sqlexpress;Database=MyMeetings;Trusted_Connection=True;";//EnvironmentVariablesProvider.GetVariable(connectionStringEnvironmentVariable); if (ConnectionString == null) { throw new ApplicationException( $"Define connection string to integration tests database using environment variable: {connectionStringEnvironmentVariable}"); } using (var sqlConnection = new SqlConnection(ConnectionString)) { await ClearDatabase(sqlConnection); } Logger = Substitute.For <ILogger>(); EmailSender = Substitute.For <IEmailSender>(); UserAccessStartup.Initialize( ConnectionString, new ExecutionContextMock(Guid.NewGuid()), Logger, new EmailsConfiguration("*****@*****.**"), "key", EmailSender); UserAccessModule = new UserAccessModule(); }
private void InitializeModule(ILifetimeScope autofacContainer) { var emailsConfiguration = new EmailsConfiguration(Configuration["EmailsConfiguration:FromEmail"], Configuration["EmailsConfiguration:SendGridUser"], Configuration["EmailsConfiguration:SendGridKey"]); var httpContextAccessor = autofacContainer.Resolve <IHttpContextAccessor>(); var executionContextAccessor = new ExecutionContextAccessor(httpContextAccessor); var eventBus = new EventBusRabbitMQ(_logger, GetRabbitMQConnection(), "football-banter", "UserAccess", 5); UserAccessStartup.Initialize( Configuration["ConnectionString"], executionContextAccessor, _logger, emailsConfiguration, Configuration["Security:TextEncryptionKey"], null, eventBus ); }
// This method gets called by the runtime. Use this method to add services to the container. public void ConfigureServices(IServiceCollection services) { services.AddControllers(); services.AddSwaggerDocumentation(); services.AddPeTelecomIdentityServer(); services.AddHttpContextAccessor(); // TODO: why do we insert execution context accessor as a singleton? services.AddSingleton <IExecutionContextAccessor, ExecutionContextAccessor>(); services.AddScoped <IUserAccessModule>(_ => UserAccessStartup.UserAccessModuleFactory()); // TODO: Add Problem Details services.AddAuthorization(options => { options.AddPolicy(HasPermissionAttribute.HasPermissionPolicyName, policyBuilder => { policyBuilder.Requirements.Add(new HasPermissionAuthorizationRequirement()); policyBuilder.AddAuthenticationSchemes(IdentityServerAuthenticationDefaults.AuthenticationScheme); }); }); }