当前位置: 首页>>代码示例>>C#>>正文


C# ProfileClient.AddOrSetEnvironment方法代码示例

本文整理汇总了C#中ProfileClient.AddOrSetEnvironment方法的典型用法代码示例。如果您正苦于以下问题:C# ProfileClient.AddOrSetEnvironment方法的具体用法?C# ProfileClient.AddOrSetEnvironment怎么用?C# ProfileClient.AddOrSetEnvironment使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在ProfileClient的用法示例。


在下文中一共展示了ProfileClient.AddOrSetEnvironment方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: RemovesAzureEnvironment

        public void RemovesAzureEnvironment()
        {
            var commandRuntimeMock = new Mock<ICommandRuntime>();
            commandRuntimeMock.Setup(f => f.ShouldProcess(It.IsAny<string>(), It.IsAny<string>())).Returns(true);

            const string name = "test";
            ProfileClient client = new ProfileClient();
            client.AddOrSetEnvironment(new AzureEnvironment
            {
                Name = name
            });
            client.Profile.Save();

            var cmdlet = new RemoveAzureEnvironmentCommand()
            {
                CommandRuntime = commandRuntimeMock.Object,
                Force = true,
                Name = name
            };

            cmdlet.InvokeBeginProcessing();
            cmdlet.ExecuteCmdlet();
            cmdlet.InvokeEndProcessing();

            client = new ProfileClient();
            Assert.False(client.Profile.Environments.ContainsKey(name));
        }
开发者ID:randorfer,项目名称:azure-powershell,代码行数:27,代码来源:RemoveAzureEnvironmentTests.cs

示例2: SetAzureSubscriptionDerivesEnvironmentFromEnvironmentParameterOnAdd

        public void SetAzureSubscriptionDerivesEnvironmentFromEnvironmentParameterOnAdd()
        {
            SetAzureSubscriptionCommand cmdlt = new SetAzureSubscriptionCommand();
            // Setup
            ProfileClient client = new ProfileClient();
            client.AddOrSetEnvironment(azureEnvironment);
            client.Profile.Save();

            cmdlt.CommandRuntime = commandRuntimeMock.Object;
            cmdlt.SubscriptionId = Guid.NewGuid().ToString();
            cmdlt.SubscriptionName = "NewSubscriptionName";
            cmdlt.CurrentStorageAccountName = "NewCloudStorage";
            cmdlt.Environment = azureEnvironment.Name;
            cmdlt.Certificate = SampleCertificate;

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

            // Verify
            client = new ProfileClient();
            var newSubscription = client.Profile.Subscriptions[new Guid(cmdlt.SubscriptionId)];
            Assert.Equal(cmdlt.SubscriptionName, newSubscription.Name);
            Assert.Equal(cmdlt.Environment, newSubscription.Environment);
            Assert.Equal(cmdlt.CurrentStorageAccountName, newSubscription.GetProperty(AzureSubscription.Property.StorageAccount));
        }
开发者ID:jeffwilcox,项目名称:azure-sdk-tools,代码行数:27,代码来源:ProfileCmdltsTests.cs

示例3: ClearAzureProfileClearsDefaultProfile

        public void ClearAzureProfileClearsDefaultProfile()
        {
            ClearAzureProfileCommand cmdlt = new ClearAzureProfileCommand();
            // Setup
            var profile = new AzureProfile(Path.Combine(AzureSession.ProfileDirectory, AzureSession.ProfileFile));
            AzurePSCmdlet.CurrentProfile = profile;
            ProfileClient client = new ProfileClient(profile);
            client.AddOrSetAccount(azureAccount);
            client.AddOrSetEnvironment(azureEnvironment);
            client.AddOrSetSubscription(azureSubscription1);
            client.Profile.Save();

            cmdlt.CommandRuntime = commandRuntimeMock;
            cmdlt.Force = new SwitchParameter(true);

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

            // Verify
            client = new ProfileClient(new AzureProfile(Path.Combine(AzureSession.ProfileDirectory, AzureSession.ProfileFile)));
            Assert.Equal(0, client.Profile.Subscriptions.Count);
            Assert.Equal(0, client.Profile.Accounts.Count);
            Assert.Equal(2, client.Profile.Environments.Count); //only default environments
        }
