public void RefreshSubscriptionsMergesFromServer()
        {
            SetMocks(new[] { rdfeSubscription1, rdfeSubscription2 }.ToList(), new[] { csmSubscription1, csmSubscription1withDuplicateId }.ToList());
            MemoryDataStore dataStore = new MemoryDataStore();
            AzureSession.DataStore = dataStore;
            currentProfile = new AzureProfile(Path.Combine(AzureSession.ProfileDirectory, AzureSession.ProfileFile));
            ProfileClient client = new ProfileClient(currentProfile);
            client.AddOrSetEnvironment(azureEnvironment);
            client.Profile.Accounts[azureAccount.Id] = azureAccount;
            client.AddOrSetSubscription(azureSubscription1);

            var subscriptions = client.RefreshSubscriptions(azureEnvironment);

            Assert.Equal(4, subscriptions.Count);
            Assert.Equal(4, subscriptions.Count(s => s.Account == "test"));
            Assert.Equal(1, subscriptions.Count(s => s.Id == azureSubscription1.Id));
            Assert.Equal(1, subscriptions.Count(s => s.Id == new Guid(rdfeSubscription1.SubscriptionId)));
            Assert.Equal(2, subscriptions.First(s => s.Id == new Guid(rdfeSubscription1.SubscriptionId)).GetPropertyAsArray(AzureSubscription.Property.SupportedModes).Count());
            Assert.Equal(1, subscriptions.Count(s => s.Id == new Guid(rdfeSubscription2.SubscriptionId)));
            Assert.Equal(1, subscriptions.Count(s => s.Id == new Guid(csmSubscription1.SubscriptionId)));
        }
        public void RefreshSubscriptionsListsAllSubscriptions()
        {
            SetMocks(new[] { rdfeSubscription1, rdfeSubscription2 }.ToList(), new[] { csmSubscription1, csmSubscription1withDuplicateId }.ToList());
            MemoryDataStore dataStore = new MemoryDataStore();
            AzureSession.DataStore = dataStore;
            currentProfile = new AzureProfile(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(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"));
        }
        public void RefreshSubscriptionsUpdatesAccounts()
        {
            SetMocks(new[] { rdfeSubscription1, rdfeSubscription2 }.ToList(), new[] { csmSubscription1, csmSubscription1withDuplicateId }.ToList());
            MemoryDataStore dataStore = new MemoryDataStore();
            AzureSession.DataStore = dataStore;
            currentProfile = new AzureProfile(Path.Combine(AzureSession.ProfileDirectory, AzureSession.ProfileFile));
            ProfileClient client = new ProfileClient(currentProfile);
            client.AddOrSetEnvironment(azureEnvironment);
            client.Profile.Accounts[azureAccount.Id] = azureAccount;
            client.AddOrSetSubscription(azureSubscription1);

            var subscriptions = client.RefreshSubscriptions(azureEnvironment);

            Assert.True(client.Profile.Accounts[azureAccount.Id].HasSubscription(new Guid(rdfeSubscription1.SubscriptionId)));
            Assert.True(client.Profile.Accounts[azureAccount.Id].HasSubscription(new Guid(rdfeSubscription2.SubscriptionId)));
            Assert.True(client.Profile.Accounts[azureAccount.Id].HasSubscription(new Guid(csmSubscription1.SubscriptionId)));
            Assert.True(client.Profile.Accounts[azureAccount.Id].HasSubscription(new Guid(csmSubscription1withDuplicateId.SubscriptionId)));
        }
        public void RefreshSubscriptionsWorksWithMooncake()
        {
            SetMocks(new[] { rdfeSubscription1, rdfeSubscription2 }.ToList(), new[] { csmSubscription1, csmSubscription1withDuplicateId }.ToList());
            MemoryDataStore dataStore = new MemoryDataStore();
            AzureSession.DataStore = dataStore;
            currentProfile = new AzureProfile(Path.Combine(AzureSession.ProfileDirectory, AzureSession.ProfileFile));
            ProfileClient client = new ProfileClient(currentProfile);

            client.Profile.Accounts[azureAccount.Id] = azureAccount;

            var subscriptions = client.RefreshSubscriptions(client.Profile.Environments[EnvironmentName.AzureChinaCloud]);

            Assert.Equal(3, subscriptions.Count);
            Assert.Equal(3, subscriptions.Count(s => s.Account == "test"));
            Assert.Equal(1, subscriptions.Count(s => s.Id == new Guid(rdfeSubscription1.SubscriptionId)));
            Assert.Equal(2, subscriptions.First(s => s.Id == new Guid(rdfeSubscription1.SubscriptionId)).GetPropertyAsArray(AzureSubscription.Property.SupportedModes).Count());
            Assert.Equal(1, subscriptions.Count(s => s.Id == new Guid(rdfeSubscription2.SubscriptionId)));
        }