Inheritance: ICommandRuntime
        public SetIPForwardingTests()
        {
            this.networkingClientMock = new Mock<INetworkManagementClient>();
            this.computeClientMock = new Mock<IComputeManagementClient>();
            this.managementClientMock = new Mock<IManagementClient>();
            this.mockCommandRuntime = new MockCommandRuntime();
            this.client = new NetworkClient(
                networkingClientMock.Object,
                computeClientMock.Object,
                managementClientMock.Object,
                mockCommandRuntime);

            this.computeClientMock
                .Setup(c => c.Deployments.GetBySlotAsync(ServiceName, DeploymentSlot.Production, It.IsAny<CancellationToken>()))
                .Returns(Task.Factory.StartNew(() => new DeploymentGetResponse()
                {
                    Name = DeploymentName
                }));

            this.networkingClientMock
                .Setup(c => c.IPForwarding.SetOnRoleAsync(
                    ServiceName,
                    DeploymentName,
                    RoleName,
                    It.IsAny<IPForwardingSetParameters>(),
                    It.IsAny<CancellationToken>()))
                .Returns(Task.Factory.StartNew(() => new Azure.OperationStatusResponse()));
        }
        /// <summary>
        /// Initializes a new instance of the <see cref="RegisterAzureProviderCmdletTests"/> class.
        /// </summary>
        public RegisterAzureProviderCmdletTests(ITestOutputHelper output)
        {
            this.providerOperationsMock = new Mock<IProvidersOperations>();
            XunitTracingInterceptor.AddToContext(new XunitTracingInterceptor(output));
            var resourceManagementClient = new Mock<IResourceManagementClient>();

            resourceManagementClient
                .SetupGet(client => client.Providers)
                .Returns(() => this.providerOperationsMock.Object);

            this.commandRuntimeMock = new Mock<ICommandRuntime>();

            this.commandRuntimeMock
              .Setup(m => m.ShouldProcess(It.IsAny<string>(), It.IsAny<string>()))
              .Returns(() => true);

            this.cmdlet = new RegisterAzureProviderCmdlet()
            {
                ResourceManagerSdkClient = new ResourceManagerSdkClient
                {
                    ResourceManagementClient = resourceManagementClient.Object
                }
            };

            PSCmdletExtensions.SetCommandRuntimeMock(cmdlet, commandRuntimeMock.Object);
            mockRuntime = new MockCommandRuntime();
            commandRuntimeMock.Setup(f => f.Host).Returns(mockRuntime.Host);
        }
 public LoginCmdletTests()
 {
     dataStore = new MemoryDataStore();
     AzureSession.DataStore = dataStore;
     commandRuntimeMock = new MockCommandRuntime();
     AzureRmProfileProvider.Instance.Profile = new AzureRMProfile();
 }
        /// <summary>
        /// Initializes a new instance of the <see cref="GetAzureProviderFeatureCmdletTests"/> class.
        /// </summary>
        public RegisterAzureProviderFeatureCmdletTests(ITestOutputHelper output)
        {
            this.featureOperationsMock = new Mock<IFeaturesOperations>();
            var featureClient = new Mock<IFeatureClient>();

            featureClient
                .SetupGet(client => client.Features)
                .Returns(() => this.featureOperationsMock.Object);

            this.commandRuntimeMock = new Mock<ICommandRuntime>();

            this.commandRuntimeMock
              .Setup(m => m.ShouldProcess(It.IsAny<string>(), It.IsAny<string>()))
              .Returns(() => true);

            this.cmdlet = new RegisterAzureProviderFeatureCmdlet()
            {
                //CommandRuntime = commandRuntimeMock.Object,
                ProviderFeatureClient = new ProviderFeatureClient
                {
                    FeaturesManagementClient = featureClient.Object
                }
            };
            PSCmdletExtensions.SetCommandRuntimeMock(cmdlet, commandRuntimeMock.Object);
            mockRuntime = new MockCommandRuntime();
            commandRuntimeMock.Setup(f => f.Host).Returns(mockRuntime.Host);
        }
        public SetSubnetRouteTableTests()
        {
            this.networkingClientMock = new Mock<INetworkManagementClient>();
            this.computeClientMock = new Mock<IComputeManagementClient>();
            this.managementClientMock = new Mock<IManagementClient>();
            this.mockCommandRuntime = new MockCommandRuntime();
            this.client = new NetworkClient(
                networkingClientMock.Object,
                computeClientMock.Object,
                managementClientMock.Object,
                mockCommandRuntime);

            this.networkingClientMock
                .Setup(c => c.Routes.GetRouteTableForSubnetAsync(
                    VirtualNetworkName,
                    SubnetName,
                    It.IsAny<CancellationToken>()))
                .Returns(Task.Factory.StartNew(() =>
                    new Models.GetRouteTableForSubnetResponse()
                    {
                        RouteTableName = RouteTableName
                    }));

            this.networkingClientMock
                .Setup(c => c.Routes.AddRouteTableToSubnetAsync(
                    VirtualNetworkName,
                    SubnetName,
                    It.Is<Models.AddRouteTableToSubnetParameters>(
                        p => string.Equals(p.RouteTableName, RouteTableName)),
                    It.IsAny<CancellationToken>()))
                .Returns(Task.Factory.StartNew(() => new Azure.OperationStatusResponse()));
        }
 public TenantCmdletTests(ITestOutputHelper output)
 {
     XunitTracingInterceptor.AddToContext(new XunitTracingInterceptor(output));
     dataStore = new MemoryDataStore();
     AzureSession.DataStore = dataStore;
     commandRuntimeMock = new MockCommandRuntime();
     AzureRmProfileProvider.Instance.Profile = new AzureRMProfile();
 }
 public void InitCommand()
 {
     MockCmdRunTime = new MockCommandRuntime();
     command = new StorageCloudCmdletBase<IStorageManagement>
     {
         CommandRuntime = MockCmdRunTime
     };
 }
 public ProfileCmdltsTests() : base()
 {
     dataStore = new MockDataStore();
     ProfileClient.DataStore = dataStore;
     commandRuntimeMock = new MockCommandRuntime();
     SetMockData();
     AzureSession.SetCurrentContext(null, null, null);
 }
 public ProfileCmdltsTests()
     : base()
 {
     dataStore = new MemoryDataStore();
     AzureSession.DataStore = dataStore;
     commandRuntimeMock = new MockCommandRuntime();
     SetMockData();
     AzureSession.AuthenticationFactory = new MockTokenAuthenticationFactory();
 }
        public GetSubnetRouteTableTests()
        {
            this.networkingClientMock = new Mock<INetworkManagementClient>();
            this.computeClientMock = new Mock<IComputeManagementClient>();
            this.managementClientMock = new Mock<IManagementClient>();
            this.mockCommandRuntime = new MockCommandRuntime();
            this.client = new NetworkClient(
                networkingClientMock.Object,
                computeClientMock.Object,
                managementClientMock.Object,
                mockCommandRuntime);

            this.networkingClientMock
                .Setup(c => c.Routes.GetRouteTableForSubnetAsync(
                    VirtualNetworkName,
                    SubnetName,
                    It.IsAny<CancellationToken>()))
                .Returns(Task.Factory.StartNew(() =>
                    new Models.GetRouteTableForSubnetResponse()
                    {
                        RouteTableName = RouteTableName
                    }));

            this.networkingClientMock
                .Setup(c => c.Routes.GetRouteTableWithDetailsAsync(
                    RouteTableName,
                    NetworkClient.WithoutRoutesDetailLevel,
                    It.IsAny<CancellationToken>()))
                .Returns(Task.Factory.StartNew(() =>
                    new Models.GetRouteTableResponse()
                    {
                        RouteTable = new Models.RouteTable()
                        {
                            Name = RouteTableName,
                            Location = RouteTableLocation,
                            Label = RouteTableLabel,
                        }
                    }));

            this.networkingClientMock
                .Setup(c => c.Routes.GetRouteTableWithDetailsAsync(
                    RouteTableName,
                    NetworkClient.WithRoutesDetailLevel,
                    It.IsAny<CancellationToken>()))
                .Returns(Task.Factory.StartNew(() =>
                    new Models.GetRouteTableResponse()
                    {
                        RouteTable = new Models.RouteTable()
                        {
                            Name = RouteTableName,
                            Location = RouteTableLocation,
                            Label = RouteTableLabel,
                            RouteList = Routes
                        }
                    }));
        }
        public void ProcessNewWebsiteTest()
        {
            const string websiteName = "website1";
            const string webspaceName = "webspace1";
            const string suffix = "azurewebsites.com";

            // Setup
            Mock<IWebsitesClient> clientMock = new Mock<IWebsitesClient>();
            clientMock.Setup(c => c.GetWebsiteDnsSuffix()).Returns(suffix);
            clientMock.Setup(f => f.GetWebsite(websiteName)).Returns(new Site() { Name = websiteName });
            clientMock.Setup(f => f.GetWebsiteConfiguration(websiteName, null)).Returns(new SiteConfig() { PublishingUsername = "******" });
            clientMock.Setup(c => c.ListWebSpaces())
                .Returns(new[]
                {
                    new WebSpace {Name = "webspace1", GeoRegion = "webspace1"},
                    new WebSpace {Name = "webspace2", GeoRegion = "webspace2"}
                });

            clientMock.Setup(c => c.GetWebsiteConfiguration("website1"))
                .Returns(new SiteConfig { PublishingUsername = "******" });

            string createdSiteName = null;
            string createdWebspaceName = null;

            clientMock.Setup(c => c.CreateWebsite(webspaceName, It.IsAny<SiteWithWebSpace>(), null))
                .Returns((string space, SiteWithWebSpace site, string slot) => site)
                .Callback((string space, SiteWithWebSpace site, string slot) =>
                {
                    createdSiteName = site.Name;
                    createdWebspaceName = space;
                });

            SetupProfile(null);
            // Test
            MockCommandRuntime mockRuntime = new MockCommandRuntime();
            NewAzureWebsiteCommand newAzureWebsiteCommand = new NewAzureWebsiteCommand
            {
                ShareChannel = true,
                CommandRuntime = mockRuntime,
                Name = websiteName,
                Location = webspaceName,
                WebsitesClient = clientMock.Object
            };

            newAzureWebsiteCommand.ExecuteWithProcessing();
            Assert.Equal(websiteName, createdSiteName);
            Assert.Equal(webspaceName, createdWebspaceName);
            Assert.Equal<string>(websiteName, (mockRuntime.OutputPipeline[0] as SiteWithConfig).Name);
        }
        public RemoveNetworkSecurityGroupAssociationTests()
        {
            this.networkingClientMock = new Mock<INetworkManagementClient>();
            this.computeClientMock = new Mock<IComputeManagementClient>();
            this.managementClientMock = new Mock<IManagementClient>();
            this.mockCommandRuntime = new MockCommandRuntime();
            this.client = new NetworkClient(
                networkingClientMock.Object,
                computeClientMock.Object,
                managementClientMock.Object,
                mockCommandRuntime);

            this.computeClientMock
                .Setup(c => c.Deployments.GetBySlotAsync(ServiceName, DeploymentSlot.Production, It.IsAny<CancellationToken>()))
                .Returns(Task.Factory.StartNew(() => new DeploymentGetResponse()
                {
                    Name = DeploymentName
                }));

            this.networkingClientMock
                .Setup(c =>
                    c.NetworkSecurityGroups.RemoveFromSubnetAsync(
                        VirtualNetworkName,
                        SubnetName,
                        NetworkSecurityGroupName,
                        It.IsAny<CancellationToken>()))
                .Returns(Task.Factory.StartNew(() => new Azure.OperationStatusResponse()));

            this.networkingClientMock
                .Setup(c =>
                    c.NetworkSecurityGroups.RemoveFromRoleAsync(
                        ServiceName,
                        DeploymentName,
                        RoleName,
                        NetworkSecurityGroupName,
                        It.IsAny<CancellationToken>()))
                .Returns(Task.Factory.StartNew(() => new Azure.OperationStatusResponse()));

            this.networkingClientMock
                .Setup(c =>
                    c.NetworkSecurityGroups.RemoveFromNetworkInterfaceAsync(
                        ServiceName,
                        DeploymentName,
                        RoleName,
                        NetworkInterfaceName,
                        NetworkSecurityGroupName,
                        It.IsAny<CancellationToken>()))
                .Returns(Task.Factory.StartNew(() => new Azure.OperationStatusResponse()));
        }
        public void TestSetup()
        {
            mockCommandRuntime = new MockCommandRuntime();
            clientMock = new Mock<ITrafficManagerClient>();

            clientMock
                .Setup(c => c.InstantiateTrafficManagerDefinition(
                    It.IsAny<string>(),
                    It.IsAny<int>(),
                    It.IsAny<string>(),
                    It.IsAny<string>(),
                    It.IsAny<int>(),
                    It.IsAny<IList<TrafficManagerEndpoint>>()))
                .Returns(DefaultDefinition);
        }
        public GetEffectiveRouteTests()
        {
            this.networkingClientMock = new Mock<INetworkManagementClient>();
            this.computeClientMock = new Mock<IComputeManagementClient>();
            this.managementClientMock = new Mock<IManagementClient>();
            this.mockCommandRuntime = new MockCommandRuntime();
            this.client = new NetworkClient(
                networkingClientMock.Object,
                computeClientMock.Object,
                managementClientMock.Object,
                mockCommandRuntime);

            this.computeClientMock
                .Setup(c => c.Deployments.GetBySlotAsync(ServiceName, DeploymentSlot.Production, It.IsAny<CancellationToken>()))
                .Returns(Task.Factory.StartNew(() => new DeploymentGetResponse()
                {
                    Name = DeploymentName
                }));

            this.networkingClientMock
                .Setup(c => c.Routes.GetEffectiveRouteTableForRoleInstanceAsync(
                    ServiceName,
                    DeploymentName,
                    RoleInstanceName,
                    It.IsAny<CancellationToken>()))
                .Returns(Task.Factory.StartNew(() => new GetEffectiveRouteTableResponse()
                {
                    EffectiveRouteTable = new EffectiveRouteTable()
                    {
                        EffectiveRoutes = new List<EffectiveRoute>()
                    }
                }));

            this.networkingClientMock
                .Setup(c => c.Routes.GetEffectiveRouteTableForNetworkInterfaceAsync(
                    ServiceName,
                    DeploymentName,
                    RoleInstanceName,
                    NetworkInterfaceName,
                    It.IsAny<CancellationToken>()))
                .Returns(Task.Factory.StartNew(() => new GetEffectiveRouteTableResponse()
                {
                    EffectiveRouteTable = new EffectiveRouteTable()
                    {
                        EffectiveRoutes = new List<EffectiveRoute>()
                    }
                }));
        }
        public RemoveRouteTableTests()
        {
            this.networkingClientMock = new Mock<INetworkManagementClient>();
            this.computeClientMock = new Mock<IComputeManagementClient>();
            this.managementClientMock = new Mock<IManagementClient>();
            this.mockCommandRuntime = new MockCommandRuntime();
            this.client = new NetworkClient(
                networkingClientMock.Object,
                computeClientMock.Object,
                managementClientMock.Object,
                mockCommandRuntime);

                        this.networkingClientMock
                .Setup(c => c.Routes.DeleteRouteTableAsync(
                    RouteTableName,
                    It.IsAny<CancellationToken>()))
                .Returns(Task.Factory.StartNew(() => new Azure.OperationStatusResponse()));
        }
        public MultivipTests()
        {
            this.networkingClientMock = new Mock<NetworkManagementClient>();
            this.computeClientMock = new Mock<ComputeManagementClient>();
            this.managementClientMock = new Mock<ManagementClient>();
            this.storageClientMock = new Mock<StorageManagementClient>();
            this.mockCommandRuntime = new MockCommandRuntime();
            testClientProvider = new TestClientProvider(this.managementClientMock.Object, this.computeClientMock.Object,
                this.storageClientMock.Object, this.networkingClientMock.Object);

            testClientProvider = new TestClientProvider(this.managementClientMock.Object,
                this.computeClientMock.Object, this.storageClientMock.Object, this.networkingClientMock.Object);

            this.computeClientMock
                .Setup(c => c.Deployments.GetBySlotAsync(ServiceName, DeploymentSlot.Production, It.IsAny<CancellationToken>()))
                .Returns(Task.Factory.StartNew(() => new DeploymentGetResponse()
                {
                    Name = DeploymentName
                }));

            this.networkingClientMock
                .Setup(c => c.VirtualIPs.AddAsync(
                    ServiceName,
                    DeploymentName,
                    VipName,
                    It.IsAny<CancellationToken>()))
                .Returns(Task.Factory.StartNew(() => new OperationStatusResponse()
                {
                    Status = OperationStatus.Succeeded
                }));


            this.networkingClientMock
                .Setup(c => c.VirtualIPs.RemoveAsync(
                    ServiceName,
                    DeploymentName,
                    VipName,
                    It.IsAny<CancellationToken>()))
                .Returns(Task.Factory.StartNew(() => new OperationStatusResponse()
                {
                    Status = OperationStatus.Succeeded
                }));
        }
        public GetIPForwardingTests()
        {
            this.networkingClientMock = new Mock<INetworkManagementClient>();
            this.computeClientMock = new Mock<IComputeManagementClient>();
            this.managementClientMock = new Mock<IManagementClient>();
            this.mockCommandRuntime = new MockCommandRuntime();
            this.client = new NetworkClient(
                networkingClientMock.Object,
                computeClientMock.Object,
                managementClientMock.Object,
                mockCommandRuntime);

            this.computeClientMock
                .Setup(c => c.Deployments.GetBySlotAsync(ServiceName, DeploymentSlot.Production, It.IsAny<CancellationToken>()))
                .Returns(Task.Factory.StartNew(() => new DeploymentGetResponse()
                {
                    Name = DeploymentName
                }));

            this.networkingClientMock
                .Setup(c => c.IPForwarding.GetForRoleAsync(
                    ServiceName,
                    DeploymentName,
                    RoleName,
                    It.IsAny<CancellationToken>()))
                .Returns(Task.Factory.StartNew(() => new IPForwardingGetResponse()
                {
                    State = "Enabled"
                }));

            this.networkingClientMock
                .Setup(c => c.IPForwarding.GetForNetworkInterfaceAsync(
                    ServiceName,
                    DeploymentName,
                    RoleName,
                    NetworkInterfaceName,
                    It.IsAny<CancellationToken>()))
                .Returns(Task.Factory.StartNew(() => new IPForwardingGetResponse()
                {
                    State = "Disabled"
                }));
        }
        public SetRouteTests()
        {
            this.networkingClientMock = new Mock<INetworkManagementClient>();
            this.computeClientMock = new Mock<IComputeManagementClient>();
            this.managementClientMock = new Mock<IManagementClient>();
            this.mockCommandRuntime = new MockCommandRuntime();
            this.client = new NetworkClient(
                networkingClientMock.Object,
                computeClientMock.Object,
                managementClientMock.Object,
                mockCommandRuntime);

            this.networkingClientMock
                .Setup(c => c.Routes.SetRouteAsync(
                    RouteTableName,
                    RouteName,
                    It.Is<SetRouteParameters>(p =>
                        string.Equals(p.Name, RouteName) &&
                        string.Equals(p.AddressPrefix, RouteAddressPrefix) &&
                        string.Equals(p.NextHop.IpAddress, RouteIpAddress) &&
                        string.Equals(p.NextHop.Type, RouteNextHopType)),
                    It.IsAny<CancellationToken>()))
                .Returns(Task.Factory.StartNew(() => new Azure.OperationStatusResponse()));

            this.networkingClientMock
                .Setup(c => c.Routes.GetRouteTableWithDetailsAsync(
                    RouteTableName,
                    NetworkClient.WithRoutesDetailLevel,
                    It.IsAny<CancellationToken>()))
                .Returns(Task.Factory.StartNew(() =>
                    new Models.GetRouteTableResponse()
                    {
                        RouteTable = new Models.RouteTable()
                        {
                            Name = RouteTableName,
                            Location = RouteTableLocation,
                            Label = RouteTableLabel,
                            RouteList = Routes
                        }
                    }));
        }
        public void CreateStageSlot()
        {
            string slot = "staging";
            const string websiteName = "website1";
            const string webspaceName = "webspace1";
            const string suffix = "azurewebsites.com";

            // Setup
            Mock<IWebsitesClient> clientMock = new Mock<IWebsitesClient>();
            clientMock.Setup(c => c.GetWebsiteDnsSuffix()).Returns(suffix);
            clientMock.Setup(c => c.ListWebSpaces())
                .Returns(new[]
                {
                    new WebSpace {Name = "webspace1", GeoRegion = "webspace1"},
                    new WebSpace {Name = "webspace2", GeoRegion = "webspace2"}
                });

            clientMock.Setup(c => c.GetWebsiteConfiguration("website1", slot))
                .Returns(new SiteConfig { PublishingUsername = "******" });

            clientMock.Setup(f => f.WebsiteExists(websiteName)).Returns(true);
            clientMock.Setup(f => f.GetWebsite(websiteName)).Returns(new Site() { Name = websiteName, Sku = SkuOptions.Standard, WebSpace = webspaceName });

            // Test
            MockCommandRuntime mockRuntime = new MockCommandRuntime();
            NewAzureWebsiteCommand newAzureWebsiteCommand = new NewAzureWebsiteCommand
            {
                ShareChannel = true,
                CommandRuntime = mockRuntime,
                Name = websiteName,
                Location = webspaceName,
                WebsitesClient = clientMock.Object,
                Slot = slot
            };
            AzureSession.SetCurrentContext(new AzureSubscription { Id = new Guid(base.subscriptionId) }, null, null);

            newAzureWebsiteCommand.ExecuteCmdlet();
            clientMock.Verify(c => c.CreateWebsite(webspaceName, It.IsAny<SiteWithWebSpace>(), slot), Times.Once());
        }
        /// <summary>
        /// Initializes a new instance of the <see cref="GetAzureProviderFeatureCmdletTests"/> class.
        /// </summary>
        public GetAzureProviderFeatureCmdletTests(ITestOutputHelper output)
        {
            this.featureOperationsMock = new Mock<IFeaturesOperations>();
            var featureClient = new Mock<IFeatureClient>();

            featureClient
                .SetupGet(client => client.Features)
                .Returns(() => this.featureOperationsMock.Object);

            this.commandRuntimeMock = new Mock<ICommandRuntime>();

            this.cmdlet = new GetAzureProviderFeatureCmdletTest
            {
                //CommandRuntime = commandRuntimeMock.Object,
                ProviderFeatureClient = new ProviderFeatureClient
                {
                    FeaturesManagementClient = featureClient.Object
                }
            };
            PSCmdletExtensions.SetCommandRuntimeMock(cmdlet, commandRuntimeMock.Object);
            mockRuntime = new MockCommandRuntime();
            commandRuntimeMock.Setup(f => f.Host).Returns(mockRuntime.Host);
        }
        public RemoveRouteTests()
        {
            this.networkingClientMock = new Mock<INetworkManagementClient>();
            this.computeClientMock = new Mock<IComputeManagementClient>();
            this.managementClientMock = new Mock<IManagementClient>();
            this.mockCommandRuntime = new MockCommandRuntime();
            this.client = new NetworkClient(
                networkingClientMock.Object,
                computeClientMock.Object,
                managementClientMock.Object,
                mockCommandRuntime);

            this.networkingClientMock
                .Setup(c => c.Routes.CreateRouteTableAsync(
                    It.Is<CreateRouteTableParameters>(p =>
                        string.Equals(p.Name, RouteTableName) &&
                        string.Equals(p.Location, RouteTableLocation) &&
                        string.Equals(p.Label, RouteTableLabel)),
                    It.IsAny<CancellationToken>()))
                .Returns(Task.Factory.StartNew(() => new Azure.OperationStatusResponse()));

            this.networkingClientMock
                .Setup(c => c.Routes.GetRouteTableWithDetailsAsync(
                    RouteTableName,
                    NetworkClient.WithRoutesDetailLevel,
                    It.IsAny<CancellationToken>()))
                .Returns(Task.Factory.StartNew(() =>
                    new Models.GetRouteTableResponse()
                    {
                        RouteTable = new Models.RouteTable()
                        {
                            Name = RouteTableName,
                            Location = RouteTableLocation,
                            Label = RouteTableLabel,
                        }
                    }));
        }
        public void CanCreateAzureProfileWithFile()
        {
           var dataStore = AzureSession.DataStore;
            try
            {
                AzureSession.DataStore = new MemoryDataStore();
                var oldProfile = new AzureProfile();
                AzurePSCmdlet.CurrentProfile = oldProfile;
                string myFile = Path.GetTempFileName();
                var profile = SetupCustomProfile(myFile);
                var cmdlet = new NewAzureProfileCommand();
                var runtime = new MockCommandRuntime();
                cmdlet.SetParameterSet(NewAzureProfileCommand.FileParameterSet);
                cmdlet.Path = myFile;

                cmdlet.CommandRuntime = runtime;
                cmdlet.InvokeBeginProcessing();
                cmdlet.ExecuteCmdlet();
                cmdlet.InvokeEndProcessing();

                var returnedProfile = runtime.OutputPipeline.First() as AzureProfile;
                Assert.NotNull(returnedProfile);
                Assert.NotNull(returnedProfile.Accounts.Values);
                Assert.NotNull(returnedProfile.Subscriptions.Values);
                Assert.NotNull(returnedProfile.Environments.Values);
                Assert.Equal(profile.Accounts.Values.Count, returnedProfile.Accounts.Values.Count);
                foreach (var account in profile.Accounts.Values)
                {
                    var returnedAccount = returnedProfile.Accounts.Values.FirstOrDefault((a) => a.Id == account.Id);
                    Assert.NotNull(returnedAccount);
                    Assert.Equal(account.GetProperty(AzureAccount.Property.Subscriptions),
                        returnedAccount.GetProperty(AzureAccount.Property.Subscriptions));
                }

                Assert.Equal(profile.Subscriptions.Values.Count, returnedProfile.Subscriptions.Values.Count);
                foreach (var subscription in profile.Subscriptions.Values)
                {
                    var returnedSub = returnedProfile.Subscriptions.Values.FirstOrDefault((s) => s.Id == subscription.Id);
                    Assert.NotNull(returnedSub);
                }

                // current profile does not change
                Assert.Equal(oldProfile.Accounts.Count, 0);
                Assert.Equal(oldProfile.Subscriptions.Count, 0);
            }
            finally
            {
                AzureSession.DataStore = dataStore;
            }
        }
        public void GetsWebsiteDefaultLocation()
        {
            const string websiteName = "website1";
            const string suffix = "azurewebsites.com";
            const string location = "West US";

            bool created = false;

            // Setup
            Mock<IWebsitesClient> clientMock = new Mock<IWebsitesClient>();
            clientMock.Setup(c => c.GetWebsiteDnsSuffix()).Returns(suffix);
            clientMock.Setup(c => c.GetDefaultLocation()).Returns(location);

            clientMock.Setup(c => c.ListWebSpaces()).Returns(new WebSpaces());
            clientMock.Setup(c => c.GetWebsite(websiteName)).Returns(new Site() { Name = websiteName });
            clientMock.Setup(c => c.GetWebsiteConfiguration(websiteName, null))
                .Returns(new SiteConfig
                {
                    PublishingUsername = "******"
                });

            clientMock.Setup(c => c.CreateWebsite(It.IsAny<string>(), It.IsAny<SiteWithWebSpace>(), null))
                .Returns((string space, SiteWithWebSpace site, string slot) => site)
                .Callback((string space, SiteWithWebSpace site, string slot) =>
                {
                    created = true;
                });

            SetupProfile(null);

            // Test
            MockCommandRuntime mockRuntime = new MockCommandRuntime();
            NewAzureWebsiteCommand newAzureWebsiteCommand = new NewAzureWebsiteCommand()
            {
                ShareChannel = true,
                CommandRuntime = mockRuntime,
                Name = websiteName,
                WebsitesClient = clientMock.Object
            };

            newAzureWebsiteCommand.ExecuteWithProcessing();
            Assert.True(created);
            Assert.Equal<string>(websiteName, (mockRuntime.OutputPipeline[0] as SiteWithConfig).Name);
            clientMock.Verify(f => f.GetDefaultLocation(), Times.Once());
        }
 public void InitMock()
 {
     tableMock = new MockStorageTableManagement();
     MockCmdRunTime = new MockCommandRuntime();
 }
        public GetNetworkSecurityGroupAssociationTests()
        {
            this.networkingClientMock = new Mock<INetworkManagementClient>();
            this.computeClientMock = new Mock<IComputeManagementClient>();
            this.managementClientMock = new Mock<IManagementClient>();
            this.mockCommandRuntime = new MockCommandRuntime();
            this.client = new NetworkClient(
                networkingClientMock.Object,
                computeClientMock.Object,
                managementClientMock.Object,
                mockCommandRuntime);

            this.networkingClientMock
                .Setup(c =>
                    c.NetworkSecurityGroups.GetForSubnetAsync(
                        VirtualNetworkName,
                        SubnetName,
                        It.IsAny<CancellationToken>()))
                .Returns(Task.Factory.StartNew(() =>
                    new Models.NetworkSecurityGroupGetAssociationResponse()
                    {
                        Name = NetworkSecurityGroupName
                    }));

            this.networkingClientMock
                .Setup(c =>
                    c.NetworkSecurityGroups.GetForRoleAsync(
                        ServiceName,
                        DeploymentName,
                        RoleName,
                        It.IsAny<CancellationToken>()))
                .Returns(Task.Factory.StartNew(() =>
                    new Models.NetworkSecurityGroupGetAssociationResponse()
                    {
                        Name = NetworkSecurityGroupName
                    }));

            this.networkingClientMock
                .Setup(c =>
                    c.NetworkSecurityGroups.GetForNetworkInterfaceAsync(
                        ServiceName,
                        DeploymentName,
                        RoleName,
                        NetworkInterfaceName,
                        It.IsAny<CancellationToken>()))
                .Returns(Task.Factory.StartNew(() =>
                    new Models.NetworkSecurityGroupGetAssociationResponse()
                    {
                        Name = NetworkSecurityGroupName
                    }));

            this.networkingClientMock
                .Setup(c =>
                    c.NetworkSecurityGroups.GetAsync(
                    NetworkSecurityGroupName,
                    null,
                    It.IsAny<CancellationToken>()))
                .Returns(Task.Factory.StartNew(() =>
                    new Models.NetworkSecurityGroupGetResponse()
                    {
                        Name = NetworkSecurityGroupName,
                        Location = NSGLocation,
                        Label = NSGLabel
                    }));

            this.networkingClientMock
                .Setup(c =>
                    c.NetworkSecurityGroups.GetAsync(
                    NetworkSecurityGroupName,
                    "Full",
                    It.IsAny<CancellationToken>()))
                .Returns(Task.Factory.StartNew(() =>
                    new Models.NetworkSecurityGroupGetResponse()
                    {
                        Name = NetworkSecurityGroupName,
                        Location = NSGLocation,
                        Label = NSGLabel,
                        Rules = Rules
                    }));
        }
 public void InitMock()
 {
     BlobMock = new MockStorageBlobManagement();
     MockCmdRunTime = new MockCommandRuntime();
     AzureSession.DataStore = new MemoryDataStore();
 }
 public void InitMock()
 {
     BlobMock = new MockStorageBlobManagement();
     MockCmdRunTime = new MockCommandRuntime();
     ProfileClient.DataStore = new MockDataStore();
 }
        public void GetAzureRmSubscriptionPaginatedResult()
        {
            var tenants = new List<string> { Guid.NewGuid().ToString(), DefaultTenant.ToString() };
            var secondsubscriptionInTheFirstTenant = Guid.NewGuid().ToString();
            var firstList = new List<string> { DefaultSubscription.ToString(), secondsubscriptionInTheFirstTenant };
            var secondList = new List<string> { Guid.NewGuid().ToString() };
            var thirdList = new List<string> { DefaultSubscription.ToString(), secondsubscriptionInTheFirstTenant };
            var fourthList = new List<string> { DefaultSubscription.ToString(), secondsubscriptionInTheFirstTenant };
            var client = SetupTestEnvironment(tenants, firstList, secondList, thirdList, fourthList);

            var dataStore = new MemoryDataStore();
            AzureSession.DataStore = dataStore;
            var commandRuntimeMock = new MockCommandRuntime();
            AzureSession.AuthenticationFactory = new MockTokenAuthenticationFactory();
            var profile = new AzureRMProfile();
            profile.Environments.Add("foo", AzureEnvironment.PublicEnvironments.Values.FirstOrDefault());
            profile.Context = Context;
            var cmdlt = new GetAzureRMSubscriptionCommand();
            // Setup
            cmdlt.DefaultProfile = profile;
            cmdlt.CommandRuntime = commandRuntimeMock;

            // Act
            cmdlt.InvokeBeginProcessing();
            cmdlt.ExecuteCmdlet();
            cmdlt.InvokeEndProcessing();

            Assert.True(commandRuntimeMock.OutputPipeline.Count == 7);
            Assert.Equal("Disabled", ((PSAzureSubscription)commandRuntimeMock.OutputPipeline[2]).State);
            Assert.Equal("LinkToNextPage", ((PSAzureSubscription)commandRuntimeMock.OutputPipeline[2]).SubscriptionName);
        }
 public void TestSetup()
 {
     mockCommandRuntime = new MockCommandRuntime();
     clientMock = new Mock<ITrafficManagerClient>();
 }
        public ReservedIPTest()
        {
            this.networkingClientMock = new Mock<NetworkManagementClient>();
            this.computeClientMock = new Mock<ComputeManagementClient>();
            this.managementClientMock = new Mock<ManagementClient>();
            this.storageClientMock = new Mock<StorageManagementClient>();
            this.mockCommandRuntime = new MockCommandRuntime();
            
            testClientProvider = new TestClientProvider(this.managementClientMock.Object,
                this.computeClientMock.Object, this.storageClientMock.Object, this.networkingClientMock.Object);

            this.computeClientMock
                .Setup(c => c.Deployments.GetBySlotAsync(ServiceName, DeploymentSlot.Production, It.IsAny<CancellationToken>()))
                .Returns(Task.Factory.StartNew(() => new DeploymentGetResponse()
                {
                    Name = DeploymentName
                }));

            this.computeClientMock
                .Setup(
                    c =>
                        c.Deployments.GetBySlotAsync(ServiceName, DeploymentSlot.Staging,
                            It.IsAny<CancellationToken>()))
                .Returns(Task.Factory.StartNew(() => new DeploymentGetResponse()
                {
                    Name = DeploymentName
                }));

            // Reserve IP simple
            this.networkingClientMock
                .Setup(c => c.ReservedIPs.CreateAsync(
                    It.Is<NetworkReservedIPCreateParameters>(
                        p =>
                            string.Equals(p.Name, ReservedIPName) && string.IsNullOrEmpty(p.ServiceName) &&
                            string.IsNullOrEmpty(p.VirtualIPName) && string.IsNullOrEmpty(p.DeploymentName)),
                    It.IsAny<CancellationToken>()))
                .Returns(Task.Factory.StartNew(() => new OperationStatusResponse()
                {
                    Status = OperationStatus.Succeeded
                }));

            // Reserve in use IP single vip
            this.networkingClientMock
                .Setup(c => c.ReservedIPs.CreateAsync(
                    It.Is<NetworkReservedIPCreateParameters>(
                        p =>
                            string.Equals(p.Name, ReservedIPName) && string.Equals(p.ServiceName, ServiceName) &&
                            string.IsNullOrEmpty(p.VirtualIPName) && string.Equals(p.DeploymentName, DeploymentName)),
                    It.IsAny<CancellationToken>()))
                .Returns(Task.Factory.StartNew(() => new OperationStatusResponse()
                {
                    Status = OperationStatus.Succeeded
                }));

            // Reserve in use IP named vip
            this.networkingClientMock
                .Setup(c => c.ReservedIPs.CreateAsync(
                    It.Is<NetworkReservedIPCreateParameters>(
                        p =>
                            string.Equals(p.Name, ReservedIPName) && string.Equals(p.ServiceName, ServiceName) &&
                            string.Equals(p.VirtualIPName, VipName) && string.Equals(p.DeploymentName, DeploymentName)),
                    It.IsAny<CancellationToken>()))
                .Returns(Task.Factory.StartNew(() => new OperationStatusResponse()
                {
                    Status = OperationStatus.Succeeded
                }));

            // Associate a reserved IP with a deployment
            this.networkingClientMock
                .Setup(c => c.ReservedIPs.AssociateAsync(
                    ReservedIPName,
                    It.Is<NetworkReservedIPMobilityParameters>(
                        p => string.Equals(p.ServiceName, ServiceName) &&
                            string.IsNullOrEmpty(p.VirtualIPName) && string.Equals(p.DeploymentName, DeploymentName)),
                    It.IsAny<CancellationToken>()))
                .Returns(Task.Factory.StartNew(() => new OperationStatusResponse()
                {
                    Status = OperationStatus.Succeeded
                }));


            // Associate a reserved IP with a vip
            this.networkingClientMock
                .Setup(c => c.ReservedIPs.AssociateAsync(
                    ReservedIPName,
                    It.Is<NetworkReservedIPMobilityParameters>(
                        p => string.Equals(p.ServiceName, ServiceName) &&
                            string.Equals(p.VirtualIPName, VipName) && string.Equals(p.DeploymentName, DeploymentName)),
                    It.IsAny<CancellationToken>()))
                .Returns(Task.Factory.StartNew(() => new OperationStatusResponse()
                {
                    Status = OperationStatus.Succeeded
                }));


            // Remove Azure Reserved IP
            this.networkingClientMock
                .Setup(c => c.ReservedIPs.DeleteAsync(
                   ReservedIPName,
                    It.IsAny<CancellationToken>()))
                .Returns(Task.Factory.StartNew(() => new OperationStatusResponse()
                {
                    Status = OperationStatus.Succeeded
                }));
        }