public void ProcessGetWebsiteTest()
        {
            // Setup
            var clientMock = new Mock<IWebsitesClient>();
            clientMock.Setup(c => c.ListWebSpaces())
                .Returns(new[] {new WebSpace {Name = "webspace1"}, new WebSpace {Name = "webspace2"}});

            clientMock.Setup(c => c.ListSitesInWebSpace("webspace1"))
                .Returns(new[] {new Site {Name = "website1", WebSpace = "webspace1"}});

            clientMock.Setup(c => c.ListSitesInWebSpace("webspace2"))
                .Returns(new[] {new Site {Name = "website2", WebSpace = "webspace2"}});

            // Test
            var getAzureWebsiteCommand = new GetAzureWebsiteCommand
            {
                CommandRuntime = new MockCommandRuntime(),
                CurrentSubscription = new WindowsAzureSubscription { SubscriptionId = subscriptionId },
                WebsitesClient = clientMock.Object
            };

            getAzureWebsiteCommand.ExecuteCmdlet();
            Assert.AreEqual(1, ((MockCommandRuntime)getAzureWebsiteCommand.CommandRuntime).OutputPipeline.Count);
            var sites = (IEnumerable<Site>)((MockCommandRuntime)getAzureWebsiteCommand.CommandRuntime).OutputPipeline.FirstOrDefault();
            Assert.IsNotNull(sites);
            Assert.IsTrue(sites.Any(website => (website).Name.Equals("website1") && (website).WebSpace.Equals("webspace1")));
            Assert.IsTrue(sites.Any(website => (website).Name.Equals("website2") && (website).WebSpace.Equals("webspace2")));
        }
        public void TestGetAzureWebsiteWithDiagnosticsSettings()
        {
            // Setup
            var websitesClientMock = new Mock <IWebsitesClient>();

            websitesClientMock.Setup(c => c.GetWebsite(It.IsAny <string>()))
            .Returns(new Site
            {
                Name = "website1", WebSpace = "webspace1", State = "Running"
            });

            websitesClientMock.Setup(c => c.GetWebsiteConfiguration(It.IsAny <string>()))
            .Returns(new SiteConfig {
                PublishingUsername = "******"
            });

            var getAzureWebsiteCommand = new GetAzureWebsiteCommand
            {
                CommandRuntime      = new MockCommandRuntime(),
                CurrentSubscription = new WindowsAzureSubscription {
                    SubscriptionId = subscriptionId
                },
                Name           = "website1",
                WebsitesClient = websitesClientMock.Object
            };

            // Test
            getAzureWebsiteCommand.ExecuteCmdlet();

            // Assert
            Assert.AreEqual(1, ((MockCommandRuntime)getAzureWebsiteCommand.CommandRuntime).OutputPipeline.Count);
            websitesClientMock.Verify(f => f.GetApplicationDiagnosticsSettings("website1"), Times.Once());
        }
Пример #3
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);
        }
Пример #4
0
        public void ProcessGetWebsiteTest()
        {
            // Setup
            var clientMock = new Mock <IWebsitesClient>();

            clientMock.Setup(c => c.ListWebSpaces())
            .Returns(new[] { new WebSpace {
                                 Name = "webspace1"
                             }, new WebSpace {
                                 Name = "webspace2"
                             } });

            clientMock.Setup(c => c.ListSitesInWebSpace("webspace1"))
            .Returns(new[] { new Site {
                                 Name = "website1", WebSpace = "webspace1"
                             } });

            clientMock.Setup(c => c.ListSitesInWebSpace("webspace2"))
            .Returns(new[] { new Site {
                                 Name = "website2", WebSpace = "webspace2"
                             } });
            clientMock.Setup(c => c.ListWebsites())
            .Returns(new List <Site> {
                new Site {
                    Name = "website1", WebSpace = "webspace1"
                },
                new Site {
                    Name = "website2", WebSpace = "webspace2"
                }
            });

            // Test
            var getAzureWebsiteCommand = new GetAzureWebsiteCommand
            {
                CommandRuntime = new MockCommandRuntime(),
                WebsitesClient = clientMock.Object
            };

            AzureSession.SetCurrentContext(new AzureSubscription {
                Id = new Guid(subscriptionId)
            }, null, null);

            getAzureWebsiteCommand.ExecuteCmdlet();
            Assert.Equal(1, ((MockCommandRuntime)getAzureWebsiteCommand.CommandRuntime).OutputPipeline.Count);
            var sites = (IEnumerable <Site>)((MockCommandRuntime)getAzureWebsiteCommand.CommandRuntime).OutputPipeline.FirstOrDefault();

            Assert.NotNull(sites);
            Assert.True(sites.Any(website => (website).Name.Equals("website1") && (website).WebSpace.Equals("webspace1")));
            Assert.True(sites.Any(website => (website).Name.Equals("website2") && (website).WebSpace.Equals("webspace2")));
        }