开发者ID:pelagos,项目名称:azure-powershell,代码行数:26,代码来源:ProfileCmdltsTests.cs

示例4: SetsAzureEnvironment

        // TODO: fix flaky test
        //[Trait(Category.AcceptanceType, Category.CheckIn)]
        public void SetsAzureEnvironment()
        {
            Mock<ICommandRuntime> commandRuntimeMock = new Mock<ICommandRuntime>();
            string name = "Katal";
            ProfileClient client = new ProfileClient(new AzureSMProfile(Path.Combine(AzureSession.ProfileDirectory, AzureSession.ProfileFile)));
            client.AddOrSetEnvironment(new AzureEnvironment { Name = name });

            SetAzureEnvironmentCommand cmdlet = new SetAzureEnvironmentCommand()
            {
                CommandRuntime = commandRuntimeMock.Object,
                Name = "KATaL",
                PublishSettingsFileUrl = "http://microsoft.com",
                ServiceEndpoint = "endpoint.net",
                ManagementPortalUrl = "management portal url",
                StorageEndpoint = "endpoint.net",
                GalleryEndpoint = "galleryendpoint"
            };

            cmdlet.InvokeBeginProcessing();
            cmdlet.ExecuteCmdlet();
            cmdlet.InvokeEndProcessing();

            commandRuntimeMock.Verify(f => f.WriteObject(It.IsAny<PSAzureEnvironment>()), Times.Once());
            client = new ProfileClient(new AzureSMProfile(Path.Combine(AzureSession.ProfileDirectory, AzureSession.ProfileFile)));
            AzureEnvironment env = client.Profile.Environments["KaTaL"];
            Assert.Equal(env.Name.ToLower(), cmdlet.Name.ToLower());
            Assert.Equal(env.Endpoints[AzureEnvironment.Endpoint.PublishSettingsFileUrl], cmdlet.PublishSettingsFileUrl);
            Assert.Equal(env.Endpoints[AzureEnvironment.Endpoint.ServiceManagement], cmdlet.ServiceEndpoint);
            Assert.Equal(env.Endpoints[AzureEnvironment.Endpoint.ManagementPortalUrl], cmdlet.ManagementPortalUrl);
            Assert.Equal(env.Endpoints[AzureEnvironment.Endpoint.Gallery], "galleryendpoint");
        }
开发者ID:docschmidt,项目名称:azure-powershell,代码行数:33,代码来源:SetAzureEnvironmentTests.cs

示例5: SetAzureSubscriptionDerivesEnvironmentFromBothEndpointParameters

        public void SetAzureSubscriptionDerivesEnvironmentFromBothEndpointParameters()
        {
            SetAzureSubscriptionCommand cmdlt = new SetAzureSubscriptionCommand();
            // Setup
            ProfileClient client = new ProfileClient();
            client.AddOrSetAccount(azureAccount);
            client.AddOrSetEnvironment(azureEnvironment);
            client.AddOrSetSubscription(azureSubscription1);
            client.Profile.Save();

            cmdlt.CommandRuntime = commandRuntimeMock.Object;
            cmdlt.SubscriptionId = azureSubscription1.Id.ToString();
            cmdlt.CurrentStorageAccountName = "NewCloudStorage";
            cmdlt.ServiceEndpoint = azureEnvironment.GetEndpoint(AzureEnvironment.Endpoint.ServiceManagement);
            cmdlt.ResourceManagerEndpoint = azureEnvironment.GetEndpoint(AzureEnvironment.Endpoint.ResourceManager);

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

            // Verify
            client = new ProfileClient();
            var newSubscription = client.Profile.Subscriptions[new Guid(cmdlt.SubscriptionId)];
            Assert.Equal(cmdlt.Environment, newSubscription.Environment);
            Assert.Equal(cmdlt.CurrentStorageAccountName, newSubscription.GetProperty(AzureSubscription.Property.StorageAccount));
        }
