public void TestSaveSubscriptions()
        {
            for (var i = 0; i < Data.ValidPublishSettings.Count; i++)
            {
                var globalSettingsManager = GlobalSettingsManager.CreateFromPublishSettings(GlobalPathInfo.GlobalSettingsDirectory, null, Data.ValidPublishSettings[i]);

                var subscriptionsManager = SubscriptionsManager.Import(
                    Data.ValidSubscriptionsData[i],
                    globalSettingsManager.PublishSettings,
                    globalSettingsManager.Certificate);

                var newSubscription = new SubscriptionData
                {
                    SubscriptionName = "newsubscription",
                    IsDefault        = false,
                    SubscriptionId   = "id"
                };

                subscriptionsManager.Subscriptions[newSubscription.SubscriptionName] = newSubscription;
                subscriptionsManager.SaveSubscriptions(Path.Combine(GlobalPathInfo.GlobalSettingsDirectory, "test.xml"));

                var newSubscriptionsManager = SubscriptionsManager.Import(
                    Path.Combine(GlobalPathInfo.GlobalSettingsDirectory, "test.xml"),
                    globalSettingsManager.PublishSettings,
                    globalSettingsManager.Certificate);

                var addedSubscription = newSubscriptionsManager.Subscriptions.Values.Single(
                    subscription => subscription.SubscriptionName == newSubscription.SubscriptionName);

                Assert.AreEqual(newSubscription.SubscriptionId, addedSubscription.SubscriptionId);

                globalSettingsManager.DeleteGlobalSettingsManager();
            }
        }
Пример #2
0
        public void TestGetCurrentSubscriptionDefault()
        {
            var globalSettingsManager = GlobalSettingsManager.CreateFromPublishSettings(GlobalPathInfo.GlobalSettingsDirectory, null, Data.ValidPublishSettings.First());

            var importSubscriptionCommand = new ImportAzurePublishSettingsCommand();

            importSubscriptionCommand.ImportSubscriptionFile(
                Data.ValidPublishSettings.First(),
                null);

            var currentSubscription = importSubscriptionCommand.GetCurrentSubscription();

            Assert.AreEqual(currentSubscription.SubscriptionName, Data.Subscription1);
            Assert.IsTrue(currentSubscription.IsDefault);

            // Test the get for the current subscription
            var getSubscriptionCommand = new GetSubscriptionCommandStub();

            getSubscriptionCommand.GetSubscriptionProcess("Default", null, null);

            Assert.AreEqual(1, getSubscriptionCommand.Messages.Count);
            Assert.AreEqual(currentSubscription.SubscriptionName, getSubscriptionCommand.Messages.First().SubscriptionName);
            Assert.AreEqual(currentSubscription.SubscriptionId, getSubscriptionCommand.Messages.First().SubscriptionId);

            globalSettingsManager.DeleteGlobalSettingsManager();
        }
Пример #3
0
 private GlobalSettingsManager CreateGlobalSettingsManager(string subscriptionsDataFile, string publishSettingsFile)
 {
     return(GlobalSettingsManager.CreateFromPublishSettings(
                GlobalPathInfo.GlobalSettingsDirectory,
                subscriptionsDataFile,
                publishSettingsFile));
 }
Пример #4
0
        public void TestGetSubscription()
        {
            var globalSettingsManager = GlobalSettingsManager.CreateFromPublishSettings(GlobalPathInfo.GlobalSettingsDirectory, null, Data.ValidPublishSettings.First());

            var cmdletStub   = new CmdletStub();
            var subscription = cmdletStub.GetSubscription("TestSubscription1", null);

            Assert.AreEqual("TestSubscription1", subscription.SubscriptionName);

            globalSettingsManager.DeleteGlobalSettingsManager();
        }
