示例#1
0
        public void ProcessNewWebsiteTest()
        {
            const string websiteName  = "website1";
            const string webspaceName = "webspace1";

            // Setup
            bool created = true;
            SimpleWebsitesManagement channel = new SimpleWebsitesManagement();

            channel.GetWebSpacesThunk = ar => new WebSpaces(new List <WebSpace>
            {
                new WebSpace {
                    Name = "webspace1", GeoRegion = "webspace1"
                },
                new WebSpace {
                    Name = "webspace2", GeoRegion = "webspace2"
                }
            });

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

                return(null);
            };

            channel.CreateSiteThunk = ar =>
            {
                Assert.AreEqual(webspaceName, ar.Values["webspaceName"]);
                Site website = ar.Values["site"] as Site;
                Assert.IsNotNull(website);
                Assert.AreEqual(websiteName, website.Name);
                Assert.IsNotNull(website.HostNames.FirstOrDefault(hostname => hostname.Equals(websiteName + General.AzureWebsiteHostNameSuffix)));
                created = true;
                return(website);
            };

            // Test
            MockCommandRuntime     mockRuntime            = new MockCommandRuntime();
            NewAzureWebsiteCommand newAzureWebsiteCommand = new NewAzureWebsiteCommand(channel)
            {
                ShareChannel        = true,
                CommandRuntime      = mockRuntime,
                Name                = websiteName,
                Location            = webspaceName,
                CurrentSubscription = new SubscriptionData {
                    SubscriptionId = base.subscriptionId
                }
            };

            newAzureWebsiteCommand.ExecuteCmdlet();
            Assert.IsTrue(created);
            Assert.AreEqual <string>(websiteName, (mockRuntime.OutputPipeline[0] as SiteWithConfig).Name);
        }
示例#2
0
        public void ProcessNewWebsiteTest()
        {
            const string websiteName  = "website1";
            const string webspaceName = "webspace1";
            const string suffix       = "azurewebsites.com";

            // Setup
            Mock <IWebsitesClient> clientMock = new Mock <IWebsitesClient>();

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

            clientMock.Setup(c => c.GetWebsiteConfiguration("website1"))
            .Returns(new SiteConfig {
                PublishingUsername = "******"
            });

            string createdSiteName     = null;
            string createdWebspaceName = null;

            clientMock.Setup(c => c.CreateWebsite(webspaceName, It.IsAny <SiteWithWebSpace>()))
            .Returns((string space, SiteWithWebSpace site) => site)
            .Callback((string space, SiteWithWebSpace site) =>
            {
                createdSiteName     = site.Name;
                createdWebspaceName = space;
            });

            // Test
            MockCommandRuntime     mockRuntime            = new MockCommandRuntime();
            NewAzureWebsiteCommand newAzureWebsiteCommand = new NewAzureWebsiteCommand
            {
                ShareChannel        = true,
                CommandRuntime      = mockRuntime,
                Name                = websiteName,
                Location            = webspaceName,
                CurrentSubscription = new WindowsAzureSubscription {
                    SubscriptionId = base.subscriptionId
                },
                WebsitesClient = clientMock.Object
            };

            newAzureWebsiteCommand.ExecuteCmdlet();
            Assert.AreEqual(websiteName, createdSiteName);
            Assert.AreEqual(webspaceName, createdWebspaceName);
            Assert.AreEqual <string>(websiteName, (mockRuntime.OutputPipeline[0] as SiteWithConfig).Name);
        }
示例#3
0
        public void CreateStageSlot()
        {
            string       slot         = "staging";
            const string websiteName  = "website1";
            const string webspaceName = "webspace1";
            const string suffix       = "azurewebsites.com";

            // Setup
            Mock <IWebsitesClient> clientMock = new Mock <IWebsitesClient>();

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

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


            clientMock.Setup(f => f.WebsiteExists(websiteName)).Returns(true);
            clientMock.Setup(f => f.GetWebsite(websiteName)).Returns(new Site()
            {
                Name = websiteName, Sku = SkuOptions.Standard, WebSpace = webspaceName
            });

            // Test
            MockCommandRuntime     mockRuntime            = new MockCommandRuntime();
            NewAzureWebsiteCommand newAzureWebsiteCommand = new NewAzureWebsiteCommand
            {
                ShareChannel   = true,
                CommandRuntime = mockRuntime,
                Name           = websiteName,
                Location       = webspaceName,
                WebsitesClient = clientMock.Object,
                Slot           = slot
            };

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

            newAzureWebsiteCommand.ExecuteCmdlet();
            clientMock.Verify(c => c.CreateWebsite(webspaceName, It.IsAny <SiteWithWebSpace>(), slot), Times.Once());
        }
