示例#1
0
        public void OneResourceGroupWithDefault()
        {
            IList <string> resourceGroupsReturned = new List <string>();

            resourceGroupsReturned.Add("test1");
            Assert.Collection(ResourceGroupCompleterAttribute.GetResourceGroups(resourceGroupsReturned, "test1"), e1 => Assert.Equal("test1", e1));
        }
示例#2
0
        public void MultipleResourceGroupsWithDefault()
        {
            IList <string> resourceGroupsReturned = new List <string>();

            resourceGroupsReturned.Add("test1");
            resourceGroupsReturned.Add("test2");
            resourceGroupsReturned.Add("test3");
            resourceGroupsReturned.Add("test4");
            Assert.Collection(ResourceGroupCompleterAttribute.GetResourceGroups(resourceGroupsReturned, "test3"), e1 => Assert.Equal("test3", e1),
                              e2 => Assert.Equal("test1", e2), e3 => Assert.Equal("test2", e3), e4 => Assert.Equal("test4", e4));
        }
        /// <summary>
        ///  Called for well-known parameters that require argument completers
        ///  </summary>
        /// <param name="completerName">string - the type of completer requested (Resource, Location)</param>
        /// <param name="invocationInfo">The <see cref="System.Management.Automation.InvocationInfo" /> from the cmdlet</param>
        /// <param name="correlationId">The <see cref="string" /> containing the correlation id for the cmdlet (if available)</param>
        /// <param name="resourceTypes">An <see cref="System.String[]"/> containing resource (or resource types) being completed  </param >
        /// <param name="parentResourceParameterNames"> An <see cref="System.String[]"/> containing list of parent resource parameter names (if applicable)</param >
        /// <returns>A <see cref="System.String[]"/> containing the valid options for the completer.</returns>
        public string[] CompleteArgument(string completerName, InvocationInfo invocationInfo, string correlationId, string[] resourceTypes, string[] parentResourceParameterNames)
        {
            var defaultValue = new string[0];

            switch (completerName)
            {
            case "Resource":
            {
                var      resourceType    = resourceTypes?.FirstOrDefault();
                string[] parentResources = ResolveParameterValues <string>(parentResourceParameterNames, invocationInfo);
                if (string.IsNullOrWhiteSpace(resourceType) || parentResources == null || parentResources.Length < 1)
                {
                    return(defaultValue);
                }

                return(ResourceNameCompleterAttribute.FindResources(resourceType, parentResourceParameterNames));
            }

            case "ResourceGroup":
            {
                return(ResourceGroupCompleterAttribute.GetResourceGroups());
            }

            case "ResourceId":
            {
                var resourceType = resourceTypes?.FirstOrDefault();
                if (string.IsNullOrWhiteSpace(resourceType))
                {
                    return(defaultValue);
                }

                return(ResourceIdCompleterAttribute.GetResourceIds(resourceType).ToArray());
            }

            case "Location":
                return(LocationCompleterAttribute.FindLocations(resourceTypes));

            default:
                return(defaultValue);
            }
        }
示例#4
0
        public void ReturnsEmptyListWhenNoResourceGroupsExist()
        {
            IList <string> resourceGroupsReturned = new List <string>();

            Assert.Collection(ResourceGroupCompleterAttribute.GetResourceGroups(resourceGroupsReturned, null));
        }