Пример #5
0
        public void ProcessGetWebsiteWithNullSubscription()
        {
            // Setup
            GlobalSettingsManager globalSettingsManager = GlobalSettingsManager.CreateFromPublishSettings(
                GlobalPathInfo.GlobalSettingsDirectory,
                null,
                Data.ValidPublishSettings[0]);
            RemoveAzureSubscriptionCommand removeCmdlet = new RemoveAzureSubscriptionCommand();

            removeCmdlet.CommandRuntime = new MockCommandRuntime();
            ICollection <string> subscriptions = globalSettingsManager.Subscriptions.Keys;

            foreach (string subscription in subscriptions)
            {
                removeCmdlet.RemoveSubscriptionProcess(subscription, null);
            }

            SimpleWebsitesManagement channel = new SimpleWebsitesManagement();

            channel.GetWebSpacesThunk = ar => new WebSpaces(new List <WebSpace> {
                new WebSpace {
                    Name = "webspace1"
                }, new WebSpace {
                    Name = "webspace2"
                }
            });
            channel.GetSitesThunk = ar =>
            {
                if (ar.Values["webspaceName"].Equals("webspace1"))
                {
                    return(new Sites(new List <Site> {
                        new Site {
                            Name = "website1", WebSpace = "webspace1"
                        }
                    }));
                }

                return(new Sites(new List <Site> {
                    new Site {
                        Name = "website2", WebSpace = "webspace2"
                    }
                }));
            };

            // Test
            GetAzureWebsiteCommand getAzureWebsiteCommand = new GetAzureWebsiteCommand(channel)
            {
                ShareChannel        = true,
                CommandRuntime      = new MockCommandRuntime(),
                CurrentSubscription = null
            };

            Testing.AssertThrows <Exception>(() => getAzureWebsiteCommand.ExecuteCmdlet(), Resources.NoDefaultSubscriptionMessage);
        }
Пример #6
0
        public void GlobalSettingsManagerCreateNewInvalidPublishSettingsFileFail()
        {
            foreach (string invalidFileName in Data.InvalidFileName)
            {
                Action <ArgumentException> verification = ex =>
                {
                    Assert.AreEqual <string>(ex.Message, Resources.IllegalPath);
                    Assert.IsFalse(Directory.Exists(Data.AzureAppDir));
                };

                Testing.AssertThrows <ArgumentException>(() => GlobalSettingsManager.CreateFromPublishSettings(Data.AzureAppDir, null, invalidFileName), verification);
            }
        }
Пример #7
0
 public void GlobalSettingsManagerCreateNewNullPublishSettingsFileFail()
 {
     try
     {
         GlobalSettingsManager.CreateFromPublishSettings(Data.AzureAppDir, null, null);
         Assert.Fail("No exception thrown");
     }
     catch (Exception ex)
     {
         Assert.IsTrue(ex is ArgumentException);
         Assert.AreEqual <string>(ex.Message, string.Format(Resources.InvalidOrEmptyArgumentMessage, Resources.PublishSettings));
         Assert.IsFalse(Directory.Exists(Data.AzureAppDir));
     }
 }
Пример #8
0
        public void GlobalSettingsManagerCreateNew()
        {
            foreach (string fileName in Data.ValidPublishSettings)
            {
                // Prepare
                GlobalSettingsManager globalSettingsManager   = GlobalSettingsManager.CreateFromPublishSettings(Data.AzureAppDir, null, fileName);
                PublishData           expectedPublishSettings = General.DeserializeXmlFile <PublishData>(fileName);

                // Assert
                AzureAssert.AreEqualGlobalSettingsManager(new GlobalPathInfo(Data.AzureAppDir), expectedPublishSettings, globalSettingsManager);

                // Clean
                globalSettingsManager.DeleteGlobalSettingsManager();
            }
        }
Пример #9
0
        /// <summary>
        /// Create a temporary Azure SDK directory to simulate global files.
        /// </summary>
        /// <param name="publishSettingsPath">
        /// Path to the publish settings.
        /// </param>
        /// <returns>The path to the temporary Azure SDK directory.</returns>
        public string CreateAzureSdkDirectoryAndImportPublishSettings(string publishSettingsPath)
        {
            Debug.Assert(!string.IsNullOrEmpty(publishSettingsPath));
            Debug.Assert(File.Exists(publishSettingsPath));
            Debug.Assert(string.IsNullOrEmpty(AzureSdkPath));

            AzureSdkPath = CreateDirectory("AzureSdk");
            GlobalPathInfo.GlobalSettingsDirectory = AzureSdkPath;
            GlobalSettingsManager globalSettingsManager = GlobalSettingsManager.CreateFromPublishSettings(
                GlobalPathInfo.GlobalSettingsDirectory,
                null,
                publishSettingsPath);

            return(AzureSdkPath);
        }
