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); }
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); }
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); ((RuntimeDefinedParameterDictionary)cmdlt.GetDynamicParameters())["TenantId"].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); }