Пример #5
0
        public void ProcessGetWebsiteTest()
        {
            // Setup
            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 = new SubscriptionData {
                    SubscriptionId = base.subscriptionId
                }
            };

            getAzureWebsiteCommand.ExecuteCmdlet();
            Assert.AreEqual(1, ((MockCommandRuntime)getAzureWebsiteCommand.CommandRuntime).OutputPipeline.Count);
            var sites = (IEnumerable <Site>)((MockCommandRuntime)getAzureWebsiteCommand.CommandRuntime).OutputPipeline.FirstOrDefault();

            Assert.IsNotNull(sites);
            Assert.IsTrue(sites.Any(website => (website).Name.Equals("website1") && (website).WebSpace.Equals("webspace1")));
            Assert.IsTrue(sites.Any(website => (website).Name.Equals("website2") && (website).WebSpace.Equals("webspace2")));
        }
Пример #6
0
        public void GetsSlots()
        {
            // Setup
            string slot       = "staging";
            var    clientMock = new Mock <IWebsitesClient>();

            clientMock.Setup(c => c.ListWebsites(slot))
            .Returns(new List <Site> {
                new Site
                {
                    Name     = "website1(stage)",
                    WebSpace = "webspace1"
                }, new Site
                {
                    Name     = "website2(stage)",
                    WebSpace = "webspace1"
                }
            });

            clientMock.Setup(c => c.GetWebsiteConfiguration(It.IsAny <string>(), slot))
            .Returns(new SiteConfig
            {
                PublishingUsername = "******"
            });

            // Test
            var getAzureWebsiteCommand = new GetAzureWebsiteCommand
            {
                CommandRuntime = new MockCommandRuntime(),
                WebsitesClient = clientMock.Object,
                Slot           = slot
            };

            AzureSession.SetCurrentContext(new AzureSubscription {
                Id = new Guid(subscriptionId)
            }, null, null);

            getAzureWebsiteCommand.ExecuteCmdlet();
            IEnumerable <Site> sites = ((MockCommandRuntime)getAzureWebsiteCommand.CommandRuntime).OutputPipeline[0] as IEnumerable <Site>;

            var website1 = sites.ElementAt(0);
            var website2 = sites.ElementAt(1);

            Assert.NotNull(website1);
            Assert.NotNull(website2);
            Assert.Equal("website1(stage)", website1.Name);
            Assert.Equal("website2(stage)", website2.Name);
        }
