public static dynamic ToData(CdmAttributeGroupReference instance, ResolveOptions resOpt, CopyOptions options) { return(CdmObjectRefPersistence.ToData(instance, resOpt, options)); }
public async Task TestEntityAttribute() { string testName = "TestEntityAttribute"; string entityName = "ThreeMusketeers"; CdmCorpusDefinition corpus = TestHelper.GetLocalCorpus(testsSubpath, testName); foreach (List <string> resOpt in resOptsCombinations) { await ProjectionTestUtils.LoadEntityForResolutionOptionAndSave(corpus, testName, testsSubpath, entityName, resOpt); } CdmEntityDefinition entity = await corpus.FetchObjectAsync <CdmEntityDefinition>($"local:/{entityName}.cdm.json/{entityName}"); CdmEntityDefinition nonStructuredResolvedEntity = await ProjectionTestUtils.GetResolvedEntity(corpus, entity, new List <string> { }); // Original set of attributes: ["name", "age", "address"] // in non-structured form // addArtifactAttribute : { "key" , "insertAtTop": true } // Expand 1...3; // renameAttributes = { {a}_{o}_key, apply to "key" } // renameAttributes = { {a}_{m}_{o}_value, apply to "name", "age", "address" } // alterTraits = { indicates.expansionInfo.mapKey(expansionName: "{a}", ordinal: "{o}") , apply to "key" , "argumentsContainWildcards" : true } // alterTraits = { has.expansionInfo.mapValue(expansionName: "{a}", ordinal: "{o}", memberAttribute: "{mo}") , apply to "name", "age", "address" , "argumentsContainWildcards" : true } // addArtifactAttribute : "personCount" // alterTraits = { indicates.expansionInfo.count(expansionName: "{a}") , apply to "personCount" , "argumentsContainWildcards" : true } Assert.AreEqual(13, nonStructuredResolvedEntity.Attributes.Count); ValidateAttributeTrait(nonStructuredResolvedEntity.Attributes[0] as CdmTypeAttributeDefinition, "key_1_key", 1, "ThreePeople", isKey: true); ValidateAttributeTrait(nonStructuredResolvedEntity.Attributes[1] as CdmTypeAttributeDefinition, "ThreePeople_name_1_value", 1, "ThreePeople", "name"); ValidateAttributeTrait(nonStructuredResolvedEntity.Attributes[2] as CdmTypeAttributeDefinition, "ThreePeople_age_1_value", 1, "ThreePeople", "age"); ValidateAttributeTrait(nonStructuredResolvedEntity.Attributes[3] as CdmTypeAttributeDefinition, "ThreePeople_address_1_value", 1, "ThreePeople", "address"); ValidateAttributeTrait(nonStructuredResolvedEntity.Attributes[4] as CdmTypeAttributeDefinition, "key_2_key", 2, "ThreePeople", isKey: true); ValidateAttributeTrait(nonStructuredResolvedEntity.Attributes[5] as CdmTypeAttributeDefinition, "ThreePeople_name_2_value", 2, "ThreePeople", "name"); ValidateAttributeTrait(nonStructuredResolvedEntity.Attributes[6] as CdmTypeAttributeDefinition, "ThreePeople_age_2_value", 2, "ThreePeople", "age"); ValidateAttributeTrait(nonStructuredResolvedEntity.Attributes[7] as CdmTypeAttributeDefinition, "ThreePeople_address_2_value", 2, "ThreePeople", "address"); ValidateAttributeTrait(nonStructuredResolvedEntity.Attributes[8] as CdmTypeAttributeDefinition, "key_3_key", 3, "ThreePeople", isKey: true); ValidateAttributeTrait(nonStructuredResolvedEntity.Attributes[9] as CdmTypeAttributeDefinition, "ThreePeople_name_3_value", 3, "ThreePeople", "name"); ValidateAttributeTrait(nonStructuredResolvedEntity.Attributes[10] as CdmTypeAttributeDefinition, "ThreePeople_age_3_value", 3, "ThreePeople", "age"); ValidateAttributeTrait(nonStructuredResolvedEntity.Attributes[11] as CdmTypeAttributeDefinition, "ThreePeople_address_3_value", 3, "ThreePeople", "address"); Assert.AreEqual("personCount", (nonStructuredResolvedEntity.Attributes[12] as CdmTypeAttributeDefinition).Name); Assert.IsNotNull(nonStructuredResolvedEntity.Attributes[12].AppliedTraits.Item("indicates.expansionInfo.count")); Assert.AreEqual("ThreePeople", (nonStructuredResolvedEntity.Attributes[12].AppliedTraits.Item("indicates.expansionInfo.count") as CdmTraitReference).Arguments[0].Value); // Original set of attributes: ["name", "age", "address"] // in structured form // addAttributeGroup: favorite people // alterTraits = { is.dataFormat.mapValue } // addArtifactAttribute : { "favorite People Key" (with trait "is.dataFormat.mapKey") , "insertAtTop": true } // addAttributeGroup: favorite People Group // alterTraits = { is.dataFormat.map } CdmEntityDefinition structuredResolvedEntity = await ProjectionTestUtils.GetResolvedEntity(corpus, entity, new List <string> { "structured" }); Assert.AreEqual(1, structuredResolvedEntity.Attributes.Count); CdmAttributeGroupDefinition attGroupDefinition = ProjectionTestUtils.ValidateAttributeGroup(structuredResolvedEntity.Attributes, "favorite People Group"); Assert.IsNotNull(attGroupDefinition.ExhibitsTraits.Item("is.dataFormat.map")); Assert.AreEqual("favorite People Key", (attGroupDefinition.Members[0] as CdmTypeAttributeDefinition).Name); Assert.IsNotNull(attGroupDefinition.Members[0].AppliedTraits.Item("is.dataFormat.mapKey")); Assert.AreEqual(CdmObjectType.AttributeGroupRef, attGroupDefinition.Members[1].ObjectType); CdmAttributeGroupReference innerAttGroupRef = attGroupDefinition.Members[1] as CdmAttributeGroupReference; Assert.IsNotNull(innerAttGroupRef.ExplicitReference); CdmAttributeGroupDefinition innerAttGroupDefinition = innerAttGroupRef.ExplicitReference as CdmAttributeGroupDefinition; Assert.AreEqual("favorite people", innerAttGroupDefinition.AttributeGroupName); Assert.IsNotNull(innerAttGroupDefinition.ExhibitsTraits.Item("is.dataFormat.mapValue")); }