开发者ID:djrosanova,项目名称:azure-sdk-tools,代码行数:27,代码来源:ProfileCmdltsTests.cs

示例6: ImportPublishSettingsAddsSecondCertificate

        public void ImportPublishSettingsAddsSecondCertificate()
        {
            MockDataStore dataStore = new MockDataStore();
            ProfileClient.DataStore = dataStore;
            ProfileClient client = new ProfileClient();
            var newSubscription = new AzureSubscription
            {
                Id = new Guid("f62b1e05-af8f-4203-8f97-421089adc053"),
                Name = "Microsoft Azure Sandbox 9-220",
                Environment = EnvironmentName.AzureCloud,
                Account = azureAccount.Id
            };
            azureAccount.SetProperty(AzureAccount.Property.Subscriptions, newSubscription.Id.ToString());
            client.AddOrSetAccount(azureAccount);
            client.AddOrSetSubscription(newSubscription);
            client.Profile.Save();

            client = new ProfileClient();

            dataStore.WriteFile("ImportPublishSettingsLoadsAndReturnsSubscriptions.publishsettings",
                Properties.Resources.ValidProfile);

            client.AddOrSetEnvironment(azureEnvironment);
            var subscriptions = client.ImportPublishSettings("ImportPublishSettingsLoadsAndReturnsSubscriptions.publishsettings", azureEnvironment.Name);

            Assert.Equal(2, client.Profile.Accounts.Count());
            var certAccount = client.Profile.Accounts.Values.First(a => a.Type == AzureAccount.AccountType.Certificate);
            var userAccount = client.Profile.Accounts.Values.First(a => a.Type == AzureAccount.AccountType.User);

            Assert.True(subscriptions.All(s => s.Account == certAccount.Id));
            Assert.Equal(azureAccount.Id, client.Profile.Subscriptions.Values.First(s => s.Id == newSubscription.Id).Account);

            Assert.True(userAccount.GetPropertyAsArray(AzureAccount.Property.Subscriptions).Contains(newSubscription.Id.ToString()));
            Assert.True(certAccount.GetPropertyAsArray(AzureAccount.Property.Subscriptions).Contains(newSubscription.Id.ToString()));

            Assert.Equal(6, subscriptions.Count);
            Assert.Equal(6, client.Profile.Subscriptions.Count);
        }
开发者ID:djrosanova,项目名称:azure-sdk-tools,代码行数:38,代码来源:ProfileClientTests.cs

示例7: ImportPublishSettingsUsesProperEnvironmentWithChinaManagementUrlOld

        public void ImportPublishSettingsUsesProperEnvironmentWithChinaManagementUrlOld()
        {
            MockDataStore dataStore = new MockDataStore();
            ProfileClient.DataStore = dataStore;
            ProfileClient client = new ProfileClient();

            dataStore.WriteFile("ImportPublishSettingsLoadsAndReturnsSubscriptions.publishsettings",
                Properties.Resources.ValidProfileChinaOld);

            client.AddOrSetEnvironment(azureEnvironment);
            var subscriptions = client.ImportPublishSettings("ImportPublishSettingsLoadsAndReturnsSubscriptions.publishsettings", null);

            Assert.True(subscriptions.All(s => s.Environment == EnvironmentName.AzureChinaCloud));
            Assert.Equal(1, subscriptions.Count);
            Assert.Equal(1, client.Profile.Subscriptions.Count);
        }
开发者ID:djrosanova,项目名称:azure-sdk-tools,代码行数:16,代码来源:ProfileClientTests.cs

示例8: ImportPublishSettingsLoadsAndReturnsSubscriptions

        public void ImportPublishSettingsLoadsAndReturnsSubscriptions()
        {
            MockDataStore dataStore = new MockDataStore();
            ProfileClient.DataStore = dataStore;
            ProfileClient client = new ProfileClient();

            dataStore.WriteFile("ImportPublishSettingsLoadsAndReturnsSubscriptions.publishsettings",
                Properties.Resources.ValidProfile);

            client.AddOrSetEnvironment(azureEnvironment);
            var subscriptions = client.ImportPublishSettings("ImportPublishSettingsLoadsAndReturnsSubscriptions.publishsettings", azureEnvironment.Name);
            var account = client.Profile.Accounts.Values.First();

            Assert.True(subscriptions.All(s => s.Account == account.Id));
            Assert.Equal(6, subscriptions.Count);
            Assert.Equal(6, client.Profile.Subscriptions.Count);
        }