Пример #7
0
        public void GetsWebsiteSlot()
        {
            // Setup
            string slot       = "staging";
            var    clientMock = new Mock <IWebsitesClient>();

            clientMock.Setup(c => c.GetWebsite(It.IsAny <string>(), slot))
            .Returns(new Site
            {
                Name     = "website1(stage)",
                WebSpace = "webspace1"
            });

            clientMock.Setup(c => c.GetWebsiteConfiguration(It.IsAny <string>()))
            .Returns(new SiteConfig
            {
                PublishingUsername = "******"
            });
            clientMock.Setup(c => c.GetWebsiteConfiguration(It.IsAny <string>(), slot))
            .Returns(new SiteConfig
            {
                PublishingUsername = "******"
            });

            // Test
            var getAzureWebsiteCommand = new GetAzureWebsiteCommand
            {
                CommandRuntime = new MockCommandRuntime(),
                Name           = "website1",
                WebsitesClient = clientMock.Object,
                Slot           = slot
            };

            AzureSession.SetCurrentContext(new AzureSubscription {
                Id = new Guid(subscriptionId)
            }, null, null);

            getAzureWebsiteCommand.ExecuteCmdlet();
            Assert.Equal(1, ((MockCommandRuntime)getAzureWebsiteCommand.CommandRuntime).OutputPipeline.Count);

            var website = ((MockCommandRuntime)getAzureWebsiteCommand.CommandRuntime).OutputPipeline[0] as SiteWithConfig;

            Assert.NotNull(website);
            Assert.Equal("website1(stage)", website.Name);
            Assert.Equal("webspace1", website.WebSpace);
            Assert.Equal("user1", website.PublishingUsername);
        }
Пример #8
0
        public void TestGetAzureWebsiteWithDiagnosticsSettings()
        {
            // Setup
            string slot = "production";
            var    websitesClientMock = new Mock <IWebsitesClient>();

            websitesClientMock.Setup(c => c.GetWebsite(It.IsAny <string>(), slot))
            .Returns(new Site
            {
                Name = "website1", WebSpace = "webspace1", State = "Running"
            });

            websitesClientMock.Setup(c => c.GetWebsiteConfiguration(It.IsAny <string>()))
            .Returns(new SiteConfig {
                PublishingUsername = "******"
            });
            websitesClientMock.Setup(c => c.GetWebsiteConfiguration(It.IsAny <string>(), slot))
            .Returns(new SiteConfig {
                PublishingUsername = "******"
            });

            var getAzureWebsiteCommand = new GetAzureWebsiteCommand
            {
                CommandRuntime = new MockCommandRuntime(),
                Name           = "website1",
                WebsitesClient = websitesClientMock.Object,
                Slot           = slot
            };

            AzureSession.SetCurrentContext(new AzureSubscription {
                Id = new Guid(subscriptionId)
            }, null, null);

            // Test
            getAzureWebsiteCommand.ExecuteCmdlet();

            // Assert
            Assert.Equal(1, ((MockCommandRuntime)getAzureWebsiteCommand.CommandRuntime).OutputPipeline.Count);
            websitesClientMock.Verify(f => f.GetApplicationDiagnosticsSettings("website1"), Times.Once());
        }
        public void TestGetAzureWebsiteWithDiagnosticsSettings()
        {
            // Setup
            var websitesClientMock = new Mock<IWebsitesClient>();
            websitesClientMock.Setup(c => c.GetWebsite(It.IsAny<string>()))
                .Returns(new Site
                {
                    Name = "website1", WebSpace = "webspace1", State = "Running"
                });

            websitesClientMock.Setup(c => c.GetWebsiteConfiguration(It.IsAny<string>()))
                .Returns(new SiteConfig {PublishingUsername = "******"});

            var getAzureWebsiteCommand = new GetAzureWebsiteCommand
            {
                CommandRuntime = new MockCommandRuntime(),
                CurrentSubscription = new WindowsAzureSubscription { SubscriptionId = subscriptionId },
                Name = "website1",
                WebsitesClient = websitesClientMock.Object
            };

            // Test
            getAzureWebsiteCommand.ExecuteCmdlet();

            // Assert
            Assert.AreEqual(1, ((MockCommandRuntime)getAzureWebsiteCommand.CommandRuntime).OutputPipeline.Count);
            websitesClientMock.Verify(f => f.GetApplicationDiagnosticsSettings("website1"), Times.Once());
        }