Пример #10
0
        public void TestGetSubscriptions()
        {
            var globalSettingsManager = GlobalSettingsManager.CreateFromPublishSettings(GlobalPathInfo.GlobalSettingsDirectory, null, Data.ValidPublishSettings.First());

            var cmdletStub    = new CmdletStub();
            var subscriptions = cmdletStub.GetSubscriptions(null);

            // All subscriptions from both the publish settings file and the subscriptions file were imported
            Assert.AreEqual(6, subscriptions.Count);

            // There's a single default subscription
            Assert.AreEqual("Windows Azure Sandbox 9-220", subscriptions.Values.Single(subscription => subscription.IsDefault).SubscriptionName);

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

            var selectSubscriptionCommand = new SelectAzureSubscriptionCommand();

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

            // Change it and make sure it got changed
            selectSubscriptionCommand.SelectSubscriptionProcess("Set", "mysub1", Data.ValidSubscriptionsData.First());
            Assert.AreEqual("mysub1", selectSubscriptionCommand.GetCurrentSubscription().SubscriptionName);

            // Clean
            globalSettingsManager.DeleteGlobalSettingsManager();
        }
Пример #12
0
        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();
        }
Пример #13
0
 public void GlobalSettingsManagerCreateNewInvalidPublishSettingsSchemaFail()
 {
     foreach (string fileName in Data.InvalidPublishSettings)
     {
         try
         {
             GlobalSettingsManager.CreateFromPublishSettings(Data.AzureAppDir, null, fileName);
             Assert.Fail("No exception thrown");
         }
         catch (Exception ex)
         {
             Assert.IsTrue(ex is InvalidOperationException);
             Assert.AreEqual <string>(ex.Message, string.Format(Resources.InvalidPublishSettingsSchema, fileName));
             Assert.IsFalse(Directory.Exists(Data.AzureAppDir));
         }
     }
 }
Пример #14
0
        public void TestGetCurrentSubscription()
        {
            var globalSettingsManager = GlobalSettingsManager.CreateFromPublishSettings(GlobalPathInfo.GlobalSettingsDirectory, null, Data.ValidPublishSettings.First());

            var cmdletStub    = new CmdletStub();
            var subscriptions = cmdletStub.GetSubscriptions(null);

            var currentSubscription = subscriptions.Values.First();

            cmdletStub.SetCurrentSubscription(currentSubscription.SubscriptionName, null);

            // Test
            var actualCurrentSubscription = cmdletStub.GetCurrentSubscription();

            Assert.AreEqual(currentSubscription.SubscriptionName, actualCurrentSubscription.SubscriptionName);
            Assert.AreEqual(currentSubscription.SubscriptionId, actualCurrentSubscription.SubscriptionId);

            globalSettingsManager.DeleteGlobalSettingsManager();
        }
Пример #15
0
        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();
        }
Пример #16
0
        public void TestRemoveNonDefaultSubscriptionProcess()
        {
            for (var i = 0; i < Data.ValidPublishSettings.Count; i++)
            {
                var targetFile = Path.Combine(Directory.GetParent(Data.ValidSubscriptionsData[i]).FullName, "removeagain" + Path.GetFileName(Data.ValidSubscriptionsData[i]));
                File.Copy(Data.ValidSubscriptionsData[i], targetFile, true);
                var globalSettingsManager             = GlobalSettingsManager.CreateFromPublishSettings(GlobalPathInfo.GlobalSettingsDirectory, targetFile, Data.ValidPublishSettings[i]);
                MockCommandRuntime mockCommandRuntime = new MockCommandRuntime();
                var removeSubscriptionCommand         = new RemoveAzureSubscriptionCommand();
                removeSubscriptionCommand.CommandRuntime = mockCommandRuntime;
                removeSubscriptionCommand.RemoveSubscriptionProcess("mysub2", targetFile);

                var subscriptionsManager = GlobalSettingsManager.Load(GlobalPathInfo.GlobalSettingsDirectory, targetFile);
                Assert.IsFalse(subscriptionsManager.Subscriptions.Values.Any(subscription => subscription.SubscriptionName == "mysub2"));
                Assert.IsTrue(subscriptionsManager.Subscriptions.Values.Any(subscription => subscription.IsDefault));

                // Clean
                globalSettingsManager.DeleteGlobalSettingsManager();
            }
        }