开发者ID:djrosanova,项目名称:azure-sdk-tools,代码行数:17,代码来源:ProfileClientTests.cs

示例9: ClearDefaultAzureSubscriptionClearsDefault

        public void ClearDefaultAzureSubscriptionClearsDefault()
        {
            MockDataStore dataStore = new MockDataStore();
            ProfileClient.DataStore = dataStore;
            ProfileClient client = new ProfileClient();
            client.Profile.Accounts[azureAccount.Id] = azureAccount;
            client.AddOrSetEnvironment(azureEnvironment);
            client.AddOrSetSubscription(azureSubscription2);

            Assert.Null(client.Profile.DefaultSubscription);
            client.SetSubscriptionAsDefault(azureSubscription2.Name, azureSubscription2.Account);
            Assert.Equal(azureSubscription2.Id, client.Profile.DefaultSubscription.Id);

            client.ClearDefaultSubscription();

            Assert.Null(client.Profile.DefaultSubscription);
        }
开发者ID:djrosanova,项目名称:azure-sdk-tools,代码行数:17,代码来源:ProfileClientTests.cs

示例10: RefreshSubscriptionsListsAllSubscriptions

        public void RefreshSubscriptionsListsAllSubscriptions()
        {
            SetMocks(new[] { rdfeSubscription1, rdfeSubscription2 }.ToList(), new[] { csmSubscription1, csmSubscription1withDuplicateId }.ToList());
            MockDataStore dataStore = new MockDataStore();
            ProfileClient.DataStore = dataStore;
            ProfileClient client = new ProfileClient();
            client.AddOrSetAccount(azureAccount);
            client.AddOrSetEnvironment(azureEnvironment);
            client.AddOrSetSubscription(azureSubscription1);
            PowerShellUtilities.GetCurrentModeOverride = () => AzureModule.AzureServiceManagement;

            var subscriptions = client.RefreshSubscriptions(azureEnvironment);

            Assert.Equal(4, subscriptions.Count);
            Assert.Equal(1, subscriptions.Count(s => s.Id == new Guid(rdfeSubscription1.SubscriptionId)));
            Assert.Equal(1, subscriptions.Count(s => s.Id == new Guid(rdfeSubscription2.SubscriptionId)));
            Assert.Equal(1, subscriptions.Count(s => s.Id == new Guid(csmSubscription1.SubscriptionId)));
            Assert.True(subscriptions.All(s => s.Environment == "Test"));
            Assert.True(subscriptions.All(s => s.Account == "test"));
        }
开发者ID:djrosanova,项目名称:azure-sdk-tools,代码行数:20,代码来源:ProfileClientTests.cs

示例11: SetAzureSubscriptionDerivesEnvironmentFromResourcesEndpointParameterOnSet

        public void SetAzureSubscriptionDerivesEnvironmentFromResourcesEndpointParameterOnSet()
        {
            // Setup
            var profile = new AzureProfile(Path.Combine(AzureSession.ProfileDirectory, AzureSession.ProfileFile));
            ProfileClient client = new ProfileClient(profile);
            AzurePSCmdlet.CurrentProfile = profile;
            client.AddOrSetAccount(azureAccount);
            client.AddOrSetEnvironment(azureEnvironment);
            client.AddOrSetSubscription(azureSubscription1);
            client.Profile.Save();
            SetAzureSubscriptionCommand cmdlt = new SetAzureSubscriptionCommand();

            cmdlt.CommandRuntime = commandRuntimeMock;
            cmdlt.SubscriptionId = azureSubscription1.Id.ToString();
            cmdlt.CurrentStorageAccountName = "NewCloudStorage";
            cmdlt.ResourceManagerEndpoint = azureEnvironment.GetEndpoint(AzureEnvironment.Endpoint.ResourceManager);

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

            // Verify
            client = new ProfileClient(profile);
            var newSubscription = client.Profile.Subscriptions[new Guid(cmdlt.SubscriptionId)];
            Assert.Equal(cmdlt.Environment, newSubscription.Environment);
            Assert.Equal(cmdlt.CurrentStorageAccountName, newSubscription.GetProperty(AzureSubscription.Property.StorageAccount));
        }
