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

            client.Profile.Accounts[azureAccount.Id] = azureAccount;
            client.AddOrSetEnvironment(azureEnvironment);
            client.AddOrSetSubscription(azureSubscription1);
            client.SetSubscriptionAsCurrent(azureSubscription1.Name, azureSubscription1.Account);
            client.SetSubscriptionAsDefault(azureSubscription1.Name, azureSubscription1.Account);

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

            List<string> log = new List<string>();
            client.WarningLog = log.Add;

            var subscription = client.RemoveSubscription(azureSubscription1.Name);

            Assert.Equal(0, client.Profile.Subscriptions.Count);
            Assert.Equal(azureSubscription1.Name, subscription.Name);
            Assert.Equal(2, log.Count);
            Assert.Equal(
                "The default subscription is being removed. Use Select-AzureSubscription -Default <subscriptionName> to select a new default subscription.",
                log[0]);
            Assert.Equal(
                "The current subscription is being removed. Use Select-AzureSubscription <subscriptionName> to select a new current subscription.",
                log[1]);
            Assert.Throws<ArgumentException>(() => client.RemoveSubscription("bad"));
            Assert.Throws<ArgumentNullException>(() => client.RemoveSubscription(null));
        }
        public void SetAzureSubscriptionAsCurrentSetsCurrent()
        {
            MockDataStore dataStore = new MockDataStore();
            ProfileClient.DataStore = dataStore;
            ProfileClient client = new ProfileClient();
            client.Profile.Accounts[azureAccount.Id] = azureAccount;
            client.AddOrSetEnvironment(azureEnvironment);
            client.AddOrSetSubscription(azureSubscription1);
            client.AddOrSetSubscription(azureSubscription2);

            Assert.Null(AzureSession.CurrentContext.Subscription);

            client.SetSubscriptionAsCurrent(azureSubscription2.Name, azureSubscription2.Account);

            Assert.Equal(azureSubscription2.Id, AzureSession.CurrentContext.Subscription.Id);
            Assert.Throws<ArgumentException>(() => client.SetSubscriptionAsCurrent("bad", null));
            Assert.Throws<ArgumentException>(() => client.SetSubscriptionAsCurrent(null, null));
        }
        public void SelectAzureSubscriptionByIdWorks()
        {
            MockDataStore dataStore = new MockDataStore();
            ProfileClient.DataStore = dataStore;
            ProfileClient client = new ProfileClient();

            var tempSubscriptions = new List<AzureSubscription>
            {
                new AzureSubscription
                {
                    Id = new Guid("11111111-1383-4740-8A69-748C5B63ADBA"),
                    Name = "Same Name Subscription",
                    Environment = azureEnvironment.Name,
                    Account = azureAccount.Id,
                    Properties = new Dictionary<AzureSubscription.Property, string>
                    {
                        { AzureSubscription.Property.Default, "True" } 
                    }
                },

                new AzureSubscription
                {
                    Id = new Guid("22222222-1383-4740-8A69-748C5B63ADBA"),
                    Name = "Same Name Subscription",
                    Environment = azureEnvironment.Name,
                    Account = azureAccount.Id,
                    Properties = new Dictionary<AzureSubscription.Property, string>()
                },

                new AzureSubscription
                {
                    Id = new Guid("33333333-1383-4740-8A69-748C5B63ADBA"),
                    Name = "Same Name Subscription",
                    Environment = azureEnvironment.Name,
                    Account = azureAccount.Id,
                    Properties = new Dictionary<AzureSubscription.Property, string>()
                }
            };

            client.Profile.Accounts[azureAccount.Id] = azureAccount;
            client.AddOrSetEnvironment(azureEnvironment);

            foreach (var s in tempSubscriptions)
            {
                client.AddOrSetSubscription(s);
            }

            client.SetSubscriptionAsCurrent(tempSubscriptions[0].Name, tempSubscriptions[0].Account);
            client.Profile.Save();

            Assert.Equal(tempSubscriptions[0].Id, AzureSession.CurrentContext.Subscription.Id);

            var cmdlt = new SelectAzureSubscriptionCommand();

            cmdlt.CommandRuntime = new MockCommandRuntime();
            cmdlt.SubscriptionId = tempSubscriptions[2].Id.ToString();
            cmdlt.SetParameterSet("SelectSubscriptionByIdParameterSet");

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

            Assert.Equal(tempSubscriptions[2].Id, AzureSession.CurrentContext.Subscription.Id);
        }