protected override void Load(ContainerBuilder builder)
        {
            builder.Register(c =>
            {
                var tokenProvider        = new AzureServiceTokenProvider();
                var tokenProviderAdapter = new AzureServiceTokenProviderAdapter(tokenProvider);
                return(new TokenCredentials(tokenProviderAdapter));
            });

            builder.Register(c =>
            {
                var tokenCredentials = c.Resolve <TokenCredentials>();

                var client = RestClient.Configure()
                             .WithEnvironment(AzureEnvironment.AzureGlobalCloud)
                             .WithLogLevel(HttpLoggingDelegatingHandler.Level.Basic)
                             .WithCredentials(new AzureCredentials(tokenCredentials, tokenCredentials, string.Empty,
                                                                   AzureEnvironment.AzureGlobalCloud))
                             .Build();

                return(Azure.Authenticate(client, string.Empty));
            });

            foreach (DeploymentEnvironment env in Enum.GetValues(typeof(DeploymentEnvironment)))
            {
                var subscriptionId = EswDevOpsSdk.GetSierraDeploymentSubscriptionId(env);
                builder.Register(c =>
                {
                    var authenticated = c.Resolve <Azure.IAuthenticated>();
                    return(authenticated.WithSubscription(subscriptionId));
                }).Keyed <IAzure>(env).InstancePerLifetimeScope();
            }
        }
Esempio n. 2
0
    public void GetDeploymentSubscriptionIdTest(DeploymentEnvironment environmentName, DeploymentEnvironment deploymentEnvironmentName, object resultEnvironmentSubscription)
    {
        Environment.SetEnvironmentVariable(EswDevOpsSdk.EnvironmentEnvVariable, environmentName.ToString(), EnvironmentVariableTarget.Process);
        var expectedSubscriptionId = resultEnvironmentSubscription as string == SierraIntegration
            ? EswDevOpsSdk.SierraIntegrationSubscriptionId
            : EswDevOpsSdk.GetSubscriptionId(deploymentEnvironmentName);

        var subscriptionId = EswDevOpsSdk.GetSierraDeploymentSubscriptionId(deploymentEnvironmentName);

        subscriptionId.Should().Be(expectedSubscriptionId);
    }