コード例 #1
0
        public void SetAzureWebsiteProcess()
        {
            const string websiteName  = "website1";
            const string webspaceName = "webspace";
            const string suffix       = "azurewebsites.com";

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

            clientMock.Setup(f => f.GetWebsiteDnsSuffix()).Returns(suffix);

            bool updatedSite       = false;
            bool updatedSiteConfig = false;

            clientMock.Setup(c => c.GetWebsite(websiteName, null))
            .Returns(new Site {
                Name = websiteName, WebSpace = webspaceName
            });
            clientMock.Setup(c => c.GetWebsiteConfiguration(websiteName, null))
            .Returns(new SiteConfig {
                NumberOfWorkers = 1
            });
            clientMock.Setup(c => c.UpdateWebsiteConfiguration(websiteName, It.IsAny <SiteConfig>(), null))
            .Callback((string name, SiteConfig config, string slot) =>
            {
                Assert.NotNull(config);
                Assert.Equal(config.NumberOfWorkers, 3);
                updatedSiteConfig = true;
            }).Verifiable();

            clientMock.Setup(c => c.UpdateWebsiteHostNames(It.IsAny <Site>(), It.IsAny <IEnumerable <string> >(), null))
            .Callback((Site site, IEnumerable <string> names, string slot) =>
            {
                Assert.Equal(websiteName, site.Name);
                Assert.True(names.Any(hostname => hostname.Equals(string.Format("{0}.{1}", websiteName, suffix))));
                Assert.True(names.Any(hostname => hostname.Equals("stuff.com")));
                updatedSite = true;
            });
            clientMock.Setup(f => f.GetHostName(websiteName, null)).Returns(string.Format("{0}.{1}", websiteName, suffix));

            // Test
            SetAzureWebsiteCommand setAzureWebsiteCommand = new SetAzureWebsiteCommand
            {
                CommandRuntime  = new MockCommandRuntime(),
                Name            = websiteName,
                NumberOfWorkers = 3,
                WebsitesClient  = clientMock.Object
            };

            currentProfile = new AzureSMProfile();
            var subscription = new AzureSubscription {
                Id = new Guid(base.subscriptionId)
            };

            subscription.Properties[AzureSubscription.Property.Default] = "True";
            currentProfile.Subscriptions[new Guid(base.subscriptionId)] = subscription;

            setAzureWebsiteCommand.ExecuteCmdlet();
            Assert.True(updatedSiteConfig);
            Assert.False(updatedSite);

            // Test updating site only and not configurations
            updatedSite            = false;
            updatedSiteConfig      = false;
            setAzureWebsiteCommand = new SetAzureWebsiteCommand
            {
                CommandRuntime = new MockCommandRuntime(),
                Name           = websiteName,
                HostNames      = new [] { "stuff.com" },
                WebsitesClient = clientMock.Object
            };
            currentProfile = new AzureSMProfile();
            subscription   = new AzureSubscription {
                Id = new Guid(base.subscriptionId)
            };
            subscription.Properties[AzureSubscription.Property.Default] = "True";
            currentProfile.Subscriptions[new Guid(base.subscriptionId)] = subscription;

            setAzureWebsiteCommand.ExecuteCmdlet();
            Assert.False(updatedSiteConfig);
            Assert.True(updatedSite);
        }
コード例 #2
0
        public void SetAzureWebsiteProcess()
        {
            const string websiteName  = "website1";
            const string webspaceName = "webspace";
            const string suffix       = "azurewebsites.com";

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

            clientMock.Setup(f => f.GetWebsiteDnsSuffix()).Returns(suffix);
            bool updatedSite                 = false;
            bool updatedSiteConfig           = false;
            SimpleWebsitesManagement channel = new SimpleWebsitesManagement();

            Site site = new Site {
                Name = websiteName, WebSpace = webspaceName
            };
            SiteConfig siteConfig = new SiteConfig {
                NumberOfWorkers = 1
            };

            channel.GetWebSpacesThunk = ar => new WebSpaces(new List <WebSpace> {
                new WebSpace {
                    Name = webspaceName
                }
            });
            channel.GetSitesThunk = ar => new Sites(new List <Site> {
                site
            });
            channel.GetSiteThunk          = ar => site;
            channel.GetSiteConfigThunk    = ar => siteConfig;
            channel.UpdateSiteConfigThunk = ar =>
            {
                Assert.AreEqual(webspaceName, ar.Values["webspaceName"]);
                SiteConfig website = ar.Values["siteConfig"] as SiteConfig;
                Assert.IsNotNull(website);
                Assert.AreEqual(website.NumberOfWorkers, 3);
                siteConfig.NumberOfWorkers = website.NumberOfWorkers;
                updatedSiteConfig          = true;
            };

            channel.UpdateSiteThunk = ar =>
            {
                Assert.AreEqual(webspaceName, ar.Values["webspaceName"]);
                Site website = ar.Values["site"] as Site;
                Assert.IsNotNull(website);
                Assert.AreEqual(websiteName, website.Name);
                Assert.IsTrue(website.HostNames.Any(hostname => hostname.Equals(string.Format("{0}.{1}", websiteName, suffix))));
                Assert.IsNotNull(website.HostNames.Any(hostname => hostname.Equals("stuff.com")));
                site.HostNames = website.HostNames;
                updatedSite    = true;
            };

            // Test
            SetAzureWebsiteCommand setAzureWebsiteCommand = new SetAzureWebsiteCommand(channel)
            {
                ShareChannel        = true,
                CommandRuntime      = new MockCommandRuntime(),
                Name                = websiteName,
                CurrentSubscription = new SubscriptionData {
                    SubscriptionId = base.subscriptionId
                },
                NumberOfWorkers = 3,
                WebsitesClient  = clientMock.Object
            };

            setAzureWebsiteCommand.ExecuteCmdlet();
            Assert.IsTrue(updatedSiteConfig);
            Assert.IsFalse(updatedSite);

            // Test updating site only and not configurations
            updatedSite            = false;
            updatedSiteConfig      = false;
            setAzureWebsiteCommand = new SetAzureWebsiteCommand(channel)
            {
                ShareChannel        = true,
                CommandRuntime      = new MockCommandRuntime(),
                Name                = websiteName,
                CurrentSubscription = new SubscriptionData {
                    SubscriptionId = base.subscriptionId
                },
                HostNames      = new [] { "stuff.com" },
                WebsitesClient = clientMock.Object
            };

            setAzureWebsiteCommand.ExecuteCmdlet();
            Assert.IsFalse(updatedSiteConfig);
            Assert.IsTrue(updatedSite);
        }
