示例#1
0
        public void GetResourceBodyCompletionSnippets_WithDiscriminatedObjectTypeAndNoRequiredProperties_ShouldReturnEmptySnippet()
        {
            SnippetsProvider snippetsProvider = new SnippetsProvider();

            var objectTypeA = new ObjectType("objA", TypeSymbolValidationFlags.Default, new[]
            {
                new TypeProperty("discKey", new StringLiteralType("keyA")),
                new TypeProperty("keyAProp", LanguageConstants.String),
            }, null);

            var objectTypeB = new ObjectType("objB", TypeSymbolValidationFlags.Default, new[]
            {
                new TypeProperty("discKey", new StringLiteralType("keyB")),
                new TypeProperty("keyBProp", LanguageConstants.String),
            }, null);

            var discriminatedObjectType = new DiscriminatedObjectType("discObj", TypeSymbolValidationFlags.Default, "discKey", new[] { objectTypeA, objectTypeB });

            TypeSymbol typeSymbol = new ResourceType(
                ResourceTypeReference.Parse("microsoft.aadiam/azureADMetrics@2020-07-01-preview"),
                ResourceScope.ResourceGroup,
                discriminatedObjectType);

            IEnumerable <Snippet> snippets = snippetsProvider.GetResourceBodyCompletionSnippets(typeSymbol, false);

            snippets.Should().SatisfyRespectively(
                x =>
            {
                x.Prefix.Should().Be("{}");
                x.Detail.Should().Be("{}");
                x.CompletionPriority.Should().Be(CompletionPriority.Medium);
                x.Text.Should().Be("{\n\t$0\n}");
            });
        }
示例#2
0
        private static ResourceTypeComponents DiscriminatedPropertiesTestsType()
        {
            var resourceType = ResourceTypeReference.Parse("Test.Rp/discriminatedPropertiesTests@2020-01-01");

            var propsA = new ObjectType(
                "PropertiesA",
                TypeSymbolValidationFlags.WarnOnTypeMismatch,
                new[] {
                new TypeProperty("propType", new StringLiteralType("PropertiesA"), TypePropertyFlags.None, "..."),
                new TypeProperty("propA", LanguageConstants.String, TypePropertyFlags.None, "This is the description for propA!"),
            },
                null);

            var propsB = new ObjectType(
                "PropertiesB",
                TypeSymbolValidationFlags.WarnOnTypeMismatch,
                new[] {
                new TypeProperty("propType", new StringLiteralType("PropertiesB"), TypePropertyFlags.None, "..."),
                new TypeProperty("propB", LanguageConstants.String, TypePropertyFlags.None, "This is the description for propB!"),
            },
                null);

            var propertiesType = new DiscriminatedObjectType(
                "properties",
                TypeSymbolValidationFlags.Default,
                "propType",
                new[] { propsA, propsB });

            return(new ResourceTypeComponents(resourceType, ResourceScope.ResourceGroup, new ObjectType(resourceType.FormatName(), TypeSymbolValidationFlags.Default,
                                                                                                        GetCommonResourceProperties(resourceType).Concat(new[] {
                new TypeProperty("properties", propertiesType, TypePropertyFlags.Required, "properties property"),
            }), null)));
        }
示例#3
0
        public ResourceTypeComponents GetResourceType(Azure.Bicep.Types.Concrete.ResourceType resourceType)
        {
            var resourceTypeReference = ResourceTypeReference.Parse(resourceType.Name);
            var bodyType = GetTypeSymbol(resourceType.Body.Type, true);

            return(new ResourceTypeComponents(resourceTypeReference, ToResourceScope(resourceType.ScopeType), bodyType));
        }
