예제 #1
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);
        }
        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 globalComponents = GlobalComponents.CreateFromPublishSettings(GlobalPathInfo.GlobalSettingsDirectory, targetFile, Data.ValidPublishSettings[i]);

                var removeSubscriptionCommand = new RemoveAzureSubscriptionCommand();
                removeSubscriptionCommand.RemoveSubscriptionProcess("mysub2", targetFile);

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

                // Clean
                globalComponents.DeleteGlobalComponents();
            }
        }
        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 globalComponents = GlobalComponents.CreateFromPublishSettings(GlobalPathInfo.GlobalSettingsDirectory, targetFile, Data.ValidPublishSettings[i]);

                var removeSubscriptionCommand = new RemoveAzureSubscriptionCommand();
                removeSubscriptionCommand.RemoveSubscriptionProcess("mysub2", targetFile);

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

                // Clean
                globalComponents.DeleteGlobalComponents();
            }
        }
예제 #4
0
        public void TestRemoveDefaultSubscriptionProcess()
        {
            for (var i = 0; i < Data.ValidPublishSettings.Count; i++)
            {
                var targetFile = Path.Combine(Directory.GetParent(Data.ValidSubscriptionsData[i]).FullName, "removeonce" + 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("mysub1", targetFile);

                var subscriptionsManager = SubscriptionsManager.Import(targetFile);
                Assert.IsFalse(subscriptionsManager.Subscriptions.Values.Any(subscription => subscription.SubscriptionName == "mysub1"));
                Assert.IsFalse(subscriptionsManager.Subscriptions.Values.Any(subscription => subscription.IsDefault));

                // Clean
                globalSettingsManager.DeleteGlobalSettingsManager();
            }
        }
        public void TestRemoveCurrentSubscriptionProcess()
        {
            for (var i = 0; i < Data.ValidPublishSettings.Count; i++)
            {
                var targetFile = Path.Combine(Directory.GetParent(Data.ValidSubscriptionsData[i]).FullName, "removeonce" + Path.GetFileName(Data.ValidSubscriptionsData[i]));
                File.Copy(Data.ValidSubscriptionsData[i], targetFile, true);
                var globalComponents = GlobalComponents.CreateFromPublishSettings(GlobalPathInfo.GlobalSettingsDirectory, targetFile, Data.ValidPublishSettings[i]);
                MockCommandRuntime mockCommandRuntime = new MockCommandRuntime();

                var removeSubscriptionCommand = new RemoveAzureSubscriptionCommand();
                removeSubscriptionCommand.SetCurrentSubscription(globalComponents.Subscriptions["mysub1"]);
                removeSubscriptionCommand.CommandRuntime = mockCommandRuntime;
                removeSubscriptionCommand.RemoveSubscriptionProcess("mysub1", targetFile);

                var subscriptionsManager = SubscriptionsManager.Import(targetFile);
                Assert.IsFalse(subscriptionsManager.Subscriptions.Values.Any(subscription => subscription.SubscriptionName == "mysub1"));
                Assert.IsFalse(subscriptionsManager.Subscriptions.Values.Any(subscription => subscription.IsDefault));
                Assert.IsNull(removeSubscriptionCommand.GetCurrentSubscription());

                // Clean
                globalComponents.DeleteGlobalComponents();
            }
        }