public void GetAzureRmSubscriptionPaginatedResult()
        {
            var tenants = new List <string> {
                Guid.NewGuid().ToString(), DefaultTenant.ToString()
            };
            var secondsubscriptionInTheFirstTenant = Guid.NewGuid().ToString();
            var firstList = new List <string> {
                DefaultSubscription.ToString(), secondsubscriptionInTheFirstTenant
            };
            var secondList = new List <string> {
                Guid.NewGuid().ToString()
            };
            var thirdList = new List <string> {
                DefaultSubscription.ToString(), secondsubscriptionInTheFirstTenant
            };
            var fourthList = new List <string> {
                DefaultSubscription.ToString(), secondsubscriptionInTheFirstTenant
            };
            var client = SetupTestEnvironment(tenants, firstList, secondList, thirdList, fourthList);

            var dataStore = new MemoryDataStore();

            AzureSession.Instance.DataStore = dataStore;
            var commandRuntimeMock = new MockCommandRuntime();

            AzureSession.Instance.AuthenticationFactory = new MockTokenAuthenticationFactory();
            var profile = new AzureRmProfile();

            profile.EnvironmentTable.Add("foo", new AzureEnvironment(AzureEnvironment.PublicEnvironments.Values.FirstOrDefault()));
            profile.DefaultContext = Context;
            var cmdlt = new GetAzureRMSubscriptionCommand();

            // Setup
            cmdlt.DefaultProfile = profile;
            cmdlt.CommandRuntime = commandRuntimeMock;

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

            var subscriptionName = MockSubscriptionClientFactory.GetSubscriptionNameFromId(secondList[0]);

            Assert.True(commandRuntimeMock.OutputPipeline.Count == 7);
            Assert.Equal("Disabled", ((PSAzureSubscription)commandRuntimeMock.OutputPipeline[2]).State);
            Assert.Equal(subscriptionName, ((PSAzureSubscription)commandRuntimeMock.OutputPipeline[2]).Name);
        }
        public void GetAzureRmSubscriptionByNameMultiplePages()
        {
            var tenants = new List <string> {
                Guid.NewGuid().ToString(), DefaultTenant.ToString()
            };
            var firstTenantSubscriptions = new List <string> {
                Guid.NewGuid().ToString(),
                Guid.NewGuid().ToString(),
                Guid.NewGuid().ToString(),
                Guid.NewGuid().ToString()
            };
            var secondTenantSubscriptions = new List <string> {
                Guid.NewGuid().ToString(),
                Guid.NewGuid().ToString(),
                Guid.NewGuid().ToString(),
                Guid.NewGuid().ToString()
            };

            var firstList = new List <string> {
                firstTenantSubscriptions[0], firstTenantSubscriptions[1]
            };
            var secondList = new List <string> {
                firstTenantSubscriptions[2], firstTenantSubscriptions[3]
            };

            var thirdList = new List <string> {
                secondTenantSubscriptions[0], secondTenantSubscriptions[1]
            };
            var fourthList = new List <string> {
                secondTenantSubscriptions[2], secondTenantSubscriptions[3]
            };

            var client = SetupTestEnvironment(tenants, firstList, secondList, thirdList, fourthList);

            var subscriptionName = MockSubscriptionClientFactory.GetSubscriptionNameFromId(secondTenantSubscriptions[2]);

            var dataStore = new MemoryDataStore();

            AzureSession.Instance.DataStore = dataStore;
            var commandRuntimeMock = new MockCommandRuntime();

            AzureSession.Instance.AuthenticationFactory = new MockTokenAuthenticationFactory();
            var profile = new AzureRmProfile();

            profile.EnvironmentTable.Add("foo", new AzureEnvironment(AzureEnvironment.PublicEnvironments.Values.FirstOrDefault()));
            profile.DefaultContext = Context;
            var cmdlt = new GetAzureRMSubscriptionCommand();

            // Setup
            cmdlt.DefaultProfile   = profile;
            cmdlt.CommandRuntime   = commandRuntimeMock;
            cmdlt.SubscriptionName = subscriptionName;

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

            Assert.True(commandRuntimeMock.OutputPipeline.Count == 1);

            // Make sure we can get a subscription from the second page of the second tenant by subscription name
            var resultSubscription = (PSAzureSubscription)commandRuntimeMock.OutputPipeline[0];

            Assert.Equal(subscriptionName, resultSubscription.Name);
            Assert.Equal(tenants[1], resultSubscription.TenantId);
        }