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


C# ProfileClient.AddOrSetAccount方法代码示例

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


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

示例1: 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

示例2: CreateAzureSMProfile

 public static AzureSMProfile CreateAzureSMProfile(string storageAccount)
 {
     var profile = new AzureSMProfile();
     var client = new ProfileClient(profile);
     var tenantId = Guid.NewGuid();
     var subscriptionId = Guid.NewGuid();
     var account = new AzureAccount
     {
         Id = "[email protected]",
         Type = AzureAccount.AccountType.User
     };
     account.SetProperty(AzureAccount.Property.Tenants, tenantId.ToString());
     account.SetProperty(AzureAccount.Property.Subscriptions, subscriptionId.ToString());
     var subscription = new AzureSubscription()
     {
         Id = subscriptionId,
         Name = "Test Subscription 1",
         Environment = EnvironmentName.AzureCloud,
         Account = account.Id,
     };
     subscription.SetProperty(AzureSubscription.Property.Tenants, tenantId.ToString());
     subscription.SetProperty(AzureSubscription.Property.StorageAccount, storageAccount);
     client.AddOrSetAccount(account);
     client.AddOrSetSubscription(subscription);
     client.SetSubscriptionAsDefault(subscriptionId, account.Id);
     return profile;
 }
开发者ID:rohmano,项目名称:azure-powershell,代码行数:27,代码来源:CommonDataCmdletTests.cs

示例3: ClearAzureProfileClearsCustomProfile

        public void ClearAzureProfileClearsCustomProfile()
        {
            string subscriptionDataFile = Path.GetTempFileName();

            ClearAzureProfileCommand cmdlt = new ClearAzureProfileCommand();
            // Setup
            ProfileClient client = new ProfileClient(new AzureProfile(subscriptionDataFile));
            client.AddOrSetAccount(azureAccount);
            client.AddOrSetEnvironment(azureEnvironment);
            client.AddOrSetSubscription(azureSubscription1);
            client.Profile.Save();

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

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

            // Verify
            client = new ProfileClient(new AzureProfile(subscriptionDataFile));
            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,代码行数:27,代码来源:ProfileCmdltsTests.cs

示例4: SetupUnitTestSubscription

        /// <summary>
        /// Common helper method for other tests to create a unit test subscription
        /// that connects to the mock server.
        /// </summary>
        /// <param name="powershell">The powershell instance used for the test.</param>
        public static AzureSubscription SetupUnitTestSubscription(System.Management.Automation.PowerShell powershell)
        {
            UnitTestHelper.ImportAzureModule(powershell);

            X509Certificate2 certificate = UnitTestHelper.GetUnitTestClientCertificate();
            Guid subscriptionId = new Guid(UnitTestSubscriptionId);

            // Set the client certificate used in the subscription
            powershell.Runspace.SessionStateProxy.SetVariable(
                "clientCertificate",
                certificate);

            var profile = new AzureSMProfile(Path.Combine(AzureSession.ProfileDirectory, AzureSession.ProfileFile));
            AzureSMCmdlet.CurrentProfile = profile;
            ProfileClient client = new ProfileClient(profile);
            client.AddOrSetEnvironment(new AzureEnvironment
                {
                    Name = UnitTestEnvironmentName,
                    Endpoints = new Dictionary<AzureEnvironment.Endpoint, string>
                    {
                        {AzureEnvironment.Endpoint.ServiceManagement, MockHttpServer.DefaultHttpsServerPrefixUri.AbsoluteUri},
                        {AzureEnvironment.Endpoint.SqlDatabaseDnsSuffix, ".database.windows.net"}
                    }
                });
            
            var account = new AzureAccount
            {
                Id = certificate.Thumbprint,
                Type = AzureAccount.AccountType.Certificate
            };

            var subscription = new AzureSubscription
            {
                Id = subscriptionId,
                Name = UnitTestSubscriptionName,
                Environment = UnitTestEnvironmentName,
                Account = account.Id
            };

            client.AddOrSetAccount(account);
            client.AddOrSetSubscription(subscription);
            client.SetSubscriptionAsDefault(subscriptionId, account.Id);
            client.Profile.Save();

            return subscription;
        }
开发者ID:docschmidt,项目名称:azure-powershell,代码行数:51,代码来源:UnitTestHelper.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: ImportPublishSettingsUsesProperEnvironmentWithManagementUrl

        public void ImportPublishSettingsUsesProperEnvironmentWithManagementUrl()
        {
            MockDataStore dataStore = new MockDataStore();
            ProfileClient.DataStore = dataStore;
            ProfileClient client = new ProfileClient();
            client.AddOrSetAccount(azureAccount);
            azureEnvironment.Endpoints[AzureEnvironment.Endpoint.ServiceManagement] = "https://newmanagement.core.windows.net/";
            client.AddOrSetEnvironment(azureEnvironment);
            client.AddOrSetSubscription(azureSubscription1);
            client.SetSubscriptionAsDefault(azureSubscription1.Name, azureAccount.Id);
            client.Profile.Save();

            client = new ProfileClient();

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

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

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

示例8: 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

示例9: ImportPublishSettingsUsesPassedInEnvironment

        public void ImportPublishSettingsUsesPassedInEnvironment()
        {
            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);
            client.SetSubscriptionAsDefault(azureSubscription1.Name, azureAccount.Id);
            client.Profile.Save();

            client = new ProfileClient(currentProfile);

            dataStore.WriteFile("ImportPublishSettingsLoadsAndReturnsSubscriptions.publishsettings",
                Microsoft.WindowsAzure.Commands.Common.Test.Properties.Resources.ValidProfile3);

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

            Assert.True(subscriptions.All(s => s.Environment == azureEnvironment.Name));
            Assert.Equal(6, subscriptions.Count);
            Assert.Equal(7, client.Profile.Subscriptions.Count);
        }
开发者ID:Azure,项目名称:azure-powershell,代码行数:24,代码来源:ProfileClientTests.cs

示例10: GetAzureSubscriptionByIdChecksAndReturnsOnlyLocal

        public void GetAzureSubscriptionByIdChecksAndReturnsOnlyLocal()
        {
            SetMocks(new[] { rdfeSubscription1, rdfeSubscription2 }.ToList(), new[] { csmSubscription1, csmSubscription1withDuplicateId }.ToList());
            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);
            client.AddOrSetSubscription(azureSubscription2);

            var subscriptions = client.GetSubscription(azureSubscription1.Id);

            Assert.Equal(azureSubscription1.Id, subscriptions.Id);
            Assert.Throws<ArgumentException>(() => client.GetSubscription(new Guid()));
        }