Пример #10
0
        public void GetWebsiteProcessShowTest()
        {
            // Setup
            SimpleWebsitesManagement channel = new SimpleWebsitesManagement();

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

                return(new Site {
                    Name = "website2", WebSpace = "webspace2"
                });
            };

            channel.GetSiteConfigThunk = ar =>
            {
                if (ar.Values["name"].Equals("website1") && ar.Values["webspaceName"].Equals("webspace1"))
                {
                    return(new SiteConfig
                    {
                        PublishingUsername = "******"
                    });
                }

                return(null);
            };

            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 = new SubscriptionData {
                    SubscriptionId = base.subscriptionId
                },
                Name           = "website1",
                WebsitesClient = new Mock <IWebsitesClient>().Object
            };

            getAzureWebsiteCommand.ExecuteCmdlet();
            Assert.AreEqual(1, ((MockCommandRuntime)getAzureWebsiteCommand.CommandRuntime).OutputPipeline.Count);

            var website = ((MockCommandRuntime)getAzureWebsiteCommand.CommandRuntime).OutputPipeline[0] as SiteWithConfig;

            Assert.IsNotNull(website);
            Assert.IsNotNull(website);
            Assert.AreEqual("website1", website.Name);
            Assert.AreEqual("webspace1", website.WebSpace);
            Assert.AreEqual("user1", website.PublishingUsername);

            // Run with mixed casing
            getAzureWebsiteCommand = new GetAzureWebsiteCommand(channel)
            {
                ShareChannel        = true,
                CommandRuntime      = new MockCommandRuntime(),
                CurrentSubscription = new SubscriptionData {
                    SubscriptionId = "GetAzureWebSiteTests_GetWebsiteProcessShowTest"
                },
                Name           = "WEBSiTe1",
                WebsitesClient = new Mock <IWebsitesClient>().Object
            };

            getAzureWebsiteCommand.ExecuteCmdlet();
            Assert.AreEqual(1, ((MockCommandRuntime)getAzureWebsiteCommand.CommandRuntime).OutputPipeline.Count);

            website = ((MockCommandRuntime)getAzureWebsiteCommand.CommandRuntime).OutputPipeline[0] as SiteWithConfig;
            Assert.IsNotNull(website);
            Assert.IsNotNull(website);
            Assert.AreEqual("website1", website.Name);
            Assert.AreEqual("webspace1", website.WebSpace);
            Assert.AreEqual("user1", website.PublishingUsername);
        }
