Exemple #1
0
        public void ListWebHostingPlansTest()
        {
            // Setup
            var clientMock = new Mock <IWebsitesClient>();

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

            clientMock.Setup(c => c.ListWebHostingPlans())
            .Returns(new List <WebHostingPlan>
            {
                new WebHostingPlan {
                    Name = "Plan1", WebSpace = "webspace1"
                },
                new WebHostingPlan {
                    Name = "Plan2", WebSpace = "webspace2"
                }
            });

            // Test
            var command = new GetAzureWebHostingPlanCommand
            {
                CommandRuntime = new MockCommandRuntime(),
                WebsitesClient = clientMock.Object
            };

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

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

            command.ExecuteCmdlet();

            var plans = System.Management.Automation.LanguagePrimitives.GetEnumerable(((MockCommandRuntime)command.CommandRuntime).OutputPipeline).Cast <WebHostingPlan>();

            Assert.NotNull(plans);
            Assert.Equal(2, plans.Count());
            Assert.True(plans.Any(p => (p).Name.Equals("Plan1") && (p).WebSpace.Equals("webspace1")));
            Assert.True(plans.Any(p => (p).Name.Equals("Plan2") && (p).WebSpace.Equals("webspace2")));
        }
        public void ListWebHostingPlansTest()
        {
            // Setup
            var clientMock = new Mock <IWebsitesClient>();

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

            clientMock.Setup(c => c.ListWebHostingPlans())
            .Returns(new List <WebHostingPlan>
            {
                new WebHostingPlan {
                    Name = "Plan1", WebSpace = "webspace1"
                },
                new WebHostingPlan {
                    Name = "Plan2", WebSpace = "webspace2"
                }
            });

            // Test
            var command = new GetAzureWebHostingPlanCommand
            {
                CommandRuntime = new MockCommandRuntime(),
                WebsitesClient = clientMock.Object
            };

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

            command.ExecuteCmdlet();
            Assert.Equal(1, ((MockCommandRuntime)command.CommandRuntime).OutputPipeline.Count);
            var plans = (IEnumerable <WebHostingPlan>)((MockCommandRuntime)command.CommandRuntime).OutputPipeline.FirstOrDefault();

            Assert.NotNull(plans);
            Assert.True(plans.Any(p => (p).Name.Equals("Plan1") && (p).WebSpace.Equals("webspace1")));
            Assert.True(plans.Any(p => (p).Name.Equals("Plan2") && (p).WebSpace.Equals("webspace2")));
        }
        public void GetAzureWebHostingPlanBasicTest()
        {
            // Setup
            var clientMock = new Mock <IWebsitesClient>();

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

            clientMock.Setup(c => c.ListWebHostingPlans("webspace1"))
            .Returns(new List <WebHostingPlan> {
                new WebHostingPlan {
                    Name = "Plan1", WebSpace = "webspace1"
                }
            });

            // Test
            var command = new GetAzureWebHostingPlanCommand
            {
                WebSpaceName   = "webspace1",
                CommandRuntime = new MockCommandRuntime(),
                WebsitesClient = clientMock.Object
            };

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

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

            command.ExecuteCmdlet();
            Assert.Equal(1, ((MockCommandRuntime)command.CommandRuntime).OutputPipeline.Count);
            var plans = (IEnumerable <WebHostingPlan>)((MockCommandRuntime)command.CommandRuntime).OutputPipeline.FirstOrDefault();

            Assert.NotNull(plans);
            Assert.True(plans.Any(p => (p).Name.Equals("Plan1") && (p).WebSpace.Equals("webspace1")));
        }
        public void GetAzureWebHostingPlanBasicTest()
        {
            // Setup
            var clientMock = new Mock <IWebsitesClient>();

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

            clientMock.Setup(c => c.ListWebHostingPlans("webspace1"))
            .Returns(new List <WebHostingPlan> {
                new WebHostingPlan {
                    Name = "Plan1", WebSpace = "webspace1"
                }
            });

            // Test
            var command = new GetAzureWebHostingPlanCommand
            {
                WebSpaceName        = "webspace1",
                CommandRuntime      = new MockCommandRuntime(),
                CurrentSubscription = new WindowsAzureSubscription {
                    SubscriptionId = subscriptionId
                },
                WebsitesClient = clientMock.Object
            };

            command.ExecuteCmdlet();
            Assert.AreEqual(1, ((MockCommandRuntime)command.CommandRuntime).OutputPipeline.Count);
            var plans = (IEnumerable <WebHostingPlan>)((MockCommandRuntime)command.CommandRuntime).OutputPipeline.FirstOrDefault();

            Assert.IsNotNull(plans);
            Assert.IsTrue(plans.Any(p => (p).Name.Equals("Plan1") && (p).WebSpace.Equals("webspace1")));
        }