Пример #1
0
        public void ConstructsDictionaryForProviderWitMultipleResourceTypes()
        {
            List <Provider> ProviderList = new List <Provider>();
            var             provider     = new Provider(
                namespaceProperty: "Microsoft.Mock",
                resourceTypes: new[]
            {
                new ProviderResourceType
                {
                    Locations    = new[] { "westus" },
                    ResourceType = "mock1",
                },
                new ProviderResourceType
                {
                    Locations    = new[] { "westus" },
                    ResourceType = "mock2",
                }
            });

            ProviderList.Add(provider);

            var resourceTypeLocationDictionary = LocationCompleterAttribute.CreateLocationDictionary(ProviderList);

            var matchingDictionary = new ConcurrentDictionary <string, ICollection <string> >();

            matchingDictionary.TryAdd("Microsoft.Mock/mock1", new string[] { "westus" });
            matchingDictionary.TryAdd("Microsoft.Mock/mock2", new string[] { "westus" });
            Assert.Equal(resourceTypeLocationDictionary, matchingDictionary);
        }
Пример #2
0
        public void ReturnsErrorForResourceTypesWithNoOverlap()
        {
            var resourceTypeLocationDictionary = SetMockDictionary();

            var ex = Assert.Throws <Exception>(() => LocationCompleterAttribute.FindLocations(new string[] { "Microsoft.Mock/mock3", "Microsoft.Mock/mock5" }, resourceTypeLocationDictionary));

            Assert.Equal(ex.Message, "No locations exist for all of the given ResourceTypes.");
        }
Пример #3
0
        public void ReturnsErrorForInvalidResourceType()
        {
            var resourceTypeLocationDictionary = SetMockDictionary();

            var ex = Assert.Throws <Exception>(() => LocationCompleterAttribute.FindLocations(new string[] { "Microsoft.InvalidResourceType/operations" }, resourceTypeLocationDictionary));

            Assert.Equal(ex.Message, "ResourceType name: 'Microsoft.InvalidResourceType/operations' is invalid.");
        }
Пример #4
0
        public void ReturnsErrorForEmptyResourceTypeList()
        {
            var resourceTypeLocationDictionary = SetMockDictionary();

            var ex = Assert.Throws <Exception>(() => LocationCompleterAttribute.FindLocations(new string[] { }, resourceTypeLocationDictionary));

            Assert.Equal(ex.Message, "No valid ResourceType given to LocationCompleter.");
        }
Пример #5
0
        public void ConstructsDictionaryForProviderWithNoResourceTypes()
        {
            List <Provider> ProviderList = new List <Provider>();
            var             provider     = new Provider(
                namespaceProperty: "Microsoft.Mock",
                resourceTypes: new ProviderResourceType[] { });

            ProviderList.Add(provider);

            var resourceTypeLocationDictionary = LocationCompleterAttribute.CreateLocationDictionary(ProviderList);

            Assert.Empty(resourceTypeLocationDictionary);
        }
        /// <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);
            }
        }
Пример #7
0
        public void ReturnsFullOverlapForMultipleResourceTypes()
        {
            var resourceTypeLocationDictionary = SetMockDictionary();

            Assert.Equal(LocationCompleterAttribute.FindLocations(new string[] { "Microsoft.Mock/mock5", "Microsoft.Mock/mock6" }, resourceTypeLocationDictionary), new string[] { "\"eastus\"", "\"china\"" });
        }
Пример #8
0
        public void ReturnsAllLocationForResourceTypeWithMultipleLocations()
        {
            var resourceTypeLocationDictionary = SetMockDictionary();

            Assert.Equal(LocationCompleterAttribute.FindLocations(new string[] { "Microsoft.Mock/mock3" }, resourceTypeLocationDictionary), new string[] { "\"westus\"", "\"centralus\"" });
        }
Пример #9
0
        public void ConstructsEmptyDictionaryForNoProviders()
        {
            var resourceTypeLocationDictionary = LocationCompleterAttribute.CreateLocationDictionary(new List <Provider>());

            Assert.Empty(resourceTypeLocationDictionary);
        }
Пример #10
0
        public void ReturnsLocationForLowercaseProvider()
        {
            var resourceTypeLocationDictionary = SetMockDictionary();

            Assert.Equal(LocationCompleterAttribute.FindLocations(new string[] { "microsofT.mock/mock2" }, resourceTypeLocationDictionary), new string[] { "\"westus\"" });
        }
Пример #11
0
        public void LocationListRecognizesDifferentFormats()
        {
            var resourceTypeLocationDictionary = SetMockDictionary();

            Assert.Equal(LocationCompleterAttribute.FindLocations(new string[] { "Microsoft.Mock/mock3", "Microsoft.Mock/mock7" }, resourceTypeLocationDictionary), new string[] { "\"westus\"", "\"centralus\"" });
        }
Пример #12
0
        public void ReturnsOverlapForMultipleResourceTypes()
        {
            var resourceTypeLocationDictionary = SetMockDictionary();

            Assert.Equal(LocationCompleterAttribute.FindLocations(new string[] { "Microsoft.Mock/mock3", "Microsoft.Mock/mock4" }, resourceTypeLocationDictionary), new string[] { "\'westus\'" });
        }
Пример #13
0
        public void ReturnsLocationForResourceTypeWithOneLocation()
        {
            var resourceTypeLocationDictionary = SetMockDictionary();

            Assert.Equal(LocationCompleterAttribute.FindLocations(new string[] { "Microsoft.Mock/mock2" }, resourceTypeLocationDictionary), new string[] { "\'westus\'" });
        }