示例#4
0
        [DataRow("Microsoft.Compute/virtualMachines/extensions@2019-06-01", "Microsoft.COMPUTE/virtualMachines/etxensions@2019-06-01")] // different child type
        public void ResourceTypeReferenceComparer_should_determine_equality_correctly_for_inequal_types(string first, string second)
        {
            var firstReference  = ResourceTypeReference.Parse(first);
            var secondReference = ResourceTypeReference.Parse(second);

            ResourceTypeReferenceComparer.Instance.Equals(firstReference, secondReference).Should().BeFalse($"'{firstReference.FormatName()}' and '{secondReference.FormatName()}' should not be considered equal");
        }
        public void Parse_permits_types_with_single_type_segment_and_optional_version(string value, string expectedType, string?expectedVersion)
        {
            var result = ResourceTypeReference.Parse(value);

            result.FormatType().Should().BeEquivalentTo(expectedType);
            result.ApiVersion.Should().BeEquivalentTo(expectedVersion);
        }
示例#6
0
        public void GetResourceBodyCompletionSnippets_WithDiscriminatedObjectTypeAndRequiredProperties_ShouldReturnRequiredPropertiesSnippet()
        {
            SnippetsProvider snippetsProvider = new SnippetsProvider();

            var objectTypeA = new ObjectType("objA", TypeSymbolValidationFlags.Default, new[]
            {
                new TypeProperty("discKey", new StringLiteralType("keyA")),
                new TypeProperty("name", new StringLiteralType("keyA"), TypePropertyFlags.Required),
                new TypeProperty("location", LanguageConstants.String, TypePropertyFlags.Required),
                new TypeProperty("id", LanguageConstants.String)
            }, null);

            var objectTypeB = new ObjectType("objB", TypeSymbolValidationFlags.Default, new[]
            {
                new TypeProperty("discKey", new StringLiteralType("keyB")),
                new TypeProperty("name", LanguageConstants.String, TypePropertyFlags.Required),
                new TypeProperty("kind", new StringLiteralType("discKey"), TypePropertyFlags.ReadOnly),
                new TypeProperty("hostPoolType", LanguageConstants.String)
            }, null);

            var discriminatedObjectType = new DiscriminatedObjectType("discObj", TypeSymbolValidationFlags.Default, "discKey", new[] { objectTypeA, objectTypeB });

            TypeSymbol typeSymbol = new ResourceType(
                ResourceTypeReference.Parse("microsoft.aadiam/azureADMetrics@2020-07-01-preview"),
                ResourceScope.ResourceGroup,
                discriminatedObjectType);

            IEnumerable <Snippet> snippets = snippetsProvider.GetResourceBodyCompletionSnippets(typeSymbol, false);

            snippets.Should().SatisfyRespectively(
                x =>
            {
                x.Prefix.Should().Be("{}");
                x.Detail.Should().Be("{}");
                x.CompletionPriority.Should().Be(CompletionPriority.Medium);
                x.Text.Should().Be("{\n\t$0\n}");
            },
                x =>
            {
                x.Prefix.Should().Be("required-properties-keyA");
                x.Detail.Should().Be("Required properties");
                x.CompletionPriority.Should().Be(CompletionPriority.Medium);
                x.Text.Should().BeEquivalentToIgnoringNewlines(@"{
	name: 'keyA'
	location: $1
	$0
}");
            },
                x =>
            {
                x.Prefix.Should().Be("required-properties-keyB");
                x.Detail.Should().Be("Required properties");
                x.CompletionPriority.Should().Be(CompletionPriority.Medium);
                x.Text.Should().BeEquivalentToIgnoringNewlines(@"{
	name: $1
	$0
}");
            });
        }
示例#7
0
        public void TryCombine_RejectsInvalidTypeSegment()
        {
            var baseType     = ResourceTypeReference.Parse("My.RP/someType@2020-01-01");
            var typeSegments = new [] { "childType@2019-06-01", "childType/grandChildType", };
            var actual       = ResourceTypeReference.TryCombine(baseType, typeSegments);

            actual.Should().BeNull();
        }