开发者ID:pelagos,项目名称:azure-powershell,代码行数:28,代码来源:ProfileCmdltsTests.cs

示例12: SetupCustomProfile

 private AzureProfile SetupCustomProfile(string path)
 {
     var profile =
         new AzureProfile(path);
     ProfileClient client = new ProfileClient(profile);
     client.AddOrSetEnvironment(azureEnvironment);
     client.AddOrSetAccount(azureAccount);
     client.AddOrSetSubscription(azureSubscription1);
     client.AddOrSetSubscription(azureSubscription2);
     profile.Save(path);
     return profile;
 }
开发者ID:pelagos,项目名称:azure-powershell,代码行数:12,代码来源:ProfileCmdltsTests.cs

示例13: SetupDefaultProfile

 private ProfileClient SetupDefaultProfile()
 {
     var profile = new AzureProfile(Path.Combine(AzureSession.ProfileDirectory, AzureSession.ProfileFile));
     AzurePSCmdlet.CurrentProfile = profile;
     ProfileClient client = new ProfileClient(profile);
     client.AddOrSetEnvironment(azureEnvironment);
     client.AddOrSetAccount(azureAccount);
     client.AddOrSetSubscription(azureSubscription1);
     client.AddOrSetSubscription(azureSubscription2);
     client.Profile.Save();
     return client;
 }
开发者ID:pelagos,项目名称:azure-powershell,代码行数:12,代码来源:ProfileCmdltsTests.cs

示例14: AddOrSetAzureSubscriptionChecksAndUpdates

        public void AddOrSetAzureSubscriptionChecksAndUpdates()
        {
            MemoryDataStore dataStore = new MemoryDataStore();
            AzureSession.DataStore = dataStore;
            currentProfile = new AzureSMProfile(Path.Combine(AzureSession.ProfileDirectory, AzureSession.ProfileFile));
            ProfileClient client = new ProfileClient(currentProfile);

            client.AddOrSetAccount(azureAccount);
            client.AddOrSetEnvironment(azureEnvironment);
            client.AddOrSetSubscription(azureSubscription1);

            Assert.Equal(1, client.Profile.Subscriptions.Count);

            var subscription = client.AddOrSetSubscription(azureSubscription1);

            Assert.Equal(1, client.Profile.Subscriptions.Count);
            Assert.Equal(1, client.Profile.Accounts.Count);
            Assert.Equal(subscription, azureSubscription1);
            Assert.Throws<ArgumentNullException>(() => client.AddOrSetSubscription(null));
            Assert.Throws<ArgumentNullException>(() => client.AddOrSetSubscription(
                new AzureSubscription { Id = new Guid(), Environment = null, Name = "foo" }));
        }
开发者ID:Azure,项目名称:azure-powershell,代码行数:22,代码来源:ProfileClientTests.cs

示例15: GetCurrentEnvironmentReturnsCorrectValue

        public void GetCurrentEnvironmentReturnsCorrectValue()
        {
            MemoryDataStore dataStore = new MemoryDataStore();
            AzureSession.DataStore = dataStore;
            ProfileClient client = new ProfileClient(currentProfile);

            client.AddOrSetEnvironment(azureEnvironment);
            client.AddOrSetAccount(azureAccount);
            client.AddOrSetSubscription(azureSubscription1);

            currentProfile.DefaultSubscription = azureSubscription1;

            var newEnv = client.GetEnvironmentOrDefault(azureEnvironment.Name);

            Assert.Equal(azureEnvironment.Name, newEnv.Name);
        }
开发者ID:Azure,项目名称:azure-powershell,代码行数:16,代码来源:ProfileClientTests.cs


注:本文中的ProfileClient.AddOrSetEnvironment方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。