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 SavingProfileWorks() { string expected = @"{ ""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 path = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, AzureSession.Instance.ProfileFile); var dataStore = new MockDataStore(); AzureSession.Instance.DataStore = dataStore; AzureRmProfile profile = new AzureRmProfile(path); var tenantId = new Guid("3c0ff8a7-e8bb-40e8-ae66-271343379af6"); var environment = new AzureEnvironment { Name = "testCloud", ActiveDirectoryAuthority = "http://contoso.com" }; var account = new AzureAccount { Id = "*****@*****.**", Type = AzureAccount.AccountType.User, }; account.SetTenants(tenantId.ToString()); var sub = new AzureSubscription { Id = new Guid().ToString(), Name = "Contoso Test Subscription", State = "Enabled", }; sub.SetAccount(account.Id); sub.SetEnvironment(environment.Name); sub.SetTenant(tenantId.ToString()); var tenant = new AzureTenant { Id = tenantId.ToString(), Directory = "contoso.com" }; profile.DefaultContext = new AzureContext(sub, account, environment, tenant); profile.EnvironmentTable[environment.Name] = environment; profile.DefaultContext.TokenCache = new AuthenticationStoreTokenCache(new AzureTokenCache { CacheData = new byte[] { 1, 2, 3, 4, 5, 6, 8, 9, 0 } }); profile.Save(); string actual = dataStore.ReadFileAsText(path); Assert.Equal(expected, actual); }