示例#4
0
        public void GetsWebsiteDefaultLocation()
        {
            const string websiteName = "website1";
            const string suffix      = "azurewebsites.com";
            const string location    = "West US";

            // Setup
            Mock <IWebsitesClient> clientMock = new Mock <IWebsitesClient>();

            clientMock.Setup(f => f.GetWebsiteDnsSuffix()).Returns(suffix);
            clientMock.Setup(f => f.GetDefaultLocation()).Returns(location);
            bool created = true;
            SimpleWebsitesManagement channel = new SimpleWebsitesManagement();

            channel.GetWebSpacesThunk = ar => new WebSpaces();

            channel.GetSiteConfigThunk = ar =>
            {
                return(new SiteConfig
                {
                    PublishingUsername = "******"
                });
            };

            channel.CreateSiteThunk = ar =>
            {
                Site website = ar.Values["site"] as Site;
                Assert.IsNotNull(website);
                Assert.AreEqual(websiteName, website.Name);
                Assert.IsNotNull(website.HostNames.FirstOrDefault(hostname => hostname.Equals(string.Format("{0}.{1}", websiteName, suffix))));
                created = true;
                return(website);
            };

            // Test
            MockCommandRuntime     mockRuntime            = new MockCommandRuntime();
            NewAzureWebsiteCommand newAzureWebsiteCommand = new NewAzureWebsiteCommand(channel)
            {
                ShareChannel        = true,
                CommandRuntime      = mockRuntime,
                Name                = websiteName,
                CurrentSubscription = new SubscriptionData {
                    SubscriptionId = base.subscriptionId
                },
                WebsitesClient = clientMock.Object
            };

            newAzureWebsiteCommand.ExecuteCmdlet();
            Assert.IsTrue(created);
            Assert.AreEqual <string>(websiteName, (mockRuntime.OutputPipeline[0] as SiteWithConfig).Name);
            clientMock.Verify(f => f.GetDefaultLocation(), Times.Once());
        }
