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));
        }
Beispiel #3
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));
        }
Beispiel #4
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));
        }