public void CanCreateAzureProfileWithFile()
        {
           var dataStore = AzureSession.DataStore;
            try
            {
                AzureSession.DataStore = new MemoryDataStore();
                var oldProfile = new AzureProfile();
                AzurePSCmdlet.CurrentProfile = oldProfile;
                string myFile = Path.GetTempFileName();
                var profile = SetupCustomProfile(myFile);
                var cmdlet = new NewAzureProfileCommand();
                var runtime = new MockCommandRuntime();
                cmdlet.SetParameterSet(NewAzureProfileCommand.FileParameterSet);
                cmdlet.Path = myFile;

                cmdlet.CommandRuntime = runtime;
                cmdlet.InvokeBeginProcessing();
                cmdlet.ExecuteCmdlet();
                cmdlet.InvokeEndProcessing();

                var returnedProfile = runtime.OutputPipeline.First() as AzureProfile;
                Assert.NotNull(returnedProfile);
                Assert.NotNull(returnedProfile.Accounts.Values);
                Assert.NotNull(returnedProfile.Subscriptions.Values);
                Assert.NotNull(returnedProfile.Environments.Values);
                Assert.Equal(profile.Accounts.Values.Count, returnedProfile.Accounts.Values.Count);
                foreach (var account in profile.Accounts.Values)
                {
                    var returnedAccount = returnedProfile.Accounts.Values.FirstOrDefault((a) => a.Id == account.Id);
                    Assert.NotNull(returnedAccount);
                    Assert.Equal(account.GetProperty(AzureAccount.Property.Subscriptions),
                        returnedAccount.GetProperty(AzureAccount.Property.Subscriptions));
                }

                Assert.Equal(profile.Subscriptions.Values.Count, returnedProfile.Subscriptions.Values.Count);
                foreach (var subscription in profile.Subscriptions.Values)
                {
                    var returnedSub = returnedProfile.Subscriptions.Values.FirstOrDefault((s) => s.Id == subscription.Id);
                    Assert.NotNull(returnedSub);
                }

                // current profile does not change
                Assert.Equal(oldProfile.Accounts.Count, 0);
                Assert.Equal(oldProfile.Subscriptions.Count, 0);
            }
            finally
            {
                AzureSession.DataStore = dataStore;
            }
        }
        private void RunCreateProfileTest(Action<NewAzureProfileCommand> prepare, string parameterSet,
            Guid subscription, Action<AzureProfile> validate)
        {
            var clientFactory = AzureSession.ClientFactory;
            try
            {

                AzureSession.ClientFactory =
                    new MockClientFactory(
                        new List<object>
                        {
                            ProfileClientHelper.CreateRdfeSubscriptionClient(subscription, subscription.ToString()),
                            ProfileClientHelper.CreateCsmSubscriptionClient(new List<string>{subscription.ToString()}, new List<string>{subscription.ToString()})
                        }, true);

                var cmdlet = new NewAzureProfileCommand();
                prepare(cmdlet);
                cmdlet.CommandRuntime = commandRuntimeMock;
                cmdlet.SetParameterSet(parameterSet);
                cmdlet.ExecuteCmdlet();
                AzureProfile profile = commandRuntimeMock.OutputPipeline.First() as AzureProfile;
                Assert.NotNull(profile);
                Assert.NotNull(profile.Subscriptions);
                Assert.NotNull(profile.DefaultSubscription);
                Assert.Equal(profile.DefaultSubscription.Id, subscription);
                Assert.Equal(profile.Subscriptions.Count, 1);
                Assert.Equal(profile.Subscriptions.Values.First().Id, subscription);
                validate(profile);
            }
            finally
            {
                AzureSession.ClientFactory = clientFactory;
            }

        }