public void SelectAzureProfileBadPath() { #pragma warning disable CS0618 // Suppress obsolescence warning: cmdlet name is changing ImportAzureRMContextCommand cmdlt = new ImportAzureRMContextCommand(); #pragma warning restore CS0618 // Suppress obsolescence warning: cmdlet name is changing cmdlt.Path = "z:\non-existent-path\non-existent-file.ext"; // Setup cmdlt.CommandRuntime = commandRuntimeMock; cmdlt.MyInvocation.BoundParameters.Add("Path", cmdlt.Path); // Act cmdlt.InvokeBeginProcessing(); Assert.Throws <PSArgumentException>(() => cmdlt.ExecuteCmdlet()); }
public void SelectAzureProfileInMemory() { var profile = new AzureRMProfile(); profile.Environments.Add("foo", AzureEnvironment.PublicEnvironments.Values.FirstOrDefault()); #pragma warning disable CS0618 // Suppress obsolescence warning: cmdlet name is changing ImportAzureRMContextCommand cmdlt = new ImportAzureRMContextCommand(); #pragma warning restore CS0618 // Suppress obsolescence warning: cmdlet name is changing // Setup cmdlt.AzureContext = profile; cmdlt.CommandRuntime = commandRuntimeMock; // Act cmdlt.InvokeBeginProcessing(); cmdlt.ExecuteCmdlet(); cmdlt.InvokeEndProcessing(); // Verify Assert.True(AzureRmProfileProvider.Instance.Profile.Environments.ContainsKey("foo")); }
public void SelectAzureProfileFromDisk() { var profile = new AzureRMProfile(); profile.Environments.Add("foo", AzureEnvironment.PublicEnvironments.Values.FirstOrDefault()); profile.Save("X:\\foo.json"); #pragma warning disable CS0618 // Suppress obsolescence warning: cmdlet name is changing ImportAzureRMContextCommand cmdlt = new ImportAzureRMContextCommand(); #pragma warning restore CS0618 // Suppress obsolescence warning: cmdlet name is changing // Setup cmdlt.Path = "X:\\foo.json"; cmdlt.CommandRuntime = commandRuntimeMock; cmdlt.MyInvocation.BoundParameters.Add("Path", cmdlt.Path); // Act cmdlt.InvokeBeginProcessing(); cmdlt.ExecuteCmdlet(); cmdlt.InvokeEndProcessing(); // Verify Assert.True(AzureRmProfileProvider.Instance.Profile.Environments.ContainsKey("foo")); }
public void SelectAzureProfileFromDisk() { var profile = new AzureRmProfile(); profile.EnvironmentTable.Add("foo", new AzureEnvironment(new AzureEnvironment(AzureEnvironment.PublicEnvironments.Values.FirstOrDefault()))); profile.EnvironmentTable["foo"].Name = "foo"; profile.Save("X:\\foo.json"); ImportAzureRMContextCommand cmdlt = new ImportAzureRMContextCommand(); // Setup cmdlt.Path = "X:\\foo.json"; cmdlt.CommandRuntime = commandRuntimeMock; cmdlt.MyInvocation.BoundParameters.Add("Path", cmdlt.Path); // Act cmdlt.InvokeBeginProcessing(); cmdlt.ExecuteCmdlet(); cmdlt.InvokeEndProcessing(); // Verify Assert.Contains(AzureRmProfileProvider.Instance.Profile.Environments, (e) => string.Equals(e.Name, "foo")); }
public void SelectAzureProfileInMemory() { var profile = new AzureRmProfile { DefaultContext = new AzureContext() }; profile.EnvironmentTable.Add("foo", new AzureEnvironment(AzureEnvironment.PublicEnvironments.Values.FirstOrDefault())); ImportAzureRMContextCommand cmdlt = new ImportAzureRMContextCommand(); // Setup cmdlt.AzureContext = profile; cmdlt.CommandRuntime = commandRuntimeMock; // Act cmdlt.InvokeBeginProcessing(); cmdlt.ExecuteCmdlet(); cmdlt.InvokeEndProcessing(); // Verify Assert.True(AzureRmProfileProvider.Instance.GetProfile <AzureRmProfile>().EnvironmentTable.ContainsKey("foo")); }
public void ImportContextNoDefaultKey() { var serializedContext = @"{ ""EnvironmentTable"": { ""testCloud"": { ""Name"": ""testCloud"", ""OnPremise"": false, ""ServiceManagementUrl"": null, ""ResourceManagerUrl"": null, ""ManagementPortalUrl"": null, ""PublishSettingsFileUrl"": null, ""ActiveDirectoryAuthority"": ""http://contoso.com"", ""GalleryUrl"": null, ""GraphUrl"": null, ""ActiveDirectoryServiceEndpointResourceId"": null, ""StorageEndpointSuffix"": null, ""SqlDatabaseDnsSuffix"": null, ""TrafficManagerDnsSuffix"": null, ""AzureKeyVaultDnsSuffix"": null, ""AzureKeyVaultServiceEndpointResourceId"": null, ""GraphEndpointResourceId"": null, ""DataLakeEndpointResourceId"": null, ""AzureDataLakeAnalyticsCatalogAndJobEndpointSuffix"": null, ""AzureDataLakeStoreFileSystemEndpointSuffix"": null, ""AdTenant"": null, ""VersionProfiles"": [], ""ExtendedProperties"": {} } }, ""Contexts"": { ""Default"": { ""Account"": { ""Id"": ""*****@*****.**"", ""Credential"": null, ""Type"": ""User"", ""TenantMap"": {}, ""ExtendedProperties"": { ""Tenants"": ""3c0ff8a7-e8bb-40e8-ae66-271343379af6"" } }, ""Tenant"": { ""Id"": ""3c0ff8a7-e8bb-40e8-ae66-271343379af6"", ""Directory"": ""contoso.com"", ""ExtendedProperties"": {} }, ""Subscription"": { ""Id"": ""00000000-0000-0000-0000-000000000000"", ""Name"": ""Contoso Test Subscription"", ""State"": ""Enabled"", ""ExtendedProperties"": { ""Account"": ""*****@*****.**"", ""Tenants"": ""3c0ff8a7-e8bb-40e8-ae66-271343379af6"", ""Environment"": ""testCloud"" } }, ""Environment"": { ""Name"": ""testCloud"", ""OnPremise"": false, ""ServiceManagementUrl"": null, ""ResourceManagerUrl"": null, ""ManagementPortalUrl"": null, ""PublishSettingsFileUrl"": null, ""ActiveDirectoryAuthority"": ""http://contoso.com"", ""GalleryUrl"": null, ""GraphUrl"": null, ""ActiveDirectoryServiceEndpointResourceId"": null, ""StorageEndpointSuffix"": null, ""SqlDatabaseDnsSuffix"": null, ""TrafficManagerDnsSuffix"": null, ""AzureKeyVaultDnsSuffix"": null, ""AzureKeyVaultServiceEndpointResourceId"": null, ""GraphEndpointResourceId"": null, ""DataLakeEndpointResourceId"": null, ""AzureDataLakeAnalyticsCatalogAndJobEndpointSuffix"": null, ""AzureDataLakeStoreFileSystemEndpointSuffix"": null, ""AdTenant"": null, ""VersionProfiles"": [], ""ExtendedProperties"": {} }, ""VersionProfile"": null, ""TokenCache"": { ""CacheData"": ""AgAAAAAAAAA="" }, ""ExtendedProperties"": {} } }, ""ExtendedProperties"": {} }"; var oldDataStore = AzureSession.Instance.DataStore; var store = new MemoryDataStore(); var filePath = "c:\\myfile.json"; store.VirtualStore[filePath] = serializedContext; try { AzureSession.Instance.DataStore = store; var cmdlet = new ImportAzureRMContextCommand(); cmdlet.CommandRuntime = commandRuntimeMock; cmdlet.Path = filePath; cmdlet.DefaultProfile = new AzureRmProfile(); cmdlet.MyInvocation.BoundParameters.Add("Path", filePath); cmdlet.InvokeBeginProcessing(); cmdlet.ExecuteCmdlet(); cmdlet.InvokeEndProcessing(); var profile = cmdlet.DefaultProfile as AzureRmProfile; Assert.NotNull(profile); Assert.NotNull(profile.DefaultContextKey); var context = profile.DefaultContext; Assert.NotNull(context); var account = context.Account; Assert.NotNull(account); Assert.Equal("*****@*****.**", account.Id); Assert.Equal("User", account.Type); Assert.Contains("3c0ff8a7-e8bb-40e8-ae66-271343379af6", account.GetTenants()); Assert.NotNull(context.Tenant); Assert.Equal("3c0ff8a7-e8bb-40e8-ae66-271343379af6", context.Tenant.Id); var subscription = context.Subscription; Assert.NotNull(subscription); Assert.Equal("Contoso Test Subscription", subscription.Name); Assert.Equal(Guid.Empty.ToString(), subscription.Id); Assert.NotNull(context.Environment); Assert.Equal("testCloud", context.Environment.Name); Assert.Equal(5, profile.EnvironmentTable.Count); } finally { AzureSession.Instance.DataStore = oldDataStore; } }