public void CanResizeCluster()
        {
            var cluster = new Cluster
            {
                Id = "id",
                Name = ClusterName + "1",
                Location = Location,
                Properties = new ClusterGetProperties
                {
                    ClusterVersion = "3.1",
                    ClusterState = "Running",
                    ClusterDefinition = new ClusterDefinition
                    {
                        ClusterType = "Hadoop"
                    },
                    QuotaInfo = new QuotaInfo
                    {
                        CoresUsed = 24
                    },
                    OperatingSystemType = OSType.Windows
                },
            };

            var getresponse = new ClusterGetResponse { Cluster = cluster };
            hdinsightManagementMock.Setup(c => c.Get(ResourceGroupName, ClusterName))
                .Returns(getresponse)
                .Verifiable();

            hdinsightManagementMock.Setup(c => c.GetCluster(It.IsAny<string>(), It.IsAny<string>()))
                .CallBase()
                .Verifiable();

            hdinsightManagementMock.Setup(
                c =>
                    c.ResizeCluster(ResourceGroupName, ClusterName,
                        It.Is<ClusterResizeParameters>(
                            param => param.TargetInstanceCount == targetcount)))
                .Returns(new HDInsightLongRunningOperationResponse
                {
                    Error = null,
                    StatusCode = HttpStatusCode.OK,
                    Status = OperationStatus.Succeeded
                })
                .Verifiable();

            cmdlet.ExecuteCmdlet();

            commandRuntimeMock.VerifyAll();
            commandRuntimeMock.Verify(f => f.WriteObject(It.Is<AzureHDInsightCluster>(c => c.Name == cluster.Name)),
                Times.Once);
        }
        public void CanGetHDInsightCluster()
        {
            cmdlet.ClusterName = ClusterName;
            cmdlet.ResourceGroupName = ResourceGroupName;
            var cluster = new Cluster
            {
                Id = "id",
                Name = ClusterName,
                Location = Location,
                Properties = new ClusterGetProperties
                {
                    ClusterVersion = "3.1",
                    ClusterState = "Running",
                    ClusterDefinition = new ClusterDefinition
                    {
                        ClusterType = ClusterType
                    },
                    QuotaInfo = new QuotaInfo
                    {
                        CoresUsed = 24
                    },
                    OperatingSystemType = OSType.Windows
                }
            };

            var getresponse = new ClusterGetResponse { Cluster = cluster };
            hdinsightManagementMock.Setup(c => c.Get(ResourceGroupName, ClusterName))
                .Returns(getresponse)
                .Verifiable(); 
            
            hdinsightManagementMock.Setup(c => c.GetCluster(It.IsAny<string>(), It.IsAny<string>()))
                .CallBase()
                .Verifiable();
            
            cmdlet.ExecuteCmdlet();

            commandRuntimeMock.VerifyAll();
            commandRuntimeMock.Verify(f => f.WriteObject(It.IsAny<List<AzureHDInsightCluster>>(), true), Times.Once);
        }
        public void CanCreateNewPremiumHDInsightCluster()
        {
            cmdlet.ClusterName = ClusterName;
            cmdlet.ResourceGroupName = ResourceGroupName;
            cmdlet.ClusterSizeInNodes = ClusterSize;
            cmdlet.Location = Location;
            cmdlet.HttpCredential = _httpCred;
            cmdlet.DefaultStorageAccountName = StorageName;
            cmdlet.DefaultStorageAccountKey = StorageKey;
            cmdlet.ClusterType = ClusterType;
            cmdlet.OSType = OSType.Linux;
            cmdlet.ClusterTier = Tier.Premium;
            cmdlet.SshCredential = _httpCred;
            var cluster = new Cluster
            {
                Id = "id",
                Name = ClusterName,
                Location = Location,
                Properties = new ClusterGetProperties
                {
                    ClusterVersion = "3.2",
                    ClusterState = "Running",
                    ClusterDefinition = new ClusterDefinition
                    {
                        ClusterType = ClusterType
                    },
                    QuotaInfo = new QuotaInfo
                    {
                        CoresUsed = 24
                    },
                    OperatingSystemType = OSType.Linux,
                    ClusterTier = Tier.Premium
                }
            };
            var coreConfigs = new Dictionary<string, string>
            {
                {"fs.defaultFS", "wasb://giyertestcsmv2@" + StorageName},
                {
                    "fs.azure.account.key." + StorageName,
                    StorageKey
                }
            };
            var gatewayConfigs = new Dictionary<string, string>
            {
                {"restAuthCredential.isEnabled", "true"},
                {"restAuthCredential.username", _httpCred.UserName},
                {"restAuthCredential.password", _httpCred.Password.ConvertToString()}
            };

            var configurations = new Dictionary<string, Dictionary<string, string>>
            {
                {"core-site", coreConfigs},
                {"gateway", gatewayConfigs}
            };
            var serializedConfig = JsonConvert.SerializeObject(configurations);
            cluster.Properties.ClusterDefinition.Configurations = serializedConfig;

            var getresponse = new ClusterGetResponse {Cluster = cluster};
            
            hdinsightManagementMock.Setup(c => c.CreateNewCluster(ResourceGroupName, ClusterName, It.Is<ClusterCreateParameters>(
                parameters => 
                    parameters.ClusterSizeInNodes == ClusterSize &&
                    parameters.DefaultStorageAccountName == StorageName &&
                    parameters.DefaultStorageAccountKey == StorageKey &&
                    parameters.Location == Location &&
                    parameters.UserName == _httpCred.UserName &&
                    parameters.Password == _httpCred.Password.ConvertToString() &&
                    parameters.SshUserName == _httpCred.UserName &&
                    parameters.SshPassword == _httpCred.Password.ConvertToString() &&
                    parameters.ClusterType == ClusterType &&
                    parameters.OSType == OSType.Linux &&
                    parameters.ClusterTier == Tier.Premium)))
            .Returns(getresponse)
            .Verifiable();    
            
            cmdlet.ExecuteCmdlet();

            commandRuntimeMock.VerifyAll();
            commandRuntimeMock.Verify(f => f.WriteObject(It.Is<AzureHDInsightCluster>(
                clusterout =>
                    clusterout.ClusterState == "Running" &&
                    clusterout.ClusterType == ClusterType &&
                    clusterout.ClusterVersion == "3.2" &&
                    clusterout.CoresUsed == 24 &&
                    clusterout.Location == Location &&
                    clusterout.Name == ClusterName &&
                    clusterout.OperatingSystemType == OSType.Linux &&
                    clusterout.ClusterTier == Tier.Premium)), 
                    Times.Once);
        }
        private void CreateNewHDInsightCluster(bool addSecurityProfileInresponse = false)
        {
            cmdlet.ClusterName = ClusterName;
            cmdlet.ResourceGroupName = ResourceGroupName;
            cmdlet.ClusterSizeInNodes = ClusterSize;
            cmdlet.Location = Location;
            cmdlet.HttpCredential = _httpCred;
            cmdlet.DefaultStorageAccountName = StorageName;
            cmdlet.DefaultStorageAccountKey = StorageKey;
            cmdlet.ClusterType = ClusterType;
            cmdlet.SshCredential = _sshCred;
            cmdlet.OSType = OSType.Linux;
            
            var cluster = new Cluster
            {
                Id = "id",
                Name = ClusterName,
                Location = Location,
                Properties = new ClusterGetProperties
                {
                    ClusterVersion = "3.1",
                    ClusterState = "Running",
                    ClusterDefinition = new ClusterDefinition
                    {
                        ClusterType = ClusterType
                    },
                    QuotaInfo = new QuotaInfo
                    {
                        CoresUsed = 24
                    },
                    OperatingSystemType = OSType.Linux
                }
            };

            if (addSecurityProfileInresponse)
            {
                cluster.Properties.SecurityProfile = new SecurityProfile()
                {
                    Domain = "domain.com",
                    DomainUsername = "******",
                    DomainUserPassword = "******",
                    OrganizationalUnitDN = "OUDN",
                    LdapsUrls = new[]
                    {
                        "ldapsurl"
                    },
                    ClusterUsersGroupDNs = new[]
                    {
                        "userGroupDn"
                    }
                };
            }

            var coreConfigs = new Dictionary<string, string>
            {
                {"fs.defaultFS", "wasb://giyertestcsmv2@" + StorageName},
                {
                    "fs.azure.account.key." + StorageName,
                    StorageKey
                }
            };
            var gatewayConfigs = new Dictionary<string, string>
            {
                {"restAuthCredential.isEnabled", "true"},
                {"restAuthCredential.username", _httpCred.UserName},
                {"restAuthCredential.password", _httpCred.Password.ConvertToString()}
            };

            var configurations = new Dictionary<string, Dictionary<string, string>>
            {
                {"core-site", coreConfigs},
                {"gateway", gatewayConfigs}
            };
            var serializedConfig = JsonConvert.SerializeObject(configurations);
            cluster.Properties.ClusterDefinition.Configurations = serializedConfig;

            var getresponse = new ClusterGetResponse {Cluster = cluster};

            hdinsightManagementMock.Setup(
                c => c.CreateNewCluster(ResourceGroupName, ClusterName, It.Is<ClusterCreateParameters>(
                    parameters =>
                        parameters.ClusterSizeInNodes == ClusterSize &&
                        parameters.DefaultStorageAccountName == StorageName &&
                        parameters.DefaultStorageAccountKey == StorageKey &&
                        parameters.Location == Location &&
                        parameters.UserName == _httpCred.UserName &&
                        parameters.Password == _httpCred.Password.ConvertToString() &&
                        parameters.ClusterType == ClusterType &&
                        parameters.OSType == OSType.Linux &&
                        parameters.SshUserName == _sshCred.UserName &&
                        parameters.SshPassword == _sshCred.Password.ConvertToString())))
                .Returns(getresponse)
                .Verifiable();

            cmdlet.ExecuteCmdlet();

            commandRuntimeMock.VerifyAll();
            commandRuntimeMock.Verify(f => f.WriteObject(It.Is<AzureHDInsightCluster>(
                clusterout =>
                    clusterout.ClusterState == "Running" &&
                    clusterout.ClusterType == ClusterType &&
                    clusterout.ClusterVersion == "3.1" &&
                    clusterout.CoresUsed == 24 &&
                    clusterout.Location == Location &&
                    clusterout.Name == ClusterName &&
                    clusterout.OperatingSystemType == OSType.Linux)),
                    Times.Once);
        }