public void SelectAzureProfileFromDisk() { var profile = new AzureRMProfile(); profile.Environments.Add("foo", AzureEnvironment.PublicEnvironments.Values.FirstOrDefault()); profile.Save("X:\\foo.json"); SelectAzureRMProfileCommand cmdlt = new SelectAzureRMProfileCommand(); // Setup cmdlt.Path = "X:\\foo.json"; cmdlt.CommandRuntime = commandRuntimeMock; // Act cmdlt.InvokeBeginProcessing(); cmdlt.ExecuteCmdlet(); cmdlt.InvokeEndProcessing(); // Verify Assert.True(AzureRmProfileProvider.Instance.Profile.Environments.ContainsKey("foo")); }
public void SavingProfileWorks() { string expected = @"{ ""Environments"": { ""testCloud"": { ""Name"": ""testCloud"", ""OnPremise"": false, ""Endpoints"": { ""ActiveDirectory"": ""http://contoso.com"" } } }, ""Context"": { ""Account"": { ""Id"": ""*****@*****.**"", ""Type"": 1, ""Properties"": { ""Tenants"": ""3c0ff8a7-e8bb-40e8-ae66-271343379af6"" } }, ""Subscription"": { ""Id"": ""00000000-0000-0000-0000-000000000000"", ""Name"": ""Contoso Test Subscription"", ""Environment"": ""testCloud"", ""Account"": ""*****@*****.**"", ""State"": ""Enabled"", ""Properties"": { ""Tenants"": ""3c0ff8a7-e8bb-40e8-ae66-271343379af6"" } }, ""Environment"": { ""Name"": ""testCloud"", ""OnPremise"": false, ""Endpoints"": { ""ActiveDirectory"": ""http://contoso.com"" } }, ""Tenant"": { ""Id"": ""3c0ff8a7-e8bb-40e8-ae66-271343379af6"", ""Domain"": ""contoso.com"" }, ""TokenCache"": ""AQIDBAUGCAkA"" } }"; var path = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, AzureSession.ProfileFile); var dataStore = new MockDataStore(); AzureSession.DataStore = dataStore; AzureRMProfile profile = new AzureRMProfile(path); var tenantId = new Guid("3c0ff8a7-e8bb-40e8-ae66-271343379af6"); var environment = new AzureEnvironment { Name = "testCloud", Endpoints = { { AzureEnvironment.Endpoint.ActiveDirectory, "http://contoso.com" } } }; var account = new AzureAccount { Id = "*****@*****.**", Type = AzureAccount.AccountType.User, Properties = { { AzureAccount.Property.Tenants, tenantId.ToString() } } }; var sub = new AzureSubscription { Account = account.Id, Environment = environment.Name, Id = new Guid(), Name = "Contoso Test Subscription", State = "Enabled", Properties = { { AzureSubscription.Property.Tenants, tenantId.ToString() } } }; var tenant = new AzureTenant { Id = tenantId, Domain = "contoso.com" }; profile.Context = new AzureContext(sub, account, environment, tenant); profile.Environments[environment.Name] = environment; profile.Context.TokenCache = new byte[] { 1, 2, 3, 4, 5, 6, 8, 9, 0 }; profile.Save(); string actual = dataStore.ReadFileAsText(path); Assert.Equal(expected, actual); }