예제 #1
0
        public void SelectAzureContextWithNoSubscriptionAndTenant()
        {
            var cmdlt       = new SetAzureRMContextCommand();
            var tenantToSet = "72f988bf-86f1-41af-91ab-2d7cd011db47";

            // Setup
            cmdlt.CommandRuntime = commandRuntimeMock;

            // Make sure that the tenant ID we are attempting to set is
            // valid for the account
            var account         = AzureRmProfileProvider.Instance.Profile.DefaultContext.Account;
            var existingTenants = account.GetProperty(AzureAccount.Property.Tenants);
            var allowedTenants  = existingTenants == null ? tenantToSet : existingTenants + "," + tenantToSet;

            account.SetProperty(AzureAccount.Property.Tenants, allowedTenants);
            account.SetProperty(AzureAccount.Property.Subscriptions, new string[0]);

            cmdlt.Tenant = tenantToSet;

            // Act
            cmdlt.InvokeBeginProcessing();
            cmdlt.ExecuteCmdlet();
            cmdlt.InvokeEndProcessing();

            // Verify
            Assert.True(commandRuntimeMock.OutputPipeline.Count == 1);
            var context = (PSAzureContext)commandRuntimeMock.OutputPipeline[0];

            // TenantId is not sufficient to change the context.
            Assert.NotEqual(tenantToSet, context.Tenant.Id);
        }
예제 #2
0
        public void SelectAzureContextWithNoSubscriptionAndNoTenant()
        {
            var cmdlt = new SetAzureRMContextCommand();

            // Setup
            cmdlt.CommandRuntime = commandRuntimeMock;

            // Act
            cmdlt.InvokeBeginProcessing();
            cmdlt.ExecuteCmdlet();
            cmdlt.InvokeEndProcessing();

            // Verify
            Assert.True(commandRuntimeMock.OutputPipeline.Count == 1);
            var context = (PSAzureContext)commandRuntimeMock.OutputPipeline[0];

            Assert.NotNull(context);
        }
예제 #3
0
        public void SelectAzureContextWithNoSubscriptionAndTenant()
        {
            var cmdlt = new SetAzureRMContextCommand();

            // Setup
            cmdlt.CommandRuntime = commandRuntimeMock;
            cmdlt.TenantId       = "72f988bf-86f1-41af-91ab-2d7cd011db47";

            // Act
            cmdlt.InvokeBeginProcessing();
            cmdlt.ExecuteCmdlet();
            cmdlt.InvokeEndProcessing();

            // Verify
            Assert.True(commandRuntimeMock.OutputPipeline.Count == 1);
            var context = (PSAzureContext)commandRuntimeMock.OutputPipeline[0];

            Assert.Equal("72f988bf-86f1-41af-91ab-2d7cd011db47", context.Tenant.TenantId);
        }
예제 #4
0
        public void SelectAzureContextWithNoSubscriptionAndTenant()
        {
            var cmdlt       = new SetAzureRMContextCommand();
            var tenantToSet = "72f988bf-86f1-41af-91ab-2d7cd011db47";

            // Setup
            cmdlt.CommandRuntime = commandRuntimeMock;

            // Make sure that the tenant ID we are attempting to set is
            // valid for the account
            var account         = AzureRmProfileProvider.Instance.Profile.Context.Account;
            var existingTenants = account.GetProperty(AzureAccount.Property.Tenants);
            var allowedTenants  = existingTenants == null ? tenantToSet : existingTenants + "," + tenantToSet;

            account.SetProperty(AzureAccount.Property.Tenants, allowedTenants);
            account.SetProperty(AzureAccount.Property.Subscriptions, new string[0]);

            var paramDictionary =
                ((RuntimeDefinedParameterDictionary)cmdlt.GetDynamicParameters());
            var tenantParam = paramDictionary["TenantId"];

            Assert.True(tenantParam.Attributes.Any(a => a is ValidateSetAttribute &&
                                                   ((ValidateSetAttribute)a).ValidValues.Any(v => string.Equals(v, tenantToSet, StringComparison.OrdinalIgnoreCase))));
            Assert.False(paramDictionary["SubscriptionId"].Attributes.Any(a => a is ValidateSetAttribute));
            tenantParam.Value = tenantToSet;

            // Act
            cmdlt.InvokeBeginProcessing();
            cmdlt.ExecuteCmdlet();
            cmdlt.InvokeEndProcessing();

            // Verify
            Assert.True(commandRuntimeMock.OutputPipeline.Count == 1);
            var context = (PSAzureContext)commandRuntimeMock.OutputPipeline[0];

            // TenantId is not sufficient to change the context.
            Assert.NotEqual(tenantToSet, context.Tenant.TenantId);
        }
예제 #5
0
        public void SetsDynamicParametersForContext(string[] subscriptions, string[] tenants)
        {
            var cmdlt = new SetAzureRMContextCommand();

            // Setup
            cmdlt.CommandRuntime = commandRuntimeMock;

            // Make sure that the tenant ID we are attempting to set is
            // valid for the account
            var account = AzureRmProfileProvider.Instance.Profile.Context.Account;

            account.SetProperty(AzureAccount.Property.Tenants, tenants);
            account.SetProperty(AzureAccount.Property.Subscriptions, subscriptions);

            var paramDictionary =
                ((RuntimeDefinedParameterDictionary)cmdlt.GetDynamicParameters());
            var subscriptionParams = paramDictionary["SubscriptionId"];

            VerifyValidationAttribute(subscriptionParams, subscriptions);
            var tenantParams = paramDictionary["TenantId"];

            VerifyValidationAttribute(tenantParams, tenants);
        }