public void GetsResourcesGroupDeployments()
        {
            List<PSResourceGroupDeployment> result = new List<PSResourceGroupDeployment>();
            PSResourceGroupDeployment expected = new PSResourceGroupDeployment()
            {
                DeploymentName = deploymentName,
                CorrelationId = "123",
                ResourceGroupName = resourceGroupName,
                Mode = DeploymentMode.Incremental
            };
            FilterResourceGroupDeploymentOptions options = new FilterResourceGroupDeploymentOptions()
            {
                ResourceGroupName = resourceGroupName
            };
            FilterResourceGroupDeploymentOptions actual = new FilterResourceGroupDeploymentOptions();
            result.Add(expected);
            resourcesClientMock.Setup(f => f.FilterResourceGroupDeployments(It.IsAny<FilterResourceGroupDeploymentOptions>()))
                .Returns(result)
                .Callback((FilterResourceGroupDeploymentOptions o) => { actual = o; });

            cmdlet.ResourceGroupName = resourceGroupName;

            cmdlet.ExecuteCmdlet();

            commandRuntimeMock.Verify(f => f.WriteObject(result, true), Times.Once());
            Assert.Equal(options.DeploymentName, actual.DeploymentName);
            Assert.Equal(options.ExcludedProvisioningStates, actual.ExcludedProvisioningStates);
            Assert.Equal(options.ProvisioningStates, actual.ProvisioningStates);
            Assert.Equal(options.ResourceGroupName, actual.ResourceGroupName);
        }
        public override void ExecuteCmdlet()
        {
            FilterResourceGroupDeploymentOptions options = new FilterResourceGroupDeploymentOptions()
            {
                ResourceGroupName = ResourceGroupName ?? ResourceIdUtility.GetResourceGroupName(Id),
                DeploymentName = Name ?? (string.IsNullOrEmpty(Id) ? null : ResourceIdUtility.GetResourceName(Id))
            };

            WriteObject(ResourceManagerSdkClient.FilterResourceGroupDeployments(options), true);
        }
        /// <summary>
        /// Cancels the active deployment.
        /// </summary>
        /// <param name="resourceGroup">The resource group name</param>
        /// <param name="deploymentName">Deployment name</param>
        public virtual void CancelDeployment(string resourceGroup, string deploymentName)
        {
            FilterResourceGroupDeploymentOptions options = new FilterResourceGroupDeploymentOptions
            {
                DeploymentName = deploymentName,
                ResourceGroupName = resourceGroup
            };

            if (string.IsNullOrEmpty(deploymentName))
            {
                options.ExcludedProvisioningStates = new List<string>
                {
                    ProvisioningState.Failed.ToString(),
                    ProvisioningState.Succeeded.ToString()
                };
            }

            List<PSResourceGroupDeployment> deployments = FilterResourceGroupDeployments(options);

            if (deployments.Count == 0)
            {
                if (string.IsNullOrEmpty(deploymentName))
                {
                    throw new ArgumentException(string.Format(ProjectResources.NoDeploymentToCancel, deploymentName));
                }
                else
                {
                    throw new ArgumentException(string.Format(ProjectResources.NoRunningDeployments, resourceGroup));
                }
            }
            else if (deployments.Count == 1)
            {
                ResourceManagementClient.Deployments.Cancel(resourceGroup, deployments.First().DeploymentName);
            }
            else
            {
                throw new ArgumentException(ProjectResources.MultipleRunningDeployment);
            }
        }
        /// <summary>
        /// Filters the resource group deployments
        /// </summary>
        /// <param name="options">The filtering options</param>
        /// <returns>The filtered list of deployments</returns>
        public virtual List<PSResourceGroupDeployment> FilterResourceGroupDeployments(FilterResourceGroupDeploymentOptions options)
        {
            List<PSResourceGroupDeployment> deployments = new List<PSResourceGroupDeployment>();
            string resourceGroup = options.ResourceGroupName;
            string name = options.DeploymentName;
            List<string> excludedProvisioningStates = options.ExcludedProvisioningStates ?? new List<string>();

            if (!string.IsNullOrEmpty(resourceGroup) && !string.IsNullOrEmpty(name))
            {
                deployments.Add(ResourceManagementClient.Deployments.Get(resourceGroup, name).ToPSResourceGroupDeployment(options.ResourceGroupName));
            }
            else if (!string.IsNullOrEmpty(resourceGroup))
            {
                var result = ResourceManagementClient.Deployments.List(resourceGroup, null);

                deployments.AddRange(result.Select(d => d.ToPSResourceGroupDeployment(options.ResourceGroupName)));

                while (!string.IsNullOrEmpty(result.NextPageLink))
                {
                    result = ResourceManagementClient.Deployments.ListNext(result.NextPageLink);
                    deployments.AddRange(result.Select(d => d.ToPSResourceGroupDeployment(options.ResourceGroupName)));
                }
            }

            if (excludedProvisioningStates.Count > 0)
            {
                return deployments.Where(d => excludedProvisioningStates
                    .All(s => !s.Equals(d.ProvisioningState, StringComparison.OrdinalIgnoreCase))).ToList();
            }
            else
            {
                return deployments;
            }
        }