Esempio n. 1
0
    public ActorTestsFixture()
    {
        if (string.IsNullOrWhiteSpace(EswDevOpsSdk.GetEnvironmentName()))
        {
            var defaultTestExecutionEnvironment = DeploymentEnvironment.Development.ToString();
            System.Environment.SetEnvironmentVariable(EswDevOpsSdk.EnvironmentEnvVariable, defaultTestExecutionEnvironment);
            EswDevOpsSdk.GetEnvironmentName().Should().Be(defaultTestExecutionEnvironment);
        }

        var builder = new ContainerBuilder();

        builder.RegisterModule(new CoreModule(true));
        builder.RegisterModule(new VstsModule());
        builder.RegisterModule(new AzureManagementFluentModule());
        builder.Register(c => new SierraDbContext
        {
            ConnectionString = c.Resolve <IConfigurationRoot>()["SierraDbConnectionString"]
        });
        builder.Register(c => new HttpClient {
            Timeout = TimeSpan.FromSeconds(200)
        });

        builder.Register(c =>
        {
            var testConfig = new TestConfig();

            var config = EswDevOpsSdk.BuildConfiguration(true);
            config.GetSection("TestConfig").Bind(testConfig);

            TestMiddlewareUri = $"{testConfig.ApiUrl}test";
            TestRegion        = string.IsNullOrEmpty(testConfig.RegionName)
                ? Region.EuropeNorth
                : Region.Create(testConfig.RegionName);

            Environment = Enum.Parse <DeploymentEnvironment>(testConfig.Environment, true);

            DeploymentSubscriptionId = EswDevOpsSdk.SierraIntegrationSubscriptionId;

            return(testConfig);
        });

        Container = builder.Build();
        //trigger set up
        Container.Resolve <TestConfig>();
    }
Esempio n. 2
0
        /// <summary>
        /// Uses the desired default configurations.  Environment taken from EnvVariable "ENVIRONMENT" if not passed.
        /// Builds configuration sources in the following order:
        /// - 1. Environment variables
        /// - 2. Command line arguments
        /// - 3. Json file (appsettings.json, followed by appsettings.{env}.json)
        /// Note:
        /// - appsettings.{env}.json WILL override appsettings.json file settings.
        /// </summary>
        /// <param name="builder">The configuration builder to bind to.</param>
        /// <param name="appSettingsPath">The application settings path.</param>
        /// <param name="environment">Specify the environment - optional, as its loaded from the ENVIRONMENT env variable if not set here.</param>
        /// <returns>The configuration builder after config has been added.</returns>
        public static IConfigurationBuilder UseDefaultConfigs(this IConfigurationBuilder builder, string appSettingsPath = "appsettings.json", string environment = null)
        {
            builder.AddEnvironmentVariables()
            .AddCommandLine(Environment.GetCommandLineArgs())
            .AddJsonFile(appSettingsPath, true);

            var env = EswDevOpsSdk.GetEnvironmentName();

            if (!string.IsNullOrEmpty(environment))
            {
                env = environment;
            }

            if (!string.IsNullOrEmpty(env))
            {
                builder.AddJsonFile($"appsettings.{env}.json", true, true);
            }

            return(builder);
        }