Exemple #1
0
        public void GetsSlots()
        {
            AzureSessionInitializer.InitializeAzureSession();
            ServiceManagementProfileProvider.InitializeServiceManagementProfile();
            // 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 = "******"
            });

            SetupProfile(null);

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

            getAzureWebsiteCommand.ExecuteWithProcessing();

            IEnumerable <Site> sites = System.Management.Automation.LanguagePrimitives.GetEnumerable(((MockCommandRuntime)getAzureWebsiteCommand.CommandRuntime).OutputPipeline).Cast <Site>();

            Assert.NotNull(sites);
            Assert.NotEmpty(sites);
            Assert.Equal(2, sites.Count());
            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);
        }
        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"
                }
            });

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

            getAzureWebsiteCommand.ExecuteWithProcessing();

            var sites = System.Management.Automation.LanguagePrimitives.GetEnumerable(((MockCommandRuntime)getAzureWebsiteCommand.CommandRuntime).OutputPipeline).Cast <Site>();

            Assert.NotNull(sites);
            Assert.NotEmpty(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")));
        }
        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"
                }
            });

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

            getAzureWebsiteCommand.ExecuteWithProcessing();
            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")));
        }
        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 = "******"
            });

            SetupProfile(null);

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

            getAzureWebsiteCommand.ExecuteWithProcessing();
            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);
        }
        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 = "******"
            });

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

            getAzureWebsiteCommand.ExecuteWithProcessing();
            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);
        }
        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 = "******"
            });

            SetupProfile(null);

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

            // Test
            getAzureWebsiteCommand.ExecuteWithProcessing();

            // Assert
            Assert.Equal(1, ((MockCommandRuntime)getAzureWebsiteCommand.CommandRuntime).OutputPipeline.Count);
            websitesClientMock.Verify(f => f.GetApplicationDiagnosticsSettings("website1"), Times.Once());
        }
        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 = "******"
            }
                     );

            SetupProfile(null);

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

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

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

            Assert.NotNull(website);
            Assert.NotNull(website);
            Assert.Equal("website1", website.Name);
            Assert.Equal("webspace1", website.WebSpace);

            SetupProfile(null);

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

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

            website = ((MockCommandRuntime)getAzureWebsiteCommand.CommandRuntime).OutputPipeline[0] as SiteWithConfig;
            Assert.NotNull(website);
            Assert.NotNull(website);
            Assert.Equal("website1", website.Name);
            Assert.Equal("webspace1", website.WebSpace);
        }