Пример #11
0
        public void TestGetAzreWebsiteWithDiagnosticsSettings()
        {
            // Setup
            SimpleWebsitesManagement channel = new SimpleWebsitesManagement();

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

                return(new Site {
                    Name = "website2", WebSpace = "webspace2"
                });
            };

            channel.GetSiteConfigThunk = ar =>
            {
                if (ar.Values["name"].Equals("website1") && ar.Values["webspaceName"].Equals("webspace1"))
                {
                    return(new SiteConfig
                    {
                        PublishingUsername = "******"
                    });
                }

                return(null);
            };

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

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

            Mock <IWebsitesClient> websitesClientMock     = new Mock <IWebsitesClient>();
            GetAzureWebsiteCommand getAzureWebsiteCommand = new GetAzureWebsiteCommand(channel)
            {
                ShareChannel        = true,
                CommandRuntime      = new MockCommandRuntime(),
                CurrentSubscription = new SubscriptionData {
                    SubscriptionId = base.subscriptionId
                },
                Name           = "website1",
                WebsitesClient = websitesClientMock.Object
            };

            // Test
            getAzureWebsiteCommand.ExecuteCmdlet();

            // Assert
            Assert.AreEqual(1, ((MockCommandRuntime)getAzureWebsiteCommand.CommandRuntime).OutputPipeline.Count);
            websitesClientMock.Verify(f => f.GetApplicationDiagnosticsSettings("website1"), Times.Once());
        }
        public void GetsSlots()
        {
            // Setup
            string slot = "staging";
            var clientMock = new Mock<IWebsitesClient>();
            clientMock.Setup(c => c.ListWebsites(slot))
                .Returns(new List<Site> {new Site
                {
                    Name = "website1(stage)",
                    WebSpace = "webspace1"
                }, new Site
                {
                    Name = "website2(stage)",
                    WebSpace = "webspace1"
                }});

            clientMock.Setup(c => c.GetWebsiteConfiguration(It.IsAny<string>(), slot))
                .Returns(new SiteConfig
                {
                    PublishingUsername = "******"
                });

            // Test
            var getAzureWebsiteCommand = new GetAzureWebsiteCommand
            {
                CommandRuntime = new MockCommandRuntime(),
                CurrentSubscription = new WindowsAzureSubscription { SubscriptionId = subscriptionId },
                WebsitesClient = clientMock.Object,
                Slot = slot
            };

            getAzureWebsiteCommand.ExecuteCmdlet();
            IEnumerable<Site> sites = ((MockCommandRuntime)getAzureWebsiteCommand.CommandRuntime).OutputPipeline[0] as IEnumerable<Site>;

            var website1 = sites.ElementAt(0);
            var website2 = sites.ElementAt(1);
            Assert.IsNotNull(website1);
            Assert.IsNotNull(website2);
            Assert.AreEqual("website1(stage)", website1.Name);
            Assert.AreEqual("website2(stage)", website2.Name);
        }
        public void GetWebsiteProcessShowTest()
        {
            // Setup
            SimpleWebsitesManagement channel = new SimpleWebsitesManagement();
            channel.GetWebSpacesThunk = ar => new WebSpaces(new List<WebSpace> { new WebSpace { Name = "webspace1" }, new WebSpace { Name = "webspace2" } });
            channel.GetSiteThunk = ar =>
            {
                if (ar.Values["webspaceName"].Equals("webspace1"))
                {
                    return new Site { Name = "website1", WebSpace = "webspace1" };
                }

                return new Site { Name = "website2", WebSpace = "webspace2" };
            };

            channel.GetSiteConfigThunk = ar =>
            {
                if (ar.Values["name"].Equals("website1") && ar.Values["webspaceName"].Equals("webspace1"))
                {
                    return new SiteConfig
                    {
                        PublishingUsername = "******"
                    };
                }

                return null;
            };

            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 = new SubscriptionData { SubscriptionId = base.subscriptionName },
                Name = "website1"
            };

            getAzureWebsiteCommand.ExecuteCmdlet();
            Assert.AreEqual(1, ((MockCommandRuntime)getAzureWebsiteCommand.CommandRuntime).OutputPipeline.Count);

            var website = ((MockCommandRuntime) getAzureWebsiteCommand.CommandRuntime).OutputPipeline[0] as SiteWithConfig;
            Assert.IsNotNull(website);
            Assert.IsNotNull(website);
            Assert.AreEqual("website1", website.Name);
            Assert.AreEqual("webspace1", website.WebSpace);
            Assert.AreEqual("user1", website.PublishingUsername);

            // Run with mixed casing
            getAzureWebsiteCommand = new GetAzureWebsiteCommand(channel)
            {
                ShareChannel = true,
                CommandRuntime = new MockCommandRuntime(),
                CurrentSubscription = new SubscriptionData { SubscriptionId = "GetAzureWebSiteTests_GetWebsiteProcessShowTest" },
                Name = "WEBSiTe1"
            };

            getAzureWebsiteCommand.ExecuteCmdlet();
            Assert.AreEqual(1, ((MockCommandRuntime)getAzureWebsiteCommand.CommandRuntime).OutputPipeline.Count);

            website = ((MockCommandRuntime)getAzureWebsiteCommand.CommandRuntime).OutputPipeline[0] as SiteWithConfig;
            Assert.IsNotNull(website);
            Assert.IsNotNull(website);
            Assert.AreEqual("website1", website.Name);
            Assert.AreEqual("webspace1", website.WebSpace);
            Assert.AreEqual("user1", website.PublishingUsername);
        }
        public void ProcessGetWebsiteWithNullSubscription()
        {
            // Setup
            GlobalComponents globalComponents = GlobalComponents.CreateFromPublishSettings(
                GlobalPathInfo.GlobalSettingsDirectory,
                null,
                Microsoft.WindowsAzure.Management.CloudService.Test.TestData.Data.ValidPublishSettings[0]);
            RemoveAzureSubscriptionCommand removeCmdlet = new RemoveAzureSubscriptionCommand();
            removeCmdlet.CommandRuntime = new MockCommandRuntime();
            ICollection<string> subscriptions = globalComponents.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 ProcessGetWebsiteTest()
        {
            // Setup
            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 = new SubscriptionData { SubscriptionId = base.subscriptionName }
            };

            getAzureWebsiteCommand.ExecuteCmdlet();
            Assert.AreEqual(1, ((MockCommandRuntime)getAzureWebsiteCommand.CommandRuntime).OutputPipeline.Count);
            var sites = (IEnumerable<Site>)((MockCommandRuntime)getAzureWebsiteCommand.CommandRuntime).OutputPipeline.FirstOrDefault();
            Assert.IsNotNull(sites);
            Assert.IsTrue(sites.Any(website => (website).Name.Equals("website1") && (website).WebSpace.Equals("webspace1")));
            Assert.IsTrue(sites.Any(website => (website).Name.Equals("website2") && (website).WebSpace.Equals("webspace2")));
        }
        public void GetWebsiteProcessShowTest()
        {
            // Setup
            var clientMock = new Mock<IWebsitesClient>();
            clientMock.Setup(c => c.GetWebsite(It.IsAny<string>()))
                .Returns(new Site
                {
                    Name = "website1",
                    WebSpace = "webspace1"
                });

            clientMock.Setup(c => c.GetWebsiteConfiguration(It.IsAny<string>()))
                .Returns(new SiteConfig {
                    PublishingUsername = "******"}
                );


            // Test
            var getAzureWebsiteCommand = new GetAzureWebsiteCommand
            {
                CommandRuntime = new MockCommandRuntime(),
                CurrentSubscription = new WindowsAzureSubscription { SubscriptionId = subscriptionId },
                Name = "website1",
                WebsitesClient = clientMock.Object
            };

            getAzureWebsiteCommand.ExecuteCmdlet();
            Assert.AreEqual(1, ((MockCommandRuntime)getAzureWebsiteCommand.CommandRuntime).OutputPipeline.Count);

            var website = ((MockCommandRuntime) getAzureWebsiteCommand.CommandRuntime).OutputPipeline[0] as SiteWithConfig;
            Assert.IsNotNull(website);
            Assert.IsNotNull(website);
            Assert.AreEqual("website1", website.Name);
            Assert.AreEqual("webspace1", website.WebSpace);
            Assert.AreEqual("user1", website.PublishingUsername);

            // Run with mixed casing
            getAzureWebsiteCommand = new GetAzureWebsiteCommand
            {
                CommandRuntime = new MockCommandRuntime(),
                CurrentSubscription = new WindowsAzureSubscription { SubscriptionId = "GetAzureWebSiteTests_GetWebsiteProcessShowTest" },
                Name = "WEBSiTe1",
                WebsitesClient = clientMock.Object
            };

            getAzureWebsiteCommand.ExecuteCmdlet();
            Assert.AreEqual(1, ((MockCommandRuntime)getAzureWebsiteCommand.CommandRuntime).OutputPipeline.Count);

            website = ((MockCommandRuntime)getAzureWebsiteCommand.CommandRuntime).OutputPipeline[0] as SiteWithConfig;
            Assert.IsNotNull(website);
            Assert.IsNotNull(website);
            Assert.AreEqual("website1", website.Name);
            Assert.AreEqual("webspace1", website.WebSpace);
            Assert.AreEqual("user1", website.PublishingUsername);
        }
        public void GetWebsiteProcessShowTest()
        {
            // Setup
            var clientMock = new Mock <IWebsitesClient>();

            clientMock.Setup(c => c.GetWebsiteSlots(It.IsAny <string>()))
            .Returns(new Sites()
            {
                new Site
                {
                    Name     = "website1",
                    WebSpace = "webspace1"
                }
            });

            clientMock.Setup(c => c.GetWebsiteConfiguration(It.IsAny <string>()))
            .Returns(new SiteConfig
            {
                PublishingUsername = "******"
            }
                     );
            clientMock.Setup(c => c.GetWebsiteConfiguration(It.IsAny <string>(), null))
            .Returns(new SiteConfig {
                PublishingUsername = "******"
            }
                     );


            // Test
            var getAzureWebsiteCommand = new GetAzureWebsiteCommand
            {
                CommandRuntime      = new MockCommandRuntime(),
                CurrentSubscription = new WindowsAzureSubscription {
                    SubscriptionId = subscriptionId
                },
                Name           = "website1",
                WebsitesClient = clientMock.Object
            };

            getAzureWebsiteCommand.ExecuteCmdlet();
            Assert.AreEqual(1, ((MockCommandRuntime)getAzureWebsiteCommand.CommandRuntime).OutputPipeline.Count);

            SiteWithConfig website = ((MockCommandRuntime)getAzureWebsiteCommand.CommandRuntime).OutputPipeline[0] as SiteWithConfig;

            Assert.IsNotNull(website);
            Assert.IsNotNull(website);
            Assert.AreEqual("website1", website.Name);
            Assert.AreEqual("webspace1", website.WebSpace);

            // Run with mixed casing
            getAzureWebsiteCommand = new GetAzureWebsiteCommand
            {
                CommandRuntime      = new MockCommandRuntime(),
                CurrentSubscription = new WindowsAzureSubscription {
                    SubscriptionId = "GetAzureWebSiteTests_GetWebsiteProcessShowTest"
                },
                Name           = "WEBSiTe1",
                WebsitesClient = clientMock.Object
            };

            getAzureWebsiteCommand.ExecuteCmdlet();
            Assert.AreEqual(1, ((MockCommandRuntime)getAzureWebsiteCommand.CommandRuntime).OutputPipeline.Count);

            website = ((MockCommandRuntime)getAzureWebsiteCommand.CommandRuntime).OutputPipeline[0] as SiteWithConfig;
            Assert.IsNotNull(website);
            Assert.IsNotNull(website);
            Assert.AreEqual("website1", website.Name);
            Assert.AreEqual("webspace1", website.WebSpace);
        }
        public void GetsWebsiteSlot()
        {
            // Setup
            string slot = "staging";
            var clientMock = new Mock<IWebsitesClient>();
            clientMock.Setup(c => c.GetWebsite(It.IsAny<string>(), slot))
                .Returns(new Site
                {
                    Name = "website1(stage)",
                    WebSpace = "webspace1"
                });

            clientMock.Setup(c => c.GetWebsiteConfiguration(It.IsAny<string>()))
                .Returns(new SiteConfig
                {
                    PublishingUsername = "******"
                });
            clientMock.Setup(c => c.GetWebsiteConfiguration(It.IsAny<string>(), slot))
                .Returns(new SiteConfig
                {
                    PublishingUsername = "******"
                });

            // Test
            var getAzureWebsiteCommand = new GetAzureWebsiteCommand
            {
                CommandRuntime = new MockCommandRuntime(),
                CurrentSubscription = new WindowsAzureSubscription { SubscriptionId = subscriptionId },
                Name = "website1",
                WebsitesClient = clientMock.Object,
                Slot = slot
            };

            getAzureWebsiteCommand.ExecuteCmdlet();
            Assert.AreEqual(1, ((MockCommandRuntime)getAzureWebsiteCommand.CommandRuntime).OutputPipeline.Count);

            var website = ((MockCommandRuntime)getAzureWebsiteCommand.CommandRuntime).OutputPipeline[0] as SiteWithConfig;
            Assert.IsNotNull(website);
            Assert.AreEqual("website1(stage)", website.Name);
            Assert.AreEqual("webspace1", website.WebSpace);
            Assert.AreEqual("user1", website.PublishingUsername);
        }