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); }
public void ProcessStopWebsiteTest() { const string websiteName = "website1"; const string webspaceName = "webspace"; // Setup bool updated = true; SimpleWebsitesManagement channel = new SimpleWebsitesManagement(); channel.GetWebSpacesThunk = ar => new WebSpaces(new List<WebSpace> { new WebSpace { Name = webspaceName } }); channel.GetSitesThunk = ar => new Sites(new List<Site> { new Site { Name = websiteName, WebSpace = webspaceName } }); 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.IsNotNull(website.HostNames.FirstOrDefault(hostname => hostname.Equals(websiteName + General.AzureWebsiteHostNameSuffix))); Assert.AreEqual(website.State, "Stopped"); updated = true; }; // Test StopAzureWebsiteCommand stopAzureWebsiteCommand = new StopAzureWebsiteCommand(channel) { ShareChannel = true, CommandRuntime = new MockCommandRuntime(), Name = websiteName, CurrentSubscription = new SubscriptionData { SubscriptionId = "StopAzureWebSiteTests_ProcessStopWebsiteTest" } }; stopAzureWebsiteCommand.ExecuteCommand(); Assert.IsTrue(updated); }
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 = "GetAzureWebSiteTests_GetWebsiteProcessShowTest" }, Name = "website1" }; getAzureWebsiteCommand.ExecuteCommand(); Assert.AreEqual(2, ((MockCommandRuntime)getAzureWebsiteCommand.CommandRuntime).WrittenObjects.Count); var website = ((MockCommandRuntime) getAzureWebsiteCommand.CommandRuntime).WrittenObjects[0] as Site; var websiteConfig = ((MockCommandRuntime)getAzureWebsiteCommand.CommandRuntime).WrittenObjects[1] as SiteConfig; Assert.IsNotNull(website); Assert.IsNotNull(websiteConfig); Assert.AreEqual("website1", website.Name); Assert.AreEqual("webspace1", website.WebSpace); Assert.AreEqual("user1", websiteConfig.PublishingUsername); }
public void ProcessShowWebsiteTest() { // 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", HostNames = new [] { "website1.cloudapp.com" } } })); } return(new Sites(new List <Site> { new Site { Name = "website2", WebSpace = "webspace2", HostNames = new[] { "website2.cloudapp.com" } } })); }; channel.GetSiteConfigThunk = ar => { if (ar.Values["name"].Equals("website1") && ar.Values["webspaceName"].Equals("webspace1")) { return(new SiteConfig { PublishingUsername = "******" }); } return(null); }; // Test ShowAzureWebsiteCommand showAzureWebsiteCommand = new ShowAzureWebsiteCommand(channel) { ShareChannel = true, CommandRuntime = new MockCommandRuntime(), Name = "website1", CurrentSubscription = new SubscriptionData { SubscriptionId = base.subscriptionId } }; // Show existing website showAzureWebsiteCommand.ExecuteCmdlet(); }
public void ProcessRemoveWebsiteTest() { // Setup bool deletedWebsite = false; 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.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" } }); }; channel.DeleteSiteThunk = ar => { if (ar.Values["name"].Equals("website1")) { deletedWebsite = true; } }; // Test RemoveAzureWebsiteCommand removeAzureWebsiteCommand = new RemoveAzureWebsiteCommand(channel) { ShareChannel = true, CommandRuntime = new MockCommandRuntime(), Name = "website1", CurrentSubscription = new SubscriptionData { SubscriptionId = base.subscriptionName } }; // Delete existing website removeAzureWebsiteCommand.ExecuteCmdlet(); Assert.IsTrue(deletedWebsite); // Delete unexisting website deletedWebsite = false; removeAzureWebsiteCommand.Name = "website2"; removeAzureWebsiteCommand.ExecuteCmdlet(); Assert.IsFalse(deletedWebsite); }
public void GetAzureWebsiteDeploymentLogsTest() { // 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", SiteProperties = new SiteProperties { Properties = new List<NameValuePair> { new NameValuePair { Name = "repositoryuri", Value = "http" }, new NameValuePair { Name = "PublishingUsername", Value = "user1" }, new NameValuePair { Name = "PublishingPassword", Value = "password1" } } }} }); } return new Sites(new List<Site> { new Site { Name = "website2", WebSpace = "webspace2" } }); }; SimpleDeploymentServiceManagement deploymentChannel = new SimpleDeploymentServiceManagement(); deploymentChannel.GetDeploymentsThunk = ar => new List<DeployResult> { new DeployResult { Id = "commit1" }, new DeployResult { Id = "commit2" } }; deploymentChannel.GetDeploymentLogsThunk = ar => { if (ar.Values["commitId"].Equals("commit1")) { return new List<LogEntry> { new LogEntry { Id = "log1" }, new LogEntry { Id = "log2" } }; } return new List<LogEntry>(); }; // Test GetAzureWebsiteDeploymentCommand getAzureWebsiteDeploymentCommand = new GetAzureWebsiteDeploymentCommand(channel, deploymentChannel) { Name = "website1", ShareChannel = true, Details = true, CommandRuntime = new MockCommandRuntime(), CurrentSubscription = new SubscriptionData { SubscriptionId = base.subscriptionName } }; getAzureWebsiteDeploymentCommand.ExecuteCmdlet(); Assert.AreEqual(1, ((MockCommandRuntime)getAzureWebsiteDeploymentCommand.CommandRuntime).OutputPipeline.Count); var deployments = (IEnumerable<DeployResult>)((MockCommandRuntime)getAzureWebsiteDeploymentCommand.CommandRuntime).OutputPipeline.FirstOrDefault(); Assert.IsNotNull(deployments); Assert.AreEqual(2, deployments.Count()); Assert.IsNotNull(deployments.First(d => d.Id.Equals("commit1")).Logs); }
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); }
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); }
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()); }
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"))); }
public void SaveAzureWebsiteLogTest() { // 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", SiteProperties = new SiteProperties { Properties = new List<NameValuePair> { new NameValuePair { Name = "repositoryuri", Value = "http" }, new NameValuePair { Name = "PublishingUsername", Value = "user1" }, new NameValuePair { Name = "PublishingPassword", Value = "password1" } } }} }); } return new Sites(new List<Site> { new Site { Name = "website2", WebSpace = "webspace2" } }); }; SimpleDeploymentServiceManagement deploymentChannel = new SimpleDeploymentServiceManagement { DownloadLogsThunk = ar => new MemoryStream(Encoding.UTF8.GetBytes("test")) }; // Test SaveAzureWebsiteLogCommand getAzureWebsiteLogCommand = new SaveAzureWebsiteLogCommand(channel, deploymentChannel) { Name = "website1", ShareChannel = true, CommandRuntime = new MockCommandRuntime(), CurrentSubscription = new SubscriptionData { SubscriptionId = base.subscriptionName } }; getAzureWebsiteLogCommand.DefaultCurrentPath = ""; getAzureWebsiteLogCommand.ExecuteCmdlet(); Assert.AreEqual("test", File.ReadAllText(SaveAzureWebsiteLogCommand.DefaultOutput)); }
public void ProcessGetAzureWebsiteLocationTest() { // Setup SimpleWebsitesManagement channel = new SimpleWebsitesManagement(); // Test GetAzureWebsiteLocationCommand getAzureWebsiteCommand = new GetAzureWebsiteLocationCommand(channel) { ShareChannel = true, CommandRuntime = new MockCommandRuntime() }; getAzureWebsiteCommand.ExecuteCommand(); Assert.AreEqual(1, ((MockCommandRuntime)getAzureWebsiteCommand.CommandRuntime).WrittenObjects.Count); var locations = (IEnumerable<string>)((MockCommandRuntime)getAzureWebsiteCommand.CommandRuntime).WrittenObjects.FirstOrDefault(); Assert.IsNotNull(locations); Assert.IsTrue(locations.Any(loc => loc.Equals("East US"))); Assert.IsTrue(locations.Any(loc => loc.Equals("West US"))); Assert.IsTrue(locations.Any(loc => loc.Equals("North Europe"))); Assert.IsTrue(locations.Any(loc => loc.Equals("West Europe"))); }
public void ProcessShowWebsiteTest() { // 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", HostNames = new [] {"website1.cloudapp.com" } } }); } return new Sites(new List<Site> { new Site { Name = "website2", WebSpace = "webspace2", HostNames = new[] { "website2.cloudapp.com" } } }); }; channel.GetSiteConfigThunk = ar => { if (ar.Values["name"].Equals("website1") && ar.Values["webspaceName"].Equals("webspace1")) { return new SiteConfig { PublishingUsername = "******" }; } return null; }; // Test ShowAzureWebsiteCommand showAzureWebsiteCommand = new ShowAzureWebsiteCommand(channel) { ShareChannel = true, CommandRuntime = new MockCommandRuntime(), Name = "website1", CurrentSubscription = new SubscriptionData { SubscriptionId = base.subscriptionName } }; // Show existing website showAzureWebsiteCommand.ExecuteCmdlet(); }
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 ProcessGetAzureWebsiteLocationTest() { // Setup SimpleWebsitesManagement channel = new SimpleWebsitesManagement(); // Test GetAzureWebsiteLocationCommand getAzureWebsiteCommand = new GetAzureWebsiteLocationCommand(channel) { ShareChannel = true, CommandRuntime = new MockCommandRuntime() }; getAzureWebsiteCommand.ExecuteCmdlet(); Assert.AreEqual(1, ((MockCommandRuntime)getAzureWebsiteCommand.CommandRuntime).OutputPipeline.Count); var locations = (IEnumerable <string>)((MockCommandRuntime)getAzureWebsiteCommand.CommandRuntime).OutputPipeline.FirstOrDefault(); Assert.IsNotNull(locations); Assert.IsTrue(locations.Any(loc => loc.Equals("East US"))); Assert.IsTrue(locations.Any(loc => loc.Equals("West US"))); Assert.IsTrue(locations.Any(loc => loc.Equals("North Europe"))); Assert.IsTrue(locations.Any(loc => loc.Equals("West Europe"))); Assert.IsTrue(locations.Any(loc => loc.Equals("East Asia"))); }
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); }
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); }
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); }
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 GetAzureWebsiteDeploymentTest() { // 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", SiteProperties = new SiteProperties { Properties = new List <NameValuePair> { new NameValuePair { Name = "repositoryuri", Value = "http" }, new NameValuePair { Name = "PublishingUsername", Value = "user1" }, new NameValuePair { Name = "PublishingPassword", Value = "password1" } } } } })); } return(new Sites(new List <Site> { new Site { Name = "website2", WebSpace = "webspace2" } })); }; SimpleDeploymentServiceManagement deploymentChannel = new SimpleDeploymentServiceManagement(); deploymentChannel.GetDeploymentsThunk = ar => new List <DeployResult> { new DeployResult(), new DeployResult() }; // Test GetAzureWebsiteDeploymentCommand getAzureWebsiteDeploymentCommand = new GetAzureWebsiteDeploymentCommand(channel, deploymentChannel) { Name = "website1", ShareChannel = true, CommandRuntime = new MockCommandRuntime(), CurrentSubscription = new SubscriptionData { SubscriptionId = base.subscriptionId } }; getAzureWebsiteDeploymentCommand.ExecuteCmdlet(); Assert.AreEqual(1, ((MockCommandRuntime)getAzureWebsiteDeploymentCommand.CommandRuntime).OutputPipeline.Count); var deployments = (IEnumerable <DeployResult>)((MockCommandRuntime)getAzureWebsiteDeploymentCommand.CommandRuntime).OutputPipeline.FirstOrDefault(); Assert.IsNotNull(deployments); Assert.AreEqual(2, deployments.Count()); }
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 SaveAzureWebsiteLogWithNoFileExtensionTest() { // Setup SimpleWebsitesManagement channel = new SimpleWebsitesManagement(); string expectedOutput = "file_without_ext.zip"; 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", SiteProperties = new SiteProperties { Properties = new List <NameValuePair> { new NameValuePair { Name = "repositoryuri", Value = "http" }, new NameValuePair { Name = "PublishingUsername", Value = "user1" }, new NameValuePair { Name = "PublishingPassword", Value = "password1" } } } } })); } return(new Sites(new List <Site> { new Site { Name = "website2", WebSpace = "webspace2" } })); }; SimpleDeploymentServiceManagement deploymentChannel = new SimpleDeploymentServiceManagement { DownloadLogsThunk = ar => new MemoryStream(Encoding.UTF8.GetBytes("test with no extnsion")) }; // Test SaveAzureWebsiteLogCommand getAzureWebsiteLogCommand = new SaveAzureWebsiteLogCommand(channel, deploymentChannel) { Name = "website1", ShareChannel = true, CommandRuntime = new MockCommandRuntime(), CurrentSubscription = new SubscriptionData { SubscriptionId = base.subscriptionId }, Output = "file_without_ext" }; getAzureWebsiteLogCommand.DefaultCurrentPath = ""; getAzureWebsiteLogCommand.ExecuteCmdlet(); Assert.AreEqual("test with no extnsion", File.ReadAllText(expectedOutput)); }
public void GetAzureWebsiteDeploymentTest() { // 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", SiteProperties = new SiteProperties { Properties = new List<NameValuePair> { new NameValuePair { Name = "repositoryuri", Value = "http" }, new NameValuePair { Name = "PublishingUsername", Value = "user1" }, new NameValuePair { Name = "PublishingPassword", Value = "password1" } } }} }); } return new Sites(new List<Site> { new Site { Name = "website2", WebSpace = "webspace2" } }); }; SimpleDeploymentServiceManagement deploymentChannel = new SimpleDeploymentServiceManagement(); deploymentChannel.GetDeploymentsThunk = ar => new List<DeployResult> { new DeployResult(), new DeployResult() }; // Test GetAzureWebsiteDeploymentCommand getAzureWebsiteDeploymentCommand = new GetAzureWebsiteDeploymentCommand(channel, deploymentChannel) { Name = "website1", ShareChannel = true, CommandRuntime = new MockCommandRuntime(), CurrentSubscription = new SubscriptionData { SubscriptionId = "GetAzureWebsiteDeploymentTests_GetAzureWebsiteDeploymentTest" } }; getAzureWebsiteDeploymentCommand.ExecuteCommand(); Assert.AreEqual(1, ((MockCommandRuntime)getAzureWebsiteDeploymentCommand.CommandRuntime).WrittenObjects.Count); var deployments = (IEnumerable<DeployResult>)((MockCommandRuntime)getAzureWebsiteDeploymentCommand.CommandRuntime).WrittenObjects.FirstOrDefault(); Assert.IsNotNull(deployments); Assert.AreEqual(2, deployments.Count()); }
public void RestoreAzureWebsiteDeploymentTest() { // 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", SiteProperties = new SiteProperties { Properties = new List<NameValuePair> { new NameValuePair { Name = "repositoryuri", Value = "http" }, new NameValuePair { Name = "PublishingUsername", Value = "user1" }, new NameValuePair { Name = "PublishingPassword", Value = "password1" } } }} }); } return new Sites(new List<Site> { new Site { Name = "website2", WebSpace = "webspace2" } }); }; SimpleDeploymentServiceManagement deploymentChannel = new SimpleDeploymentServiceManagement(); var deployments = new List<DeployResult> { new DeployResult { Id = "id1", Current = false }, new DeployResult { Id = "id2", Current = true } }; deploymentChannel.GetDeploymentsThunk = ar => deployments; deploymentChannel.DeployThunk = ar => { // Keep track of currently deployed id DeployResult newDeployment = deployments.FirstOrDefault(d => d.Id.Equals(ar.Values["commitId"])); if (newDeployment != null) { // Make all inactive deployments.ForEach(d => d.Complete = false); // Set new to active newDeployment.Complete = true; } }; // Test RestoreAzureWebsiteDeploymentCommand restoreAzureWebsiteDeploymentCommand = new RestoreAzureWebsiteDeploymentCommand(channel, deploymentChannel) { Name = "website1", CommitId = "id2", ShareChannel = true, CommandRuntime = new MockCommandRuntime(), CurrentSubscription = new SubscriptionData { SubscriptionId = base.subscriptionName } }; restoreAzureWebsiteDeploymentCommand.ExecuteCmdlet(); Assert.AreEqual(1, ((MockCommandRuntime) restoreAzureWebsiteDeploymentCommand.CommandRuntime).OutputPipeline.Count); var responseDeployments = (IEnumerable<DeployResult>)((MockCommandRuntime) restoreAzureWebsiteDeploymentCommand.CommandRuntime).OutputPipeline.FirstOrDefault(); Assert.IsNotNull(responseDeployments); Assert.AreEqual(2, responseDeployments.Count()); Assert.IsTrue(responseDeployments.Any(d => d.Id.Equals("id2") && d.Complete)); Assert.IsTrue(responseDeployments.Any(d => d.Id.Equals("id1") && !d.Complete)); // Change active deployment to id1 restoreAzureWebsiteDeploymentCommand = new RestoreAzureWebsiteDeploymentCommand(channel, deploymentChannel) { Name = "website1", CommitId = "id1", ShareChannel = true, CommandRuntime = new MockCommandRuntime(), CurrentSubscription = new SubscriptionData { SubscriptionId = base.subscriptionName } }; restoreAzureWebsiteDeploymentCommand.ExecuteCmdlet(); Assert.AreEqual(1, ((MockCommandRuntime)restoreAzureWebsiteDeploymentCommand.CommandRuntime).OutputPipeline.Count); responseDeployments = (IEnumerable<DeployResult>)((MockCommandRuntime)restoreAzureWebsiteDeploymentCommand.CommandRuntime).OutputPipeline.FirstOrDefault(); Assert.IsNotNull(responseDeployments); Assert.AreEqual(2, responseDeployments.Count()); Assert.IsTrue(responseDeployments.Any(d => d.Id.Equals("id1") && d.Complete)); Assert.IsTrue(responseDeployments.Any(d => d.Id.Equals("id2") && !d.Complete)); }
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 RestoreAzureWebsiteDeploymentTest() { // 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", SiteProperties = new SiteProperties { Properties = new List <NameValuePair> { new NameValuePair { Name = "repositoryuri", Value = "http" }, new NameValuePair { Name = "PublishingUsername", Value = "user1" }, new NameValuePair { Name = "PublishingPassword", Value = "password1" } } } } })); } return(new Sites(new List <Site> { new Site { Name = "website2", WebSpace = "webspace2" } })); }; SimpleDeploymentServiceManagement deploymentChannel = new SimpleDeploymentServiceManagement(); var deployments = new List <DeployResult> { new DeployResult { Id = "id1", Current = false }, new DeployResult { Id = "id2", Current = true } }; deploymentChannel.GetDeploymentsThunk = ar => deployments; deploymentChannel.DeployThunk = ar => { // Keep track of currently deployed id DeployResult newDeployment = deployments.FirstOrDefault(d => d.Id.Equals(ar.Values["commitId"])); if (newDeployment != null) { // Make all inactive deployments.ForEach(d => d.Complete = false); // Set new to active newDeployment.Complete = true; } }; // Test RestoreAzureWebsiteDeploymentCommand restoreAzureWebsiteDeploymentCommand = new RestoreAzureWebsiteDeploymentCommand(channel, deploymentChannel) { Name = "website1", CommitId = "id2", ShareChannel = true, CommandRuntime = new MockCommandRuntime(), CurrentSubscription = new SubscriptionData { SubscriptionId = base.subscriptionId } }; restoreAzureWebsiteDeploymentCommand.ExecuteCmdlet(); Assert.AreEqual(1, ((MockCommandRuntime)restoreAzureWebsiteDeploymentCommand.CommandRuntime).OutputPipeline.Count); var responseDeployments = (IEnumerable <DeployResult>)((MockCommandRuntime)restoreAzureWebsiteDeploymentCommand.CommandRuntime).OutputPipeline.FirstOrDefault(); Assert.IsNotNull(responseDeployments); Assert.AreEqual(2, responseDeployments.Count()); Assert.IsTrue(responseDeployments.Any(d => d.Id.Equals("id2") && d.Complete)); Assert.IsTrue(responseDeployments.Any(d => d.Id.Equals("id1") && !d.Complete)); // Change active deployment to id1 restoreAzureWebsiteDeploymentCommand = new RestoreAzureWebsiteDeploymentCommand(channel, deploymentChannel) { Name = "website1", CommitId = "id1", ShareChannel = true, CommandRuntime = new MockCommandRuntime(), CurrentSubscription = new SubscriptionData { SubscriptionId = base.subscriptionId } }; restoreAzureWebsiteDeploymentCommand.ExecuteCmdlet(); Assert.AreEqual(1, ((MockCommandRuntime)restoreAzureWebsiteDeploymentCommand.CommandRuntime).OutputPipeline.Count); responseDeployments = (IEnumerable <DeployResult>)((MockCommandRuntime)restoreAzureWebsiteDeploymentCommand.CommandRuntime).OutputPipeline.FirstOrDefault(); Assert.IsNotNull(responseDeployments); Assert.AreEqual(2, responseDeployments.Count()); Assert.IsTrue(responseDeployments.Any(d => d.Id.Equals("id1") && d.Complete)); Assert.IsTrue(responseDeployments.Any(d => d.Id.Equals("id2") && !d.Complete)); }
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 = "GetAzureWebSiteTests_ProcessGetWebsiteTest" } }; getAzureWebsiteCommand.ExecuteCommand(); Assert.AreEqual(1, ((MockCommandRuntime)getAzureWebsiteCommand.CommandRuntime).WrittenObjects.Count); var sites = (IEnumerable<Site>)((MockCommandRuntime)getAzureWebsiteCommand.CommandRuntime).WrittenObjects.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 ProcessRemoveWebsiteTest() { // Setup bool deletedWebsite = false; 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.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" } })); }; channel.DeleteSiteThunk = ar => { if (ar.Values["name"].Equals("website1")) { deletedWebsite = true; } }; // Test RemoveAzureWebsiteCommand removeAzureWebsiteCommand = new RemoveAzureWebsiteCommand(channel) { ShareChannel = true, CommandRuntime = new MockCommandRuntime(), Name = "website1", CurrentSubscription = new SubscriptionData { SubscriptionId = base.subscriptionId } }; // Delete existing website removeAzureWebsiteCommand.ExecuteCmdlet(); Assert.IsTrue(deletedWebsite); // Delete unexisting website deletedWebsite = false; removeAzureWebsiteCommand.Name = "website2"; removeAzureWebsiteCommand.ExecuteCmdlet(); Assert.IsFalse(deletedWebsite); }