public void TestResetDefaultSubscription()
        {
            var globalSettingsManager = GlobalSettingsManager.CreateFromPublishSettings(GlobalPathInfo.GlobalSettingsDirectory, null, Data.ValidPublishSettings.First());

            var setSubscriptionCommand = new SetSubscriptionCommandStub();

            // Check that current subscription is the default one
            Assert.AreEqual("Windows Azure Sandbox 9-220", setSubscriptionCommand.GetCurrentSubscription().SubscriptionName);

            // Change it and make sure it got changed
            setSubscriptionCommand.SetSubscriptionProcess("DefaultSubscription", null, null, null, null, "TestSubscription1", null, null);
            Assert.AreEqual("TestSubscription1", setSubscriptionCommand.GetCurrentSubscription().SubscriptionName);
            Assert.AreEqual("TestSubscription1", setSubscriptionCommand.GetSubscriptions(null).Values.Single(sub => sub.IsDefault).SubscriptionName);

            setSubscriptionCommand.SetSubscriptionProcess("ResetDefaultSubscription", null, null, null, null, null, null, null);
            Assert.AreEqual("TestSubscription1", setSubscriptionCommand.GetCurrentSubscription().SubscriptionName);
            Assert.AreEqual("Windows Azure Sandbox 9-220", setSubscriptionCommand.GetSubscriptions(null).Values.Single(sub => sub.IsDefault).SubscriptionName);

            // Clean
            globalSettingsManager.DeleteGlobalSettingsManager();
        }
        public void TestCreateSubscription()
        {
            var globalSettingsManager = GlobalSettingsManager.CreateFromPublishSettings(GlobalPathInfo.GlobalSettingsDirectory, null, Data.ValidPublishSettings.First());

            var setSubscriptionCommand = new SetSubscriptionCommandStub();

            // Check that current subscription is the default one
            Assert.AreEqual("Windows Azure Sandbox 9-220", setSubscriptionCommand.GetCurrentSubscription().SubscriptionName);

            // Change it and make sure it got changed
            setSubscriptionCommand.SetSubscriptionProcess("CommonSettings", "newSubscription", "newSubscriptionId", null, "newEndpoint", null, "storage", null);
            var updatedSubscription = setSubscriptionCommand.GetSubscriptions(null).Values.First(subscription => subscription.SubscriptionName == "newSubscription");
            Assert.AreEqual("newSubscriptionId", updatedSubscription.SubscriptionId);
            Assert.AreEqual("newEndpoint", updatedSubscription.ServiceEndpoint);
            Assert.AreEqual("storage", updatedSubscription.CurrentStorageAccount);

            // Clean
            globalSettingsManager.DeleteGlobalSettingsManager();
        }
        public void TestUpdateSubscription()
        {
            var globalSettingsManager = GlobalSettingsManager.CreateFromPublishSettings(GlobalPathInfo.GlobalSettingsDirectory, null, Data.ValidPublishSettings.First());

            var setSubscriptionCommand = new SetSubscriptionCommandStub();

            // Check that current subscription is the default one
            Assert.AreEqual("Windows Azure Sandbox 9-220", setSubscriptionCommand.GetCurrentSubscription().SubscriptionName);

            // Change it and make sure it got changed
            setSubscriptionCommand.SetSubscriptionProcess("CommonSettings", "TestSubscription1", "newSubscriptionId", null, "newEndpoint", null, null, null);
            var updatedSubscription = setSubscriptionCommand.GetSubscriptions(null).Values.First(subscription => subscription.SubscriptionName == "TestSubscription1");

            Assert.AreEqual("newSubscriptionId", updatedSubscription.SubscriptionId);
            Assert.AreEqual("newEndpoint", updatedSubscription.ServiceEndpoint);

            // Clean
            globalSettingsManager.DeleteGlobalSettingsManager();
        }
        public void CreatesNewSubscriptionOnCleanMachine()
        {
            var setSubscriptionCommand = new SetSubscriptionCommandStub();

            // Check that we cant get a current subscription as there is no working directory
            Assert.IsNotNull(GlobalSettingsManager.Instance.SubscriptionManager);

            // Create a new subscription and a new working directory implicitly.
            var publishSettings = General.DeserializeXmlFile<PublishData>(Data.ValidPublishSettings.First(), string.Empty);
            var certificate = new X509Certificate2(Convert.FromBase64String(publishSettings.Items[0].ManagementCertificate), string.Empty);

            setSubscriptionCommand.SetSubscriptionProcess("CommonSettings", "newSubscription", "newSubscriptionId", certificate, "newEndpoint", null, null, null);
            var updatedSubscription = setSubscriptionCommand.GetSubscriptions(null).Values.First(subscription => subscription.SubscriptionName == "newSubscription");
            Assert.AreEqual("newSubscriptionId", updatedSubscription.SubscriptionId);
            Assert.AreEqual("newEndpoint", updatedSubscription.ServiceEndpoint);

            // Clean
            var globalSettingsManager = GlobalSettingsManager.Load(GlobalPathInfo.GlobalSettingsDirectory);
            globalSettingsManager.DeleteGlobalSettingsManager();
        }
        public void TestCreateSubscriptionNoImport()
        {
            var setSubscriptionCommand = new SetSubscriptionCommandStub();

            // Check that we cant get a current subscription as there is no working directory
            Assert.IsNull(setSubscriptionCommand.GetCurrentSubscription());

            // Create a new subscription and a new working directory implicitly.
            var publishSettings = General.DeserializeXmlFile <PublishData>(Data.ValidPublishSettings.First(), string.Empty);
            var certificate     = new X509Certificate2(Convert.FromBase64String(publishSettings.Items[0].ManagementCertificate), string.Empty);

            setSubscriptionCommand.SetSubscriptionProcess("CommonSettings", "newSubscription", "newSubscriptionId", certificate, "newEndpoint", null, null, null);
            var updatedSubscription = setSubscriptionCommand.GetSubscriptions(null).Values.First(subscription => subscription.SubscriptionName == "newSubscription");

            Assert.AreEqual("newSubscriptionId", updatedSubscription.SubscriptionId);
            Assert.AreEqual("newEndpoint", updatedSubscription.ServiceEndpoint);

            // Clean
            var globalSettingsManager = GlobalSettingsManager.Load(GlobalPathInfo.GlobalSettingsDirectory);

            globalSettingsManager.DeleteGlobalSettingsManager();
        }
        public void TestSetDefaultSubscription()
        {
            var globalSettingsManager = GlobalSettingsManager.CreateFromPublishSettings(GlobalPathInfo.GlobalSettingsDirectory, null, Data.ValidPublishSettings.First());

            var setSubscriptionCommand = new SetSubscriptionCommandStub();

            // Check that current subscription is the default one
            Assert.AreEqual("Windows Azure Sandbox 9-220", setSubscriptionCommand.GetCurrentSubscription().SubscriptionName);

            // Change it and make sure it got changed
            setSubscriptionCommand.SetSubscriptionProcess("DefaultSubscription", null, null, null, null, "TestSubscription1", null, null);
            Assert.AreEqual("TestSubscription1", setSubscriptionCommand.GetCurrentSubscription().SubscriptionName);
            Assert.AreEqual("TestSubscription1", setSubscriptionCommand.GetSubscriptions(null).Values.Single(sub => sub.IsDefault).SubscriptionName);

            // Clean
            globalSettingsManager.DeleteGlobalSettingsManager();
        }