示例#5
0
        public void GetsWebsiteDefaultLocation()
        {
            const string websiteName = "website1";
            const string suffix      = "azurewebsites.com";
            const string location    = "West US";

            bool created = false;

            // Setup
            Mock <IWebsitesClient> clientMock = new Mock <IWebsitesClient>();

            clientMock.Setup(c => c.GetWebsiteDnsSuffix()).Returns(suffix);
            clientMock.Setup(c => c.GetDefaultLocation()).Returns(location);

            clientMock.Setup(c => c.ListWebSpaces()).Returns(new WebSpaces());
            clientMock.Setup(c => c.GetWebsite(websiteName)).Returns(new Site()
            {
                Name = websiteName
            });
            clientMock.Setup(c => c.GetWebsiteConfiguration(websiteName, null))
            .Returns(new SiteConfig
            {
                PublishingUsername = "******"
            });

            clientMock.Setup(c => c.CreateWebsite(It.IsAny <string>(), It.IsAny <SiteWithWebSpace>(), null))
            .Returns((string space, SiteWithWebSpace site, string slot) => site)
            .Callback((string space, SiteWithWebSpace site, string slot) =>
            {
                created = true;
            });

            // Test
            MockCommandRuntime     mockRuntime            = new MockCommandRuntime();
            NewAzureWebsiteCommand newAzureWebsiteCommand = new NewAzureWebsiteCommand()
            {
                ShareChannel   = true,
                CommandRuntime = mockRuntime,
                Name           = websiteName,
                WebsitesClient = clientMock.Object
            };

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

            newAzureWebsiteCommand.ExecuteCmdlet();
            Assert.True(created);
            Assert.Equal <string>(websiteName, (mockRuntime.OutputPipeline[0] as SiteWithConfig).Name);
            clientMock.Verify(f => f.GetDefaultLocation(), Times.Once());
        }
        public void ProcessNewWebsiteTest()
        {
            const string websiteName = "website1";
            const string webspaceName = "webspace1";
            const string suffix = "azurewebsites.com";

            // Setup
            Mock<IWebsitesClient> clientMock = new Mock<IWebsitesClient>();
            clientMock.Setup(c => c.GetWebsiteDnsSuffix()).Returns(suffix);
            clientMock.Setup(f => f.GetWebsite(websiteName)).Returns(new Site() { Name = websiteName });
            clientMock.Setup(f => f.GetWebsiteConfiguration(websiteName, null)).Returns(new SiteConfig() { PublishingUsername = "******" });
            clientMock.Setup(c => c.ListWebSpaces())
                .Returns(new[]
                {
                    new WebSpace {Name = "webspace1", GeoRegion = "webspace1"},
                    new WebSpace {Name = "webspace2", GeoRegion = "webspace2"}
                });

            clientMock.Setup(c => c.GetWebsiteConfiguration("website1"))
                .Returns(new SiteConfig {PublishingUsername = "******"});

            string createdSiteName = null;
            string createdWebspaceName = null;

            clientMock.Setup(c => c.CreateWebsite(webspaceName, It.IsAny<SiteWithWebSpace>(), null))
                .Returns((string space, SiteWithWebSpace site, string slot) => site)
                .Callback((string space, SiteWithWebSpace site, string slot) =>
                    {
                        createdSiteName = site.Name;
                        createdWebspaceName = space;
                    });

            // Test
            MockCommandRuntime mockRuntime = new MockCommandRuntime();
            NewAzureWebsiteCommand newAzureWebsiteCommand = new NewAzureWebsiteCommand
            {
                ShareChannel = true,
                CommandRuntime = mockRuntime,
                Name = websiteName,
                Location = webspaceName,
                CurrentSubscription = new WindowsAzureSubscription { SubscriptionId = base.subscriptionId },
                WebsitesClient = clientMock.Object
            };

            newAzureWebsiteCommand.ExecuteCmdlet();
            Assert.AreEqual(websiteName, createdSiteName);
            Assert.AreEqual(webspaceName, createdWebspaceName);
            Assert.AreEqual<string>(websiteName, (mockRuntime.OutputPipeline[0] as SiteWithConfig).Name);
        }
        public void ProcessNewWebsiteTest()
        {
            const string websiteName = "website1";
            const string webspaceName = "webspace1";

            // Setup
            bool created = true;
            SimpleWebsitesManagement channel = new SimpleWebsitesManagement();
            channel.GetWebSpacesThunk = ar => new WebSpaces(new List<WebSpace>
            {
                new WebSpace { Name = "webspace1", GeoRegion = "webspace1" },
                new WebSpace { Name = "webspace2", GeoRegion = "webspace2" }
            });

            channel.CreateSiteThunk = ar =>
                                          {
                                              Assert.AreEqual(webspaceName, ar.Values["webspaceName"]);
                                              Site website = ar.Values["site"] as Site;
                                              Assert.IsNotNull(website);
                                              Assert.AreEqual(websiteName, website.Name);
                                              Assert.IsNotNull(website.HostNames.FirstOrDefault(hostname => hostname.Equals(websiteName + General.AzureWebsiteHostNameSuffix)));
                                              created = true;
                                              return website;
                                          };

            // Test
            NewAzureWebsiteCommand newAzureWebsiteCommand = new NewAzureWebsiteCommand(channel)
            {
                ShareChannel = true,
                CommandRuntime = new MockCommandRuntime(),
                Name = websiteName,
                Location = webspaceName,
                CurrentSubscription = new SubscriptionData { SubscriptionId = "NewAzureWebSiteTests_ProcessNewWebsiteTest" }
            };

            newAzureWebsiteCommand.ExecuteCommand();
            Assert.IsTrue(created);
        }
        public void GetsWebsiteDefaultLocation()
        {
            const string websiteName = "website1";
            const string suffix = "azurewebsites.com";
            const string location = "West US";

            bool created = false;

            // Setup
            Mock<IWebsitesClient> clientMock = new Mock<IWebsitesClient>();
            clientMock.Setup(c => c.GetWebsiteDnsSuffix()).Returns(suffix);
            clientMock.Setup(c => c.GetDefaultLocation()).Returns(location);

            clientMock.Setup(c => c.ListWebSpaces()).Returns(new WebSpaces());
            clientMock.Setup(c => c.GetWebsite(websiteName)).Returns(new Site() { Name = websiteName });
            clientMock.Setup(c => c.GetWebsiteConfiguration(websiteName, null))
                .Returns(new SiteConfig
                {
                    PublishingUsername = "******"
                });

            clientMock.Setup(c => c.CreateWebsite(It.IsAny<string>(), It.IsAny<SiteWithWebSpace>(), null))
                .Returns((string space, SiteWithWebSpace site, string slot) => site)
                .Callback((string space, SiteWithWebSpace site, string slot) =>
                    {
                        created = true;
                    });

            // Test
            MockCommandRuntime mockRuntime = new MockCommandRuntime();
            NewAzureWebsiteCommand newAzureWebsiteCommand = new NewAzureWebsiteCommand()
            {
                ShareChannel = true,
                CommandRuntime = mockRuntime,
                Name = websiteName,
                CurrentSubscription = new WindowsAzureSubscription { SubscriptionId = base.subscriptionId },
                WebsitesClient = clientMock.Object
            };

            newAzureWebsiteCommand.ExecuteCmdlet();
            Assert.IsTrue(created);
            Assert.AreEqual<string>(websiteName, (mockRuntime.OutputPipeline[0] as SiteWithConfig).Name);
            clientMock.Verify(f => f.GetDefaultLocation(), Times.Once());
        }
        public void CreateStageSlot()
        {
            string slot = "staging";
            const string websiteName = "website1";
            const string webspaceName = "webspace1";
            const string suffix = "azurewebsites.com";

            // Setup
            Mock<IWebsitesClient> clientMock = new Mock<IWebsitesClient>();
            clientMock.Setup(c => c.GetWebsiteDnsSuffix()).Returns(suffix);
            clientMock.Setup(c => c.ListWebSpaces())
                .Returns(new[]
                {
                    new WebSpace {Name = "webspace1", GeoRegion = "webspace1"},
                    new WebSpace {Name = "webspace2", GeoRegion = "webspace2"}
                });

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


            clientMock.Setup(f => f.WebsiteExists(websiteName)).Returns(true);
            clientMock.Setup(f => f.GetWebsite(websiteName)).Returns(new Site() { Name = websiteName, ComputeMode = WebSiteComputeMode.Dedicated });

            // Test
            MockCommandRuntime mockRuntime = new MockCommandRuntime();
            NewAzureWebsiteCommand newAzureWebsiteCommand = new NewAzureWebsiteCommand
            {
                ShareChannel = true,
                CommandRuntime = mockRuntime,
                Name = websiteName,
                Location = webspaceName,
                CurrentSubscription = new WindowsAzureSubscription { SubscriptionId = base.subscriptionId },
                WebsitesClient = clientMock.Object,
                Slot = slot
            };

            newAzureWebsiteCommand.ExecuteCmdlet();
            clientMock.Verify(c => c.CreateWebsite(webspaceName, It.IsAny<SiteWithWebSpace>(), slot), Times.Once());
        }
        public void ProcessNewWebsiteTest()
        {
            const string websiteName = "website1";
            const string webspaceName = "webspace1";

            // Setup
            bool created = true;
            SimpleWebsitesManagement channel = new SimpleWebsitesManagement();
            channel.GetWebSpacesThunk = ar => new WebSpaces(new List<WebSpace>
            {
                new WebSpace { Name = "webspace1", GeoRegion = "webspace1" },
                new WebSpace { Name = "webspace2", GeoRegion = "webspace2" }
            });

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

                return null;
            };

            channel.CreateSiteThunk = ar =>
                                          {
                                              Assert.AreEqual(webspaceName, ar.Values["webspaceName"]);
                                              Site website = ar.Values["site"] as Site;
                                              Assert.IsNotNull(website);
                                              Assert.AreEqual(websiteName, website.Name);
                                              Assert.IsNotNull(website.HostNames.FirstOrDefault(hostname => hostname.Equals(websiteName + General.AzureWebsiteHostNameSuffix)));
                                              created = true;
                                              return website;
                                          };

            // Test
            MockCommandRuntime mockRuntime = new MockCommandRuntime();
            NewAzureWebsiteCommand newAzureWebsiteCommand = new NewAzureWebsiteCommand(channel)
            {
                ShareChannel = true,
                CommandRuntime = mockRuntime,
                Name = websiteName,
                Location = webspaceName,
                CurrentSubscription = new SubscriptionData { SubscriptionId = base.subscriptionName }
            };

            newAzureWebsiteCommand.ExecuteCmdlet();
            Assert.IsTrue(created);
            Assert.AreEqual<string>(websiteName, (mockRuntime.OutputPipeline[0] as SiteWithConfig).Name);
        }