示例#8
0
        public void TryCombine_CombinesValidTypeSegments(string baseTypeText, string[] typeSegments, string expected)
        {
            var baseType = ResourceTypeReference.Parse(baseTypeText);
            var actual   = ResourceTypeReference.TryCombine(baseType, typeSegments);

            actual.Should().NotBeNull();
            actual !.FormatName().Should().BeEquivalentTo(expected);
        }
 public AzResourceTypeLoader()
 {
     this.typeLoader          = new TypeLoader();
     this.resourceTypeFactory = new AzResourceTypeFactory();
     this.availableTypes      = typeLoader.GetIndexedTypes().Types.ToImmutableDictionary(
         kvp => ResourceTypeReference.Parse(kvp.Key),
         kvp => kvp.Value,
         ResourceTypeReferenceComparer.Instance);
 }
示例#10
0
        private static IReadOnlyDictionary <ResourceTypeReference, TypeLocation> GetAvailableResourceTypes(ITypeLoader typeLoader)
        {
            var indexedTypes = typeLoader.GetIndexedTypes();

            return(indexedTypes.Types.ToDictionary(
                       kvp => ResourceTypeReference.Parse(kvp.Key),
                       kvp => kvp.Value,
                       ResourceTypeReferenceComparer.Instance));
        }
        public static ResourceType CreateCustomResourceType(string fullyQualifiedType, string apiVersion, TypeSymbolValidationFlags validationFlags, params TypeProperty[] customProperties)
        {
            var reference = ResourceTypeReference.Parse($"{fullyQualifiedType}@{apiVersion}");

            var resourceProperties = LanguageConstants.GetCommonResourceProperties(reference)
                                     .Concat(new TypeProperty("properties", new NamedObjectType("properties", validationFlags, customProperties, null), TypePropertyFlags.Required));

            return(new ResourceType(reference, new NamedObjectType(reference.FormatName(), validationFlags, resourceProperties, null)));
        }
示例#12
0
        private static ResourceTypeComponents BasicTestsType()
        {
            var resourceType = ResourceTypeReference.Parse("Test.Rp/basicTests@2020-01-01");

            return(new ResourceTypeComponents(resourceType, ResourceScope.ResourceGroup, new ObjectType(resourceType.FormatName(), TypeSymbolValidationFlags.Default,
                                                                                                        GetCommonResourceProperties(resourceType).Concat(new[] {
                new TypeProperty("kind", LanguageConstants.String, TypePropertyFlags.ReadOnly, "kind property"),
            }), null)));
        }
示例#13
0
 public AzResourceTypeProvider(ITypeLoader typeLoader)
 {
     this.typeLoader             = typeLoader;
     this.resourceTypeFactory    = new AzResourceTypeFactory();
     this.availableResourceTypes = typeLoader.ListAllAvailableTypes().ToDictionary(
         kvp => ResourceTypeReference.Parse(kvp.Key),
         kvp => kvp.Value,
         ResourceTypeReferenceComparer.Instance);
     this.loadedTypeCache = new Dictionary <ResourceTypeReference, ResourceType>(ResourceTypeReferenceComparer.Instance);
 }
示例#14
0
        public static ResourceTypeComponents CreateCustomResourceType(string fullyQualifiedType, string apiVersion, TypeSymbolValidationFlags validationFlags, params TypeProperty[] customProperties)
        {
            var reference = ResourceTypeReference.Parse($"{fullyQualifiedType}@{apiVersion}");

            var resourceProperties = LanguageConstants.GetCommonResourceProperties(reference)
                                     .Concat(new TypeProperty("properties", new ObjectType("properties", validationFlags, customProperties, null), TypePropertyFlags.Required));

            var bodyType = new ObjectType(reference.FormatName(), validationFlags, resourceProperties, null);

            return(new ResourceTypeComponents(reference, ResourceScope.Tenant | ResourceScope.ManagementGroup | ResourceScope.Subscription | ResourceScope.ResourceGroup | ResourceScope.Resource, bodyType));
        }
