Inheritance: Microsoft.WindowsAzure.Commands.Utilities.Websites.Common.WebsiteContextBaseCmdlet, IGithubCmdlet
        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;
                });

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

            newAzureWebsiteCommand.ExecuteWithProcessing();
            Assert.Equal(websiteName, createdSiteName);
            Assert.Equal(webspaceName, createdWebspaceName);
            Assert.Equal<string>(websiteName, (mockRuntime.OutputPipeline[0] as SiteWithConfig).Name);
        }
        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());
        }
        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;
                });

            SetupProfile(null);

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

            newAzureWebsiteCommand.ExecuteWithProcessing();
            Assert.True(created);
            Assert.Equal<string>(websiteName, (mockRuntime.OutputPipeline[0] as SiteWithConfig).Name);
            clientMock.Verify(f => f.GetDefaultLocation(), Times.Once());
        }