开发者ID:Azure,项目名称:azure-powershell,代码行数:17,代码来源:ProfileClientTests.cs

示例11: RefreshSubscriptionsListsAllSubscriptions

        public void RefreshSubscriptionsListsAllSubscriptions()
        {
            SetMocks(new[] { rdfeSubscription1, rdfeSubscription2 }.ToList(), new[] { csmSubscription1, csmSubscription1withDuplicateId }.ToList());
            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);

            var subscriptions = client.RefreshSubscriptions(azureEnvironment);

            Assert.Equal(3, 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(0, 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:Azure,项目名称:azure-powershell,代码行数:20,代码来源:ProfileClientTests.cs

示例12: SetAzureSubscriptionUpdatesSubscriptionWithCertificate

        public void SetAzureSubscriptionUpdatesSubscriptionWithCertificate()
        {
            RunMockedCmdletTest(() =>
            {

                // Setup
                var profile =
                    new AzureSMProfile(Path.Combine(AzureSession.ProfileDirectory, AzureSession.ProfileFile));
                AzureSMCmdlet.CurrentProfile = profile;
                ProfileClient client = new ProfileClient(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.Certificate = SampleCertificate;

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

                // Verify
                client =
                    new ProfileClient(
                        new AzureSMProfile(Path.Combine(AzureSession.ProfileDirectory,
                            AzureSession.ProfileFile)));
                var newSubscription = client.Profile.Subscriptions[new Guid(cmdlt.SubscriptionId)];
                var newAccount = client.Profile.Accounts[SampleCertificate.Thumbprint];
                var existingAccount = client.Profile.Accounts[azureAccount.Id];
                Assert.Equal(azureEnvironment.Name, newSubscription.Environment);
                Assert.True(StorageAccountMatchesConnectionString(cmdlt.CurrentStorageAccountName,
                    newSubscription.GetProperty(AzureSubscription.Property.StorageAccount)));

                Assert.Equal(newAccount.Id, newSubscription.Account);
                Assert.Equal(AzureAccount.AccountType.Certificate, newAccount.Type);
                Assert.Equal(SampleCertificate.Thumbprint, newAccount.Id);
                Assert.Equal(cmdlt.SubscriptionId,
                    newAccount.GetProperty(AzureAccount.Property.Subscriptions));

                Assert.Equal(azureAccount.Id, existingAccount.Id);
                Assert.Equal(AzureAccount.AccountType.User, existingAccount.Type);
                Assert.True(
                    existingAccount.GetPropertyAsArray(AzureAccount.Property.Subscriptions)
                        .Contains(cmdlt.SubscriptionId));
            });
        }
开发者ID:rbramwell,项目名称:azure-powershell,代码行数:52,代码来源:ProfileCmdltsTests.cs

示例13: GetAzureSubscriptionByNameChecksAndReturnsOnlyLocal

        public void GetAzureSubscriptionByNameChecksAndReturnsOnlyLocal()
        {
            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);
            client.AddOrSetSubscription(azureSubscription2);

            var subscriptions = client.GetSubscription(azureSubscription1.Name);

            Assert.Equal(azureSubscription1.Id, subscriptions.Id);
            Assert.Throws<ArgumentException>(() => client.GetSubscription(new Guid()));
        }
开发者ID:khoatle,项目名称:azure-powershell,代码行数:16,代码来源:ProfileClientTests.cs

示例14: AddOrSetAzureSubscriptionChecksAndUpdates

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

            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:djrosanova,项目名称:azure-sdk-tools,代码行数:21,代码来源: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.AddOrSetAccount方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。