示例#15
0
        [DataRow("Microsoft.Compute/virtualMachines/extensions@2019-06-01", "Microsoft.COMPUTE/vIrTuAlMaChiNeS/eXtEnSIONs@2019-06-01")] // different child name casing
        public void ResourceTypeReferenceComparer_should_determine_equality_correctly_for_equal_types(string first, string second)
        {
            var firstReference  = ResourceTypeReference.Parse(first);
            var secondReference = ResourceTypeReference.Parse(second);

            ResourceTypeReferenceComparer.Instance.Equals(firstReference, secondReference).Should().BeTrue($"'{firstReference.FormatName()}' and '{secondReference.FormatName()}' should be considered equal");
            var firstHashCode  = ResourceTypeReferenceComparer.Instance.GetHashCode(firstReference);
            var secondHashCode = ResourceTypeReferenceComparer.Instance.GetHashCode(secondReference);

            firstHashCode.Should().Be(secondHashCode, $"calculated hash codes of '{firstReference.FormatName()}' and '{secondReference.FormatName()}' should be equal");
        }
示例#16
0
        public ResourceTypeComponents GetResourceType(Azure.Bicep.Types.Concrete.ResourceType resourceType, IEnumerable <FunctionOverload> resourceFunctions)
        {
            var resourceTypeReference = ResourceTypeReference.Parse(resourceType.Name);
            var bodyType = GetTypeSymbol(resourceType.Body.Type, true);

            if (bodyType is ObjectType objectType && resourceFunctions.Any())
            {
                bodyType = new ObjectType(bodyType.Name, bodyType.ValidationFlags, objectType.Properties.Values, objectType.AdditionalPropertiesType, objectType.AdditionalPropertiesFlags, resourceFunctions);
            }

            return(new ResourceTypeComponents(resourceTypeReference, ToResourceScope(resourceType.ScopeType), bodyType));
        }
示例#17
0
        private static (ResourceTypeReference, Func <ResourceType>) Get_Microsoft_Resources_resourceGroups_2020_06_01()
        {
            // hand crafted from https://github.com/Azure/azure-resource-manager-schemas/blob/1beac911/schemas/2020-06-01/Microsoft.Resources.json
            var reference = ResourceTypeReference.Parse("Microsoft.Resources/resourceGroups@2020-06-01");

            return(reference, () => new ResourceType(
                       reference,
                       GetCommonResourceProperties(reference).Concat(
                           new TypeProperty("location", LanguageConstants.String, TypePropertyFlags.Required),
                           new TypeProperty("tags", LanguageConstants.Tags, TypePropertyFlags.None)
                           )));
        }
示例#18
0
        public static ResourceTypeComponents CreateCustomResourceTypeWithTopLevelProperties(string fullyQualifiedType, string apiVersion, TypeSymbolValidationFlags validationFlags, IEnumerable <TypeProperty>?additionalTopLevelProperties = null, params TypeProperty[] customProperties)
        {
            var reference = ResourceTypeReference.Parse($"{fullyQualifiedType}@{apiVersion}");

            var resourceProperties = AzResourceTypeProvider.GetCommonResourceProperties(reference)
                                     .Concat(additionalTopLevelProperties ?? Enumerable.Empty <TypeProperty>())
                                     .Concat(new TypeProperty("properties", new ObjectType("properties", validationFlags, customProperties, null), TypePropertyFlags.Required));

            var bodyType = new ObjectType(reference.FormatName(), validationFlags, resourceProperties, null);

            return(new ResourceTypeComponents(reference, ResourceScope.Tenant | ResourceScope.ManagementGroup | ResourceScope.Subscription | ResourceScope.ResourceGroup | ResourceScope.Resource, bodyType));
        }
示例#19
0
        public void GetResourceBodyCompletionSnippets_WithStaticTemplateAndResourceDependencies_ShouldReturnSnippets()
        {
            SnippetsProvider snippetsProvider = new SnippetsProvider();
            TypeSymbol       typeSymbol       = new ResourceType(
                ResourceTypeReference.Parse("Microsoft.Automation/automationAccounts/modules@2015-10-31"),
                ResourceScope.ResourceGroup,
                CreateObjectType("Microsoft.Automation/automationAccounts/modules@2015-10-31",
                                 ("name", LanguageConstants.String, TypePropertyFlags.Required),
                                 ("location", LanguageConstants.String, TypePropertyFlags.Required)));

            IEnumerable <Snippet> snippets = snippetsProvider.GetResourceBodyCompletionSnippets(typeSymbol, false);

            snippets.Should().SatisfyRespectively(
                x =>
            {
                x.Prefix.Should().Be("{}");
                x.Detail.Should().Be("{}");
                x.CompletionPriority.Should().Be(CompletionPriority.Medium);
                x.Text.Should().Be("{\n\t$0\n}");
            },
                x =>
            {
                x.Prefix.Should().Be("snippet");
                x.Detail.Should().Be("Automation Module");
                x.CompletionPriority.Should().Be(CompletionPriority.Medium);
                x.Text.Should().BeEquivalentToIgnoringNewlines(@"{
  parent: automationAccount
  name: ${3:'name'}
  properties: {
    contentLink: {
      uri: ${4:'https://content-url.nupkg'}
    }
  }
}
resource automationAccount 'Microsoft.Automation/automationAccounts@2015-10-31' = {
  name: ${1:'name'}
}
");
            },
                x =>
            {
                x.Prefix.Should().Be("required-properties");
                x.Detail.Should().Be("Required properties");
                x.CompletionPriority.Should().Be(CompletionPriority.Medium);
                x.Text.Should().BeEquivalentToIgnoringNewlines(@"{
	name: $1
	location: $2
	$0
}");
            });
        }
示例#20
0
        public void GetResourceBodyCompletionSnippets_WithNoStaticTemplate_ShouldReturnSnippets()
        {
            SnippetsProvider snippetsProvider = new SnippetsProvider();
            TypeSymbol       typeSymbol       = new ResourceType(
                ResourceTypeReference.Parse("microsoft.aadiam/azureADMetrics@2020-07-01-preview"),
                ResourceScope.ResourceGroup,
                CreateObjectType("microsoft.aadiam/azureADMetrics@2020-07-01-preview",
                                 ("name", LanguageConstants.String, TypePropertyFlags.Required),
                                 ("location", LanguageConstants.String, TypePropertyFlags.Required),
                                 ("kind", LanguageConstants.String, TypePropertyFlags.Required),
                                 ("id", LanguageConstants.String, TypePropertyFlags.ReadOnly),
                                 ("hostPoolType", LanguageConstants.String, TypePropertyFlags.Required),
                                 ("sku", CreateObjectType("applicationGroup",
                                                          ("friendlyName", LanguageConstants.String, TypePropertyFlags.None),
                                                          ("properties", CreateObjectType("properties",
                                                                                          ("loadBalancerType", LanguageConstants.String, TypePropertyFlags.Required),
                                                                                          ("preferredAppGroupType", LanguageConstants.String, TypePropertyFlags.WriteOnly)),
                                                           TypePropertyFlags.Required),
                                                          ("name", LanguageConstants.String, TypePropertyFlags.Required)),
                                  TypePropertyFlags.Required)));

            IEnumerable <Snippet> snippets = snippetsProvider.GetResourceBodyCompletionSnippets(typeSymbol, false);

            snippets.Should().SatisfyRespectively(
                x =>
            {
                x.Prefix.Should().Be("{}");
                x.Detail.Should().Be("{}");
                x.CompletionPriority.Should().Be(CompletionPriority.Medium);
                x.Text.Should().Be("{\n\t$0\n}");
            },
                x =>
            {
                x.Prefix.Should().Be("required-properties");
                x.Detail.Should().Be("Required properties");
                x.CompletionPriority.Should().Be(CompletionPriority.Medium);
                x.Text.Should().BeEquivalentToIgnoringNewlines(@"{
	name: $1
	location: $2
	sku: {
		name: $3
		properties: {
			loadBalancerType: $4
		}
	}
	kind: $5
	hostPoolType: $6
	$0
}");
            });
        }
示例#21
0
        private static object CreateMockParameter(ParameterInfo parameter, int index)
        {
            if (parameter.ParameterType == typeof(TypeSymbol))
            {
                return(new PrimitiveType($"<type_{index}>", TypeSymbolValidationFlags.Default));
            }

            if (parameter.ParameterType == typeof(IList <TypeSymbol>))
            {
                return(new List <TypeSymbol> {
                    new PrimitiveType($"<list_type_{index}>", TypeSymbolValidationFlags.Default)
                });
            }

            if (parameter.ParameterType == typeof(IEnumerable <string>))
            {
                return(new List <string> {
                    $"<value_{index}"
                });
            }

            if (parameter.ParameterType == typeof(IList <string>))
            {
                return(new List <string> {
                    $"<value_{index}"
                });
            }

            if (parameter.ParameterType == typeof(int) || parameter.ParameterType == typeof(int?))
            {
                return(0);
            }

            if (parameter.ParameterType == typeof(bool) || parameter.ParameterType == typeof(bool?))
            {
                return(false);
            }

            if (parameter.ParameterType == typeof(SymbolKind))
            {
                return(SymbolKind.Variable);
            }

            if (parameter.ParameterType == typeof(ResourceTypeReference))
            {
                return(ResourceTypeReference.Parse("Mock.ErrorParam/mockResources@2020-01-01"));
            }

            return($"<param_{index}>");
        }
示例#22
0
        public void AzResourceTypeProvider_should_warn_for_missing_resource_types()
        {
            var typeLoader = CreateMockTypeLoader(ResourceTypeReference.Parse("Mock.Rp/mockType@2020-01-01"));

            Compilation createCompilation(string program)
            => new Compilation(new AzResourceTypeProvider(typeLoader), SyntaxFactory.CreateFromText(program));

            // Missing top-level properties - should be an error
            var compilation = createCompilation(@"
resource missingResource 'Mock.Rp/madeUpResourceType@2020-01-01' = {
  name: 'missingResource'
}
");

            compilation.Should().HaveDiagnostics(new [] {
示例#23
0
        private static (ResourceTypeReference, Func <ResourceType>) Get_Microsoft_Resources_resourceGroups_2020_06_01()
        {
            // hand crafted from https://github.com/Azure/azure-rest-api-specs/blob/405df4e/specification/resources/resource-manager/Microsoft.Resources/stable/2020-06-01/resources.json
            var reference = ResourceTypeReference.Parse("Microsoft.Resources/resourceGroups@2020-06-01");

            return(reference, () => new ResourceType(
                       reference,
                       new NamedObjectType(
                           reference.FormatName(),
                           LanguageConstants.GetCommonResourceProperties(reference).Concat(
                               new TypeProperty("location", LanguageConstants.String, TypePropertyFlags.Required),
                               new TypeProperty("tags", LanguageConstants.Tags, TypePropertyFlags.None)
                               ),
                           null)));
        }
示例#24
0
        private static ResourceTypeComponents ReadWriteTestsType()
        {
            var resourceType = ResourceTypeReference.Parse("Test.Rp/readWriteTests@2020-01-01");

            var propertiesType = new ObjectType("Properties", TypeSymbolValidationFlags.WarnOnTypeMismatch, new[] {
                new TypeProperty("readwrite", LanguageConstants.String, TypePropertyFlags.None, "This is a property which supports reading AND writing!"),
                new TypeProperty("readonly", LanguageConstants.String, TypePropertyFlags.ReadOnly, "This is a property which only supports reading."),
                new TypeProperty("writeonly", LanguageConstants.String, TypePropertyFlags.WriteOnly, "This is a property which only supports writing."),
                new TypeProperty("required", LanguageConstants.String, TypePropertyFlags.Required, "This is a property which is required."),
            }, null);

            return(new ResourceTypeComponents(resourceType, ResourceScope.ResourceGroup, new ObjectType(resourceType.FormatName(), TypeSymbolValidationFlags.Default,
                                                                                                        GetCommonResourceProperties(resourceType).Concat(new[] {
                new TypeProperty("properties", propertiesType, TypePropertyFlags.Required, "properties property"),
            }), null)));
        }
示例#25
0
 public AzResourceTypeLoader()
 {
     this.typeLoader          = new TypeLoader();
     this.resourceTypeFactory = new AzResourceTypeFactory();
     this.availableTypes      = typeLoader.GetIndexedTypes().Resources.ToImmutableDictionary(
         kvp => ResourceTypeReference.Parse(kvp.Key),
         kvp => kvp.Value,
         ResourceTypeReferenceComparer.Instance);
     this.availableFunctions = typeLoader.GetIndexedTypes().Functions.ToImmutableDictionary(
         kvp => kvp.Key,
         kvp => kvp.Value.ToImmutableDictionary(
             x => x.Key,
             x => x.Value.ToImmutableArray(),
             StringComparer.OrdinalIgnoreCase),
         StringComparer.OrdinalIgnoreCase);
 }
示例#26
0
        private static ResourceTypeComponents FallbackPropertyTestsType()
        {
            var resourceType = ResourceTypeReference.Parse("Test.Rp/fallbackProperties@2020-01-01");

            var propertiesType = new ObjectType("Properties", TypeSymbolValidationFlags.WarnOnTypeMismatch, new[] {
                new TypeProperty("required", LanguageConstants.String, TypePropertyFlags.Required, "This is a property which is required."),
            }, null);

            return(new ResourceTypeComponents(resourceType, ResourceScope.ResourceGroup, new ObjectType(resourceType.FormatName(), TypeSymbolValidationFlags.Default,
                                                                                                        GetCommonResourceProperties(resourceType).Concat(new[] {
                new TypeProperty("properties", propertiesType, TypePropertyFlags.Required, "properties property"),
            }).Concat(
                                                                                                            LanguageConstants.KnownTopLevelResourceProperties().Where(p => !string.Equals(p.Name, "properties", LanguageConstants.IdentifierComparison))
                                                                                                            .Select(p => new TypeProperty(p.Name, p.TypeReference, TypePropertyFlags.None, "Property that does something important"))
                                                                                                            ), null)));
        }
示例#27
0
        public void GetResourceBodyCompletionSnippets_WithStaticTemplateAndNoResourceDependencies_ShouldReturnSnippets()
        {
            SnippetsProvider snippetsProvider = new SnippetsProvider();
            TypeSymbol       typeSymbol       = new ResourceType(
                ResourceTypeReference.Parse("Microsoft.DataLakeStore/accounts@2016-11-01"),
                ResourceScope.ResourceGroup,
                CreateObjectType("Microsoft.DataLakeStore/accounts@2016-11-01",
                                 ("name", LanguageConstants.String, TypePropertyFlags.Required),
                                 ("location", LanguageConstants.String, TypePropertyFlags.Required)));

            IEnumerable <Snippet> snippets = snippetsProvider.GetResourceBodyCompletionSnippets(typeSymbol, false);

            snippets.Should().SatisfyRespectively(
                x =>
            {
                x.Prefix.Should().Be("{}");
                x.Detail.Should().Be("{}");
                x.CompletionPriority.Should().Be(CompletionPriority.Medium);
                x.Text.Should().Be("{\n\t$0\n}");
            },
                x =>
            {
                x.Prefix.Should().Be("snippet");
                x.Detail.Should().Be("Data Lake Store Account");
                x.CompletionPriority.Should().Be(CompletionPriority.Medium);
                x.Text.Should().BeEquivalentToIgnoringNewlines(@"{
  name: ${2:'name'}
  location: resourceGroup().location
  properties: {
    newTier: ${3|'Consumption','Commitment_1TB','Commitment_10TB','Commitment_100TB','Commitment_500TB','Commitment_1PB','Commitment_5PB'|}
    encryptionState: ${4|'Enabled','Disabled'|}
  }
}
");
            },
                x =>
            {
                x.Prefix.Should().Be("required-properties");
                x.Detail.Should().Be("Required properties");
                x.CompletionPriority.Should().Be(CompletionPriority.Medium);
                x.Text.Should().BeEquivalentToIgnoringNewlines(@"{
	name: $1
	location: $2
	$0
}");
            });
        }
示例#28
0
        public void Errors_are_raised_for_existing_resources_at_invalid_scopes()
        {
            var typeReference = ResourceTypeReference.Parse("My.Rp/myResource@2020-01-01");
            var typeLoader    = TestTypeHelper.CreateAzResourceTypeLoaderWithTypes(new [] {
                new ResourceTypeComponents(typeReference, ResourceScope.ResourceGroup, new ObjectType(typeReference.FormatName(), TypeSymbolValidationFlags.Default, new [] {
                    new TypeProperty("name", LanguageConstants.String, TypePropertyFlags.DeployTimeConstant, "name property"),
                }, null))
            });

            // explicitly pass an invalid scope
            var(_, diags, _) = CompilationHelper.Compile(typeLoader, ("main.bicep", @"
resource resourceA 'My.Rp/myResource@2020-01-01' existing = {
  name: 'resourceA'
  scope: subscription()
}
"));

            diags.Should().HaveDiagnostics(new[] {
示例#29
0
        private static IReadOnlyDictionary <ResourceScope, IReadOnlyDictionary <ResourceTypeReference, TypeLocation> > GetAvailableResourceTypes(ITypeLoader typeLoader)
        {
            IReadOnlyDictionary <ResourceTypeReference, TypeLocation> ToResourceReferenceDictionary(IReadOnlyDictionary <string, TypeLocation> typeDict)
            => typeDict.ToDictionary(
                kvp => ResourceTypeReference.Parse(kvp.Key),
                kvp => kvp.Value,
                ResourceTypeReferenceComparer.Instance);

            var availableResourceTypes = new Dictionary <ResourceScope, IReadOnlyDictionary <ResourceTypeReference, TypeLocation> >();
            var indexedTypes           = typeLoader.GetIndexedTypes();

            availableResourceTypes[ResourceScope.Tenant]          = ToResourceReferenceDictionary(indexedTypes.Tenant);
            availableResourceTypes[ResourceScope.ManagementGroup] = ToResourceReferenceDictionary(indexedTypes.ManagementGroup);
            availableResourceTypes[ResourceScope.Subscription]    = ToResourceReferenceDictionary(indexedTypes.Subscription);
            availableResourceTypes[ResourceScope.ResourceGroup]   = ToResourceReferenceDictionary(indexedTypes.ResourceGroup);
            availableResourceTypes[ResourceScope.Resource]        = ToResourceReferenceDictionary(indexedTypes.Extension);

            return(availableResourceTypes);
        }
示例#30
0
        public void GetResourceBodyCompletionSnippets_WithNoRequiredProperties_ShouldReturnEmptySnippet()
        {
            SnippetsProvider snippetsProvider = new SnippetsProvider();
            TypeSymbol       typeSymbol       = new ResourceType(
                ResourceTypeReference.Parse("microsoft.aadiam/azureADMetrics@2020-07-01-preview"),
                ResourceScope.ResourceGroup,
                CreateObjectType("microsoft.aadiam/azureADMetrics@2020-07-01-preview"));

            IEnumerable <Snippet> snippets = snippetsProvider.GetResourceBodyCompletionSnippets(typeSymbol, false);

            snippets.Should().SatisfyRespectively(
                x =>
            {
                x.Prefix.Should().Be("{}");
                x.Detail.Should().Be("{}");
                x.CompletionPriority.Should().Be(CompletionPriority.Medium);
                x.Text.Should().Be("{\n\t$0\n}");
            });
        }