コード例 #3
0
        public void SetAzureWebsiteProcess()
        {
            const string websiteName = "website1";
            const string webspaceName = "webspace";
            const string suffix = "azurewebsites.com";

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

            bool updatedSite = false;
            bool updatedSiteConfig = false;

            clientMock.Setup(c => c.GetWebsite(websiteName))
                .Returns(new Site {Name = websiteName, WebSpace = webspaceName});
            clientMock.Setup(c => c.GetWebsiteConfiguration(websiteName))
                .Returns(new SiteConfig {NumberOfWorkers = 1});
            clientMock.Setup(c => c.UpdateWebsiteConfiguration(websiteName, It.IsAny<SiteConfig>()))
                .Callback((string name, SiteConfig config) =>
                    {
                        Assert.IsNotNull(config);
                        Assert.AreEqual(config.NumberOfWorkers, 3);
                        updatedSiteConfig = true;
                    }).Verifiable();

            clientMock.Setup(c => c.UpdateWebsiteHostNames(It.IsAny<Site>(), It.IsAny<IEnumerable<string>>()))
                .Callback((Site site, IEnumerable<string> names) =>
                    {
                        Assert.AreEqual(websiteName, site.Name);
                        Assert.IsTrue(names.Any(hostname => hostname.Equals(string.Format("{0}.{1}", websiteName, suffix))));
                        Assert.IsTrue(names.Any(hostname => hostname.Equals("stuff.com")));
                        updatedSite = true;
                    });

            // Test
            SetAzureWebsiteCommand setAzureWebsiteCommand = new SetAzureWebsiteCommand
            {
                CommandRuntime = new MockCommandRuntime(),
                Name = websiteName,
                CurrentSubscription = new WindowsAzureSubscription { SubscriptionId = base.subscriptionId },
                NumberOfWorkers = 3,
                WebsitesClient = clientMock.Object
            };

            setAzureWebsiteCommand.ExecuteCmdlet();
            Assert.IsTrue(updatedSiteConfig);
            Assert.IsFalse(updatedSite);

            // Test updating site only and not configurations
            updatedSite = false;
            updatedSiteConfig = false;
            setAzureWebsiteCommand = new SetAzureWebsiteCommand
            {
                CommandRuntime = new MockCommandRuntime(),
                Name = websiteName,
                CurrentSubscription = new WindowsAzureSubscription { SubscriptionId = base.subscriptionId },
                HostNames = new [] { "stuff.com" },
                WebsitesClient = clientMock.Object
            };

            setAzureWebsiteCommand.ExecuteCmdlet();
            Assert.IsFalse(updatedSiteConfig);
            Assert.IsTrue(updatedSite);
        }
