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.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()); Assert.IsNotNull(deployments.First(d => d.Id.Equals("commit1")).Logs); }
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.subscriptionId } }; getAzureWebsiteLogCommand.DefaultCurrentPath = ""; getAzureWebsiteLogCommand.ExecuteCmdlet(); Assert.AreEqual("test", File.ReadAllText(SaveAzureWebsiteLogCommand.DefaultOutput)); }
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)); }