Пример #17
0
        public void TestUpdateSubscriptions()
        {
            var globalSettingsManager = GlobalSettingsManager.CreateFromPublishSettings(GlobalPathInfo.GlobalSettingsDirectory, null, Data.ValidPublishSettings.First());

            var cmdletStub    = new CmdletStub();
            var subscriptions = cmdletStub.GetSubscriptions(Data.ValidSubscriptionsData[0]);

            var deleteSubscriptionKey = subscriptions.Keys.First();

            subscriptions.Remove(deleteSubscriptionKey);

            var newPath = Path.Combine(GlobalPathInfo.GlobalSettingsDirectory, "test.xml");

            cmdletStub.UpdateSubscriptions(subscriptions, newPath);

            var newSubscriptions = cmdletStub.GetSubscriptions(newPath);

            Assert.IsFalse(newSubscriptions.ContainsKey(deleteSubscriptionKey));

            globalSettingsManager.DeleteGlobalSettingsManager();
        }
        public void TestImportSubscriptionProcess()
        {
            MockCommandRuntime mockCommandRuntime;
            ImportAzurePublishSettingsCommand cmdlet;

            mockCommandRuntime    = new MockCommandRuntime();
            cmdlet                = new ImportAzurePublishSettingsCommand();
            cmdlet.CommandRuntime = mockCommandRuntime;
            var globalSettingsManager = GlobalSettingsManager.CreateFromPublishSettings(GlobalPathInfo.GlobalSettingsDirectory, null, Data.ValidPublishSettings.First());


            cmdlet.ImportSubscriptionFile(
                Data.ValidPublishSettings.First(),
                null);

            var currentSubscription = cmdlet.GetCurrentSubscription();

            Assert.AreEqual(currentSubscription.SubscriptionName, Data.Subscription1);
            Assert.IsTrue(currentSubscription.IsDefault);

            globalSettingsManager.DeleteGlobalSettingsManager();
        }
Пример #19
0
        public void TestSetDefaultSubscription()
        {
            var globalSettingsManager = GlobalSettingsManager.CreateFromPublishSettings(GlobalPathInfo.GlobalSettingsDirectory, null, Data.ValidPublishSettings.First());

            var newPath = Path.Combine(GlobalPathInfo.GlobalSettingsDirectory, "test.xml");

            File.Copy(Data.ValidSubscriptionsData[0], newPath, true);

            var cmdletStub    = new CmdletStub();
            var subscriptions = cmdletStub.GetSubscriptions(Data.ValidSubscriptionsData[0]);

            var newDefaultSubscription = subscriptions.Values.First(subscription => !subscription.IsDefault);

            cmdletStub.SetDefaultSubscription(newDefaultSubscription.SubscriptionName, newPath);

            // Test - reimport and make sure the current subscription after import is the correct one
            var subscriptionsManager = GlobalSettingsManager.Load(GlobalPathInfo.GlobalSettingsDirectory, newPath).SubscriptionManager;
            var defaultSubscription  = subscriptionsManager.Subscriptions.Values.First(subscription => subscription.IsDefault);

            Assert.AreEqual(newDefaultSubscription.SubscriptionName, defaultSubscription.SubscriptionName);

            globalSettingsManager.DeleteGlobalSettingsManager();
        }
Пример #20
0
        public void GlobalSettingsManagerLoadIgnoresPublishExisting()
        {
            var publishSettingsFile        = Data.ValidPublishSettings.First();
            var subscriptionDataFile       = Data.ValidSubscriptionsData.First();
            var outputSubscriptionDataFile = Path.Combine(Directory.GetParent(subscriptionDataFile).FullName, "outputNoPublish.xml");

            File.Copy(subscriptionDataFile, outputSubscriptionDataFile);

            // Create with both an existing ouput subscription data file and the publish settings file
            GlobalSettingsManager globalSettingsManager = GlobalSettingsManager.CreateFromPublishSettings(Data.AzureAppDir, outputSubscriptionDataFile, publishSettingsFile);

            Assert.AreEqual(6, globalSettingsManager.Subscriptions.Count);

            // Remove one of the subscriptions from the publish settings file
            globalSettingsManager.Subscriptions.Remove("TestSubscription1");
            globalSettingsManager.SaveSubscriptions();

            // Load and make sure the subscription is still gone although it still is in the publish settings file
            globalSettingsManager = GlobalSettingsManager.Load(Data.AzureAppDir, outputSubscriptionDataFile);
            Assert.AreEqual(5, globalSettingsManager.Subscriptions.Count);

            // Clean
            globalSettingsManager.DeleteGlobalSettingsManager();
        }