コード例 #4
0
        public void SetAzureWebsiteProcess()
        {
            const string websiteName = "website1";
            const string webspaceName = "webspace";

            // Setup
            bool updatedSite = false;
            bool updatedSiteConfig = false;
            SimpleWebsitesManagement channel = new SimpleWebsitesManagement();

            Site site = new Site {Name = websiteName, WebSpace = webspaceName};
            SiteConfig siteConfig = new SiteConfig { NumberOfWorkers = 1};
            channel.GetWebSpacesThunk = ar => new WebSpaces(new List<WebSpace> { new WebSpace { Name = webspaceName } });
            channel.GetSitesThunk = ar => new Sites(new List<Site> { site });
            channel.GetSiteThunk = ar => site;
            channel.GetSiteConfigThunk = ar => siteConfig;
            channel.UpdateSiteConfigThunk = ar =>
            {
                Assert.AreEqual(webspaceName, ar.Values["webspaceName"]);
                SiteConfig website = ar.Values["siteConfig"] as SiteConfig;
                Assert.IsNotNull(website);
                Assert.AreEqual(website.NumberOfWorkers, 3);
                siteConfig.NumberOfWorkers = website.NumberOfWorkers;
                updatedSiteConfig = true;
            };

            channel.UpdateSiteThunk = ar =>
            {
                Assert.AreEqual(webspaceName, ar.Values["webspaceName"]);
                Site website = ar.Values["site"] as Site;
                Assert.IsNotNull(website);
                Assert.AreEqual(websiteName, website.Name);
                Assert.IsTrue(website.HostNames.Any(hostname => hostname.Equals(websiteName + General.AzureWebsiteHostNameSuffix)));
                Assert.IsNotNull(website.HostNames.Any(hostname => hostname.Equals("stuff.com")));
                site.HostNames = website.HostNames;
                updatedSite = true;
            };

            // Test
            SetAzureWebsiteCommand setAzureWebsiteCommand = new SetAzureWebsiteCommand(channel)
            {
                ShareChannel = true,
                CommandRuntime = new MockCommandRuntime(),
                Name = websiteName,
                CurrentSubscription = new SubscriptionData { SubscriptionId = base.subscriptionName },
                NumberOfWorkers = 3
            };

            setAzureWebsiteCommand.ExecuteCmdlet();
            Assert.IsTrue(updatedSiteConfig);
            Assert.IsFalse(updatedSite);

            // Test updating site only and not configurations
            updatedSite = false;
            updatedSiteConfig = false;
            setAzureWebsiteCommand = new SetAzureWebsiteCommand(channel)
            {
                ShareChannel = true,
                CommandRuntime = new MockCommandRuntime(),
                Name = websiteName,
                CurrentSubscription = new SubscriptionData { SubscriptionId = base.subscriptionName },
                HostNames = new [] { "stuff.com" }
            };

            setAzureWebsiteCommand.ExecuteCmdlet();
            Assert.IsFalse(updatedSiteConfig);
            Assert.IsTrue(updatedSite);
        }
コード例 #5
0
        public void SetsWebsiteSlot()
        {
            const string websiteName  = "website1";
            const string webspaceName = "webspace";
            const string suffix       = "azurewebsites.com";
            const string slot         = "staging";

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

            clientMock.Setup(f => f.GetWebsiteDnsSuffix()).Returns(suffix);

            bool updatedSite       = false;
            bool updatedSiteConfig = false;

            clientMock.Setup(c => c.GetWebsite(websiteName, slot))
            .Returns(new Site {
                Name = websiteName, WebSpace = webspaceName
            });
            clientMock.Setup(c => c.GetWebsiteConfiguration(websiteName, slot))
            .Returns(new SiteConfig {
                NumberOfWorkers = 1
            });
            clientMock.Setup(c => c.UpdateWebsiteConfiguration(websiteName, It.IsAny <SiteConfig>(), slot))
            .Callback((string name, SiteConfig config, string slotName) =>
            {
                Assert.IsNotNull(config);
                Assert.AreEqual(config.NumberOfWorkers, 3);
                updatedSiteConfig = true;
            }).Verifiable();

            clientMock.Setup(c => c.UpdateWebsiteHostNames(It.IsAny <Site>(), It.IsAny <IEnumerable <string> >(), slot))
            .Callback((Site site, IEnumerable <string> names, string slotName) =>
            {
                Assert.AreEqual(websiteName, site.Name);
                Assert.IsTrue(names.Any(hostname => hostname.Equals(string.Format("{0}.{1}", websiteName, suffix))));
                Assert.IsTrue(names.Any(hostname => hostname.Equals("stuff.com")));
                updatedSite = true;
            });
            clientMock.Setup(f => f.GetHostName(websiteName, slot)).Returns(string.Format("{0}.{1}", websiteName, suffix));

            // Test
            SetAzureWebsiteCommand setAzureWebsiteCommand = new SetAzureWebsiteCommand
            {
                CommandRuntime      = new MockCommandRuntime(),
                Name                = websiteName,
                CurrentSubscription = new WindowsAzureSubscription {
                    SubscriptionId = base.subscriptionId
                },
                NumberOfWorkers = 3,
                WebsitesClient  = clientMock.Object,
                Slot            = slot
            };

            setAzureWebsiteCommand.ExecuteCmdlet();
            Assert.IsTrue(updatedSiteConfig);
            Assert.IsFalse(updatedSite);

            // Test updating site only and not configurations
            updatedSite            = false;
            updatedSiteConfig      = false;
            setAzureWebsiteCommand = new SetAzureWebsiteCommand
            {
                CommandRuntime      = new MockCommandRuntime(),
                Name                = websiteName,
                CurrentSubscription = new WindowsAzureSubscription {
                    SubscriptionId = base.subscriptionId
                },
                HostNames      = new[] { "stuff.com" },
                WebsitesClient = clientMock.Object,
                Slot           = slot
            };

            setAzureWebsiteCommand.ExecuteCmdlet();
            Assert.IsFalse(updatedSiteConfig);
            Assert.IsTrue(updatedSite);
        }