Ejemplo n.º 1
0
        public async Task BeforeEachTest()
        {
            const string connectionStringEnvironmentVariable =
                "ASPNETCORE_MyMeetings_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>();
            ExecutionContext = new ExecutionContextMock(Guid.NewGuid());

            AdministrationStartup.Initialize(
                ConnectionString,
                ExecutionContext,
                Logger);

            AdministrationModule = new AdministrationModule();
        }
        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));
        }
Ejemplo n.º 3
0
        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 = 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>();
            ExecutionContext = new ExecutionContextMock(Guid.NewGuid());

            EventsBus = new InMemoryEventBusClient(Logger);


            AdministrationModule = new AdministrationModule();
            MeetingsModule       = new MeetingsModule();
            MeetingsStartup      = new MeetingsStartup();

            AdministrationStartup.Initialize(
                ConnectionString,
                ExecutionContext,
                Logger,
                EventsBus);

            MeetingsStartup.Initialize(
                ConnectionString,
                ExecutionContext,
                Logger,
                new EmailsConfiguration("*****@*****.**"),
                EventsBus);
        }