public void SaveAzureWebsiteLogWithSlotTest()
        {
            // Setup
            SimpleDeploymentServiceManagement deploymentChannel = new SimpleDeploymentServiceManagement
            {
                DownloadLogsThunk = ar => new MemoryStream(Encoding.UTF8.GetBytes("test"))
            };

            // Test
            SaveAzureWebsiteLogCommand getAzureWebsiteLogCommand = new SaveAzureWebsiteLogCommand(deploymentChannel)
            {
                Name                = "website1",
                ShareChannel        = true,
                WebsitesClient      = clientMock.Object,
                CommandRuntime      = new MockCommandRuntime(),
                CurrentSubscription = new WindowsAzureSubscription {
                    SubscriptionId = base.subscriptionId
                },
                Slot = slot
            };

            getAzureWebsiteLogCommand.DefaultCurrentPath = "";
            getAzureWebsiteLogCommand.ExecuteCmdlet();
            Assert.AreEqual("test", File.ReadAllText(SaveAzureWebsiteLogCommand.DefaultOutput));
        }
        public void SaveAzureWebsiteLogWithNoFileExtensionTest()
        {
            TestExecutionHelpers.RetryAction(
                () =>
            {
                // Setup
                string expectedOutput = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "file_without_ext.zip");

                SimpleDeploymentServiceManagement deploymentChannel = new SimpleDeploymentServiceManagement
                {
                    DownloadLogsThunk = ar => new MemoryStream(Encoding.UTF8.GetBytes("test with no extension"))
                };

                // Test
                SaveAzureWebsiteLogCommand getAzureWebsiteLogCommand = new SaveAzureWebsiteLogCommand(deploymentChannel)
                {
                    Name           = "website1",
                    ShareChannel   = true,
                    WebsitesClient = clientMock.Object,
                    CommandRuntime = new MockCommandRuntime(),
                    Output         = "file_without_ext"
                };
                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;

                getAzureWebsiteLogCommand.DefaultCurrentPath = AppDomain.CurrentDomain.BaseDirectory;
                getAzureWebsiteLogCommand.ExecuteCmdlet();
                Assert.Equal("test with no extension", FileUtilities.DataStore.ReadFileAsText(expectedOutput));
            });
        }
        public void SaveAzureWebsiteLogTest()
        {
            // Setup
            SimpleDeploymentServiceManagement deploymentChannel = new SimpleDeploymentServiceManagement
            {
                DownloadLogsThunk = ar => new MemoryStream(Encoding.UTF8.GetBytes("test"))
            };

            // Test
            SaveAzureWebsiteLogCommand getAzureWebsiteLogCommand = new SaveAzureWebsiteLogCommand(deploymentChannel)
            {
                Name           = "website1",
                ShareChannel   = true,
                WebsitesClient = clientMock.Object,
                CommandRuntime = new MockCommandRuntime(),
            };

            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;

            getAzureWebsiteLogCommand.DefaultCurrentPath = AppDomain.CurrentDomain.BaseDirectory;
            getAzureWebsiteLogCommand.ExecuteCmdlet();
            Assert.Equal("test", FileUtilities.DataStore.ReadFileAsText(
                             Path.Combine(AppDomain.CurrentDomain.BaseDirectory, SaveAzureWebsiteLogCommand.DefaultOutput)));
        }
Ejemplo n.º 4
0
        public void SaveAzureWebsiteLogTest()
        {
            // Setup
            SimpleDeploymentServiceManagement deploymentChannel = new SimpleDeploymentServiceManagement
            {
                DownloadLogsThunk = ar => new MemoryStream(Encoding.UTF8.GetBytes("test"))
            };

            // Test
            SaveAzureWebsiteLogCommand getAzureWebsiteLogCommand = new SaveAzureWebsiteLogCommand(deploymentChannel)
            {
                Name           = "website1",
                ShareChannel   = true,
                WebsitesClient = clientMock.Object,
                CommandRuntime = new MockCommandRuntime(),
            };

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

            getAzureWebsiteLogCommand.DefaultCurrentPath = "";
            getAzureWebsiteLogCommand.ExecuteCmdlet();
            Assert.Equal("test", FileUtilities.DataStore.ReadFileAsText(SaveAzureWebsiteLogCommand.DefaultOutput));
        }
        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 GetAzureWebsiteDeploymentTest()
        {
            // Setup
            var clientMock = new Mock<IWebsitesClient>();
            var site1 = 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"}
                    }
                }
            };

            clientMock.Setup(c => c.GetWebsite("website1", null))
                .Returns(site1);

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

            clientMock.Setup(c => c.ListSitesInWebSpace("webspace2"))
                .Returns(new[] { 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(deploymentChannel)
            {
                Name = "website1",
                ShareChannel = true,
                WebsitesClient = clientMock.Object,
                CommandRuntime = new MockCommandRuntime(),
                CurrentSubscription = new WindowsAzureSubscription { 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 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 SaveAzureWebsiteLogTest()
        {
            // Setup
            SimpleDeploymentServiceManagement deploymentChannel = new SimpleDeploymentServiceManagement
            {
                DownloadLogsThunk = ar => new MemoryStream(Encoding.UTF8.GetBytes("test"))
            };

            // Test
            SaveAzureWebsiteLogCommand getAzureWebsiteLogCommand = new SaveAzureWebsiteLogCommand(deploymentChannel)
            {
                Name = "website1", 
                ShareChannel = true,
                WebsitesClient = clientMock.Object,
                CommandRuntime = new MockCommandRuntime(),
                CurrentSubscription = new WindowsAzureSubscription { 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.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 RestoresDeploymentForSlot()
        {
            string slot = "staging";
            // Setup
            var site1 = 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"}
                    }
                }
            };

            var clientMock = new Mock<IWebsitesClient>();
            clientMock.Setup(c => c.ListWebSpaces())
                .Returns(new[] { new WebSpace { Name = "webspace1" }, new WebSpace { Name = "webspace2" } });
            clientMock.Setup(c => c.GetWebsite("website1", slot))
                .Returns(site1);

            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(deploymentChannel)
                {
                    Name = "website1",
                    CommitId = "id2",
                    ShareChannel = true,
                    WebsitesClient = clientMock.Object,
                    CommandRuntime = new MockCommandRuntime(),
                    CurrentSubscription = new WindowsAzureSubscription { SubscriptionId = base.subscriptionId },
                    Slot = slot
                };

            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(deploymentChannel)
            {
                Name = "website1",
                CommitId = "id1",
                ShareChannel = true,
                WebsitesClient = clientMock.Object,
                CommandRuntime = new MockCommandRuntime(),
                CurrentSubscription = new WindowsAzureSubscription { SubscriptionId = base.subscriptionId },
                Slot = slot
            };

            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 GetAzureWebsiteDeploymentTest()
        {
            // Setup
            var clientMock = new Mock <IWebsitesClient>();
            var site1      = 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"
                        }
                    }
                }
            };

            clientMock.Setup(c => c.GetWebsite("website1", null))
            .Returns(site1);

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

            clientMock.Setup(c => c.ListSitesInWebSpace("webspace2"))
            .Returns(new[] { 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(deploymentChannel)
            {
                Name           = "website1",
                ShareChannel   = true,
                WebsitesClient = clientMock.Object,
                CommandRuntime = new MockCommandRuntime(),
            };

            currentProfile = new AzureProfile();
            var subscription = new AzureSubscription {
                Id = new Guid(subscriptionId)
            };

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


            getAzureWebsiteDeploymentCommand.ExecuteCmdlet();

            var deployments = System.Management.Automation.LanguagePrimitives.GetEnumerable(((MockCommandRuntime)getAzureWebsiteDeploymentCommand.CommandRuntime).OutputPipeline).Cast <DeployResult>();

            Assert.NotNull(deployments);
            Assert.Equal(2, deployments.Count());
        }
Ejemplo n.º 12
0
        public void RestoreAzureWebsiteDeploymentTest()
        {
            // Setup
            var site1 = 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"
                        }
                    }
                }
            };

            var clientMock = new Mock <IWebsitesClient>();

            clientMock.Setup(c => c.ListWebSpaces())
            .Returns(new[] { new WebSpace {
                                 Name = "webspace1"
                             }, new WebSpace {
                                 Name = "webspace2"
                             } });
            clientMock.Setup(c => c.GetWebsite("website1", null))
            .Returns(site1);

            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(deploymentChannel)
            {
                Name           = "website1",
                CommitId       = "id2",
                ShareChannel   = true,
                WebsitesClient = clientMock.Object,
                CommandRuntime = new MockCommandRuntime(),
            };

            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;

            restoreAzureWebsiteDeploymentCommand.ExecuteCmdlet();

            var responseDeployments = System.Management.Automation.LanguagePrimitives.GetEnumerable(((MockCommandRuntime)restoreAzureWebsiteDeploymentCommand.CommandRuntime).OutputPipeline).Cast <DeployResult>();

            Assert.NotNull(responseDeployments);
            Assert.Equal(2, responseDeployments.Count());
            Assert.True(responseDeployments.Any(d => d.Id.Equals("id2") && d.Complete));
            Assert.True(responseDeployments.Any(d => d.Id.Equals("id1") && !d.Complete));

            // Change active deployment to id1
            restoreAzureWebsiteDeploymentCommand = new RestoreAzureWebsiteDeploymentCommand(deploymentChannel)
            {
                Name           = "website1",
                CommitId       = "id1",
                ShareChannel   = true,
                WebsitesClient = clientMock.Object,
                CommandRuntime = new MockCommandRuntime(),
            };
            currentProfile = new AzureSMProfile();
            subscription   = new AzureSubscription {
                Id = new Guid(base.subscriptionId)
            };
            subscription.Properties[AzureSubscription.Property.Default] = "True";
            currentProfile.Subscriptions[new Guid(base.subscriptionId)] = subscription;

            restoreAzureWebsiteDeploymentCommand.ExecuteCmdlet();

            responseDeployments = System.Management.Automation.LanguagePrimitives.GetEnumerable(((MockCommandRuntime)restoreAzureWebsiteDeploymentCommand.CommandRuntime).OutputPipeline).Cast <DeployResult>();
            Assert.NotNull(responseDeployments);
            Assert.Equal(2, responseDeployments.Count());
            Assert.True(responseDeployments.Any(d => d.Id.Equals("id1") && d.Complete));
            Assert.True(responseDeployments.Any(d => d.Id.Equals("id2") && !d.Complete));
        }
        public void RestoresDeploymentForSlot()
        {
            string slot = "staging";
            // Setup
            var site1 = 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"
                        }
                    }
                }
            };

            var clientMock = new Mock <IWebsitesClient>();

            clientMock.Setup(c => c.ListWebSpaces())
            .Returns(new[] { new WebSpace {
                                 Name = "webspace1"
                             }, new WebSpace {
                                 Name = "webspace2"
                             } });
            clientMock.Setup(c => c.GetWebsite("website1", slot))
            .Returns(site1);

            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(deploymentChannel)
            {
                Name                = "website1",
                CommitId            = "id2",
                ShareChannel        = true,
                WebsitesClient      = clientMock.Object,
                CommandRuntime      = new MockCommandRuntime(),
                CurrentSubscription = new WindowsAzureSubscription {
                    SubscriptionId = base.subscriptionId
                },
                Slot = slot
            };

            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(deploymentChannel)
            {
                Name                = "website1",
                CommitId            = "id1",
                ShareChannel        = true,
                WebsitesClient      = clientMock.Object,
                CommandRuntime      = new MockCommandRuntime(),
                CurrentSubscription = new WindowsAzureSubscription {
                    SubscriptionId = base.subscriptionId
                },
                Slot = slot
            };

            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));
        }
Ejemplo n.º 14
0
        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));
        }
Ejemplo n.º 15
0
        public void GetAzureWebsiteDeploymentLogsTest()
        {
            // Setup
            var clientMock = new Mock <IWebsitesClient>();
            var site1      = 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"
                        }
                    }
                }
            };

            clientMock.Setup(c => c.ListWebSpaces())
            .Returns(new[] { new WebSpace {
                                 Name = "webspace1"
                             }, new WebSpace {
                                 Name = "webspace2"
                             } });
            clientMock.Setup(c => c.GetWebsite("website1", null)).Returns(site1);

            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(deploymentChannel)
            {
                Name           = "website1",
                ShareChannel   = true,
                WebsitesClient = clientMock.Object,
                Details        = true,
                CommandRuntime = new MockCommandRuntime(),
            };

            currentProfile = new AzureProfile();
            var subscription = new AzureSubscription {
                Id = new Guid(subscriptionId)
            };

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

            getAzureWebsiteDeploymentCommand.ExecuteCmdlet();
            Assert.Equal(1, ((MockCommandRuntime)getAzureWebsiteDeploymentCommand.CommandRuntime).OutputPipeline.Count);
            var deployments = (IEnumerable <DeployResult>)((MockCommandRuntime)getAzureWebsiteDeploymentCommand.CommandRuntime).OutputPipeline.FirstOrDefault();

            Assert.NotNull(deployments);
            Assert.Equal(2, deployments.Count());
            Assert.NotNull(deployments.First(d => d.Id.Equals("commit1")).Logs);
        }
Ejemplo n.º 16
0
        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));
        }
Ejemplo n.º 17
0
        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 GetAzureWebsiteDeploymentTest()
        {
            // Setup
            var clientMock = new Mock <IWebsitesClient>();
            var site1      = 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"
                        }
                    }
                }
            };

            clientMock.Setup(c => c.GetWebsite("website1", null))
            .Returns(site1);

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

            clientMock.Setup(c => c.ListSitesInWebSpace("webspace2"))
            .Returns(new[] { 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(deploymentChannel)
            {
                Name                = "website1",
                ShareChannel        = true,
                WebsitesClient      = clientMock.Object,
                CommandRuntime      = new MockCommandRuntime(),
                CurrentSubscription = new WindowsAzureSubscription {
                    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 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());
        }