Пример #1
0
        public async Task TestAlterTraitsOnAttrGrpProj()
        {
            string testName            = nameof(TestAlterTraitsOnAttrGrpProj);
            string entityName          = "NewPerson";
            CdmCorpusDefinition corpus = TestHelper.GetLocalCorpus(testsSubpath, testName);

            corpus.Storage.Mount("traitGroup", new LocalAdapter(traitGroupFilePath));

            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 resolvedEntity = await ProjectionTestUtils.GetResolvedEntity(corpus, entity, new List <string> {
            });

            CdmAttributeGroupReference  attGroupReference  = resolvedEntity.Attributes[0] as CdmAttributeGroupReference;
            CdmAttributeGroupDefinition attGroupDefinition = attGroupReference.ExplicitReference as CdmAttributeGroupDefinition;

            Assert.AreEqual(5, attGroupDefinition.Members.Count);
            Assert.AreEqual("PersonAttributeGroup", attGroupDefinition.AttributeGroupName);
            Assert.IsNotNull(attGroupDefinition.ExhibitsTraits.Item("means.TraitG100"));
            Assert.IsNotNull(attGroupDefinition.ExhibitsTraits.Item("means.TraitG200"));
            Assert.IsNull(attGroupDefinition.ExhibitsTraits.Item("means.TraitG300"));
            Assert.IsNotNull(attGroupDefinition.ExhibitsTraits.Item("means.TraitG400"));
            CdmTraitReference traitG4 = (CdmTraitReference)attGroupDefinition.ExhibitsTraits.Item("means.TraitG4");

            Assert.IsNotNull(traitG4);
            Assert.AreEqual("5", traitG4.Arguments.FetchValue("precision"));
            Assert.AreEqual("15", traitG4.Arguments.FetchValue("scale"));
        }
        public async Task TestNestedProj()
        {
            string testName            = "TestNestedProj";
            string entityName          = "NewPerson";
            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 resolvedEntity = await ProjectionTestUtils.GetResolvedEntity(corpus, entity, new List <string> {
            });

            // Original set of attributes: ["name", "age", "address", "phoneNumber", "email"]
            CdmAttributeGroupDefinition outerAttGroup = ProjectionTestUtils.ValidateAttributeGroup(resolvedEntity.Attributes, "OuterAttributeGroup");
            CdmAttributeGroupDefinition innerAttGroup = ProjectionTestUtils.ValidateAttributeGroup(outerAttGroup.Members, "InnerAttributeGroup");

            Assert.AreEqual(5, innerAttGroup.Members.Count);
            Assert.AreEqual("name", (innerAttGroup.Members[0] as CdmTypeAttributeDefinition).Name);
            Assert.AreEqual("age", (innerAttGroup.Members[1] as CdmTypeAttributeDefinition).Name);
            Assert.AreEqual("address", (innerAttGroup.Members[2] as CdmTypeAttributeDefinition).Name);
            Assert.AreEqual("phoneNumber", (innerAttGroup.Members[3] as CdmTypeAttributeDefinition).Name);
            Assert.AreEqual("email", (innerAttGroup.Members[4] as CdmTypeAttributeDefinition).Name);
        }
        public async Task TestCombineOpsProj()
        {
            string testName            = "TestCombineOpsProj";
            string entityName          = "NewPerson";
            CdmCorpusDefinition corpus = ProjectionTestUtils.GetCorpus(testName, testsSubpath);

            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 resolvedEntity = await ProjectionTestUtils.GetResolvedEntity(corpus, entity, new List <string> {
            });

            // Original set of attributes: ["name", "age", "address", "phoneNumber", "email"]
            // Included attributes: ["age", "phoneNumber"]
            CdmAttributeGroupDefinition attGroupDefinition = this.ValidateAttributeGroup(resolvedEntity.Attributes, "PersonAttributeGroup", 3);

            Assert.AreEqual(5, attGroupDefinition.Members.Count);
            Assert.AreEqual("name", (attGroupDefinition.Members[0] as CdmTypeAttributeDefinition).Name);
            Assert.AreEqual("age", (attGroupDefinition.Members[1] as CdmTypeAttributeDefinition).Name);
            Assert.AreEqual("address", (attGroupDefinition.Members[2] as CdmTypeAttributeDefinition).Name);
            Assert.AreEqual("phoneNumber", (attGroupDefinition.Members[3] as CdmTypeAttributeDefinition).Name);
            Assert.AreEqual("email", (attGroupDefinition.Members[4] as CdmTypeAttributeDefinition).Name);

            // Check the attributes coming from the IncludeAttribute operation
            Assert.AreEqual("age", (resolvedEntity.Attributes[1] as CdmTypeAttributeDefinition).Name);
            Assert.AreEqual("phoneNumber", (resolvedEntity.Attributes[2] as CdmTypeAttributeDefinition).Name);
        }
        public async Task TestTypeAttributeProj()
        {
            string testName            = "TestTypeAttributeProj";
            string entityName          = "Person";
            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 resolvedEntity = await ProjectionTestUtils.GetResolvedEntity(corpus, entity, new List <string> {
                "referenceOnly"
            });

            // Original set of attributes: ["name", "age", "address", "phoneNumber", "email"]
            // Add attribute group applied to "address"
            Assert.AreEqual(5, resolvedEntity.Attributes.Count);
            Assert.AreEqual("name", (resolvedEntity.Attributes[0] as CdmTypeAttributeDefinition).Name);
            Assert.AreEqual("age", (resolvedEntity.Attributes[1] as CdmTypeAttributeDefinition).Name);
            CdmAttributeGroupDefinition attGroupDefinition = ProjectionTestUtils.ValidateAttributeGroup(resolvedEntity.Attributes, "AddressAttributeGroup", 5, 2);

            Assert.AreEqual("address", (attGroupDefinition.Members[0] as CdmTypeAttributeDefinition).Name);
            Assert.AreEqual("phoneNumber", (resolvedEntity.Attributes[3] as CdmTypeAttributeDefinition).Name);
            Assert.AreEqual("email", (resolvedEntity.Attributes[4] as CdmTypeAttributeDefinition).Name);
        }
Пример #5
0
        public async Task TestEANameProj()
        {
            string testName            = "TestEANameProj";
            string entityName          = "NewPerson";
            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 resolvedEntity = await ProjectionTestUtils.GetResolvedEntity(corpus, entity, new List <string> {
                "structured"
            });

            // Original set of attributes: ["name", "age", "address", "phoneNumber", "email", "title", "company", "tenure"]
            // Excluded attributes: ["OccupationInfo"] (name of entity attribute that contains "title", "company", "tenure")
            Assert.AreEqual(1, resolvedEntity.Attributes.Count); // attribute group created because of structured directive
            CdmAttributeGroupDefinition attGroup = (resolvedEntity.Attributes[0] as CdmAttributeGroupReference).ExplicitReference as CdmAttributeGroupDefinition;

            Assert.AreEqual(5, attGroup.Members.Count);
            Assert.AreEqual("name", (attGroup.Members[0] as CdmTypeAttributeDefinition).Name);
            Assert.AreEqual("age", (attGroup.Members[1] as CdmTypeAttributeDefinition).Name, "age");
            Assert.AreEqual("address", (attGroup.Members[2] as CdmTypeAttributeDefinition).Name, "address");
            Assert.AreEqual("phoneNumber", (attGroup.Members[3] as CdmTypeAttributeDefinition).Name, "phoneNumber");
            Assert.AreEqual("email", (attGroup.Members[4] as CdmTypeAttributeDefinition).Name, "email");
        }
Пример #6
0
        public async Task TestPersistAttributeGroupDefinition()
        {
            var corpus         = new CdmCorpusDefinition();
            var attGroup       = new CdmAttributeGroupDefinition(corpus.Ctx, "attGroup");
            var persistedGroup = AttributeGroupPersistence.ToData(attGroup, new ResolveOptions(attGroup.InDocument), new CopyOptions());

            Assert.IsNotNull(persistedGroup.Members);
        }
Пример #7
0
 public static dynamic ToData(CdmAttributeGroupDefinition instance, ResolveOptions resOpt, CopyOptions options)
 {
     return(new AttributeGroup
     {
         Explanation = instance.Explanation,
         AttributeGroupName = instance.AttributeGroupName,
         ExhibitsTraits = CopyDataUtils.ListCopyData(resOpt, instance.ExhibitsTraits, options),
         AttributeContext = instance.AttributeContext?.CopyData(resOpt, options) as string,
         Members = CopyDataUtils.ListCopyData(resOpt, instance.Members, options)
     });
 }
Пример #8
0
        public async Task TestTypeAttribute()
        {
            string testName            = "TestTypeAttribute";
            string entityName          = "Person";
            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: [ "FavoriteTerms" ]
            // in non-structured form
            // addArtifactAttribute : { "Term key" , "insertAtTop": true }
            // Expand 1...2;
            // renameAttributes = { {m}_{o}_key, apply to "Term key" }
            // renameAttributes = { {m}_{o}_value, apply to "FavoriteTerms" }
            // alterTraits = { indicates.expansionInfo.mapKey(expansionName: "{a}", ordinal: "{o}") , apply to "Term key" , "argumentsContainWildcards" : true }
            // alterTraits = { has.expansionInfo.mapValue(expansionName: "{a}", ordinal: "{o}") , apply to "FavoriteTerms"  , "argumentsContainWildcards" : true }
            // addArtifactAttribute : number of favorite terms"
            // alterTraits = { indicates.expansionInfo.count(expansionName: "{a}") , apply to "number of favorite terms" , "argumentsContainWildcards" : true }
            Assert.AreEqual(5, nonStructuredResolvedEntity.Attributes.Count);
            ValidateAttributeTrait(nonStructuredResolvedEntity.Attributes[0] as CdmTypeAttributeDefinition, "Term key_1_key", 1, "FavoriteTerms", isKey: true);
            ValidateAttributeTrait(nonStructuredResolvedEntity.Attributes[1] as CdmTypeAttributeDefinition, "FavoriteTerms_1_value", 1, "FavoriteTerms");
            ValidateAttributeTrait(nonStructuredResolvedEntity.Attributes[2] as CdmTypeAttributeDefinition, "Term key_2_key", 2, "FavoriteTerms", isKey: true);
            ValidateAttributeTrait(nonStructuredResolvedEntity.Attributes[3] as CdmTypeAttributeDefinition, "FavoriteTerms_2_value", 2, "FavoriteTerms");
            Assert.AreEqual("number of favorite terms", (nonStructuredResolvedEntity.Attributes[4] as CdmTypeAttributeDefinition).Name);
            Assert.IsNotNull(nonStructuredResolvedEntity.Attributes[4].AppliedTraits.Item("indicates.expansionInfo.count"));
            Assert.AreEqual("FavoriteTerms", (nonStructuredResolvedEntity.Attributes[4].AppliedTraits.Item("indicates.expansionInfo.count") as CdmTraitReference).Arguments[0].Value);

            // Original set of attributes: [ "FavoriteTerms" ]
            // in structured form
            // alterTraits = { is.dataFormat.mapValue }
            // addArtifactAttribute : { "Favorite Terms Key" (with trait "is.dataFormat.mapKey")  , "insertAtTop": true }
            // addAttributeGroup: favorite Term 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 Term Group");

            Assert.IsNotNull(attGroupDefinition.ExhibitsTraits.Item("is.dataFormat.map"));
            Assert.AreEqual("Favorite Terms Key", (attGroupDefinition.Members[0] as CdmTypeAttributeDefinition).Name);
            Assert.IsNotNull(attGroupDefinition.Members[0].AppliedTraits.Item("is.dataFormat.mapKey"));
            Assert.AreEqual("FavoriteTerms", (attGroupDefinition.Members[1] as CdmTypeAttributeDefinition).Name);
            Assert.IsNotNull(attGroupDefinition.Members[1].AppliedTraits.Item("is.dataFormat.mapValue"));
        }
Пример #9
0
        public async Task TestNonMaxDepthCached()
        {
            CdmCorpusDefinition cdmCorpus = TestHelper.GetLocalCorpus(testsSubpath, "TestMaxDepth");
            CdmEntityDefinition aEnt      = await cdmCorpus.FetchObjectAsync <CdmEntityDefinition>("A.cdm.json/A");

            CdmEntityDefinition bEnt = await cdmCorpus.FetchObjectAsync <CdmEntityDefinition>("B.cdm.json/B");

            CdmEntityDefinition cEnt = await cdmCorpus.FetchObjectAsync <CdmEntityDefinition>("C.cdm.json/C");

            CdmEntityDefinition dEnt = await cdmCorpus.FetchObjectAsync <CdmEntityDefinition>("D.cdm.json/D");

            // when resolving A, B should be cached and it should exclude any attributes from D because
            // it is outside of the maxDepth
            CdmEntityDefinition resA = await aEnt.CreateResolvedEntityAsync("resA", new ResolveOptions(
                                                                                aEnt.InDocument,
                                                                                new AttributeResolutionDirectiveSet(new HashSet <string> {
                "normalized", "structured"
            })
                                                                                ));

            // ensure that when resolving B on its own, attributes from D are included
            CdmEntityDefinition resB = await bEnt.CreateResolvedEntityAsync("resB", new ResolveOptions(
                                                                                bEnt.InDocument,
                                                                                new AttributeResolutionDirectiveSet(new HashSet <string> {
                "normalized", "structured"
            })
                                                                                ));

            // check the attributes found in D from resolving A
            CdmAttributeGroupDefinition bAttInA = ((CdmAttributeGroupDefinition)((CdmAttributeGroupReference)resA.Attributes[1]).ExplicitReference);
            CdmAttributeGroupDefinition cAttInA = ((CdmAttributeGroupDefinition)((CdmAttributeGroupReference)(bAttInA.Members[1])).ExplicitReference);
            CdmAttributeGroupDefinition dAttInA = ((CdmAttributeGroupDefinition)((CdmAttributeGroupReference)(cAttInA.Members[1])).ExplicitReference);

            Assert.AreEqual(dAttInA.Members.Count, 1);
            // check that the attribute in D is a foreign key attribute
            CdmTypeAttributeDefinition dIdAttFromA = (CdmTypeAttributeDefinition)(dAttInA.Members[0]);

            Assert.AreEqual(dIdAttFromA.Name, "dId");
            Assert.IsNotNull(dIdAttFromA.AppliedTraits.Item("is.linkedEntity.identifier"));

            // check the attributes found in D from resolving B
            CdmAttributeGroupDefinition cAttInB = ((CdmAttributeGroupDefinition)((CdmAttributeGroupReference)resB.Attributes[1]).ExplicitReference);
            CdmAttributeGroupDefinition dAttInB = ((CdmAttributeGroupDefinition)((CdmAttributeGroupReference)(cAttInB.Members[1])).ExplicitReference);

            Assert.AreEqual(dAttInB.Members.Count, 2);
            // check that the attribute in D is not a foreign key attribute
            CdmTypeAttributeDefinition dIdAttFromB = (CdmTypeAttributeDefinition)(dAttInB.Members[0]);

            Assert.AreEqual(dIdAttFromB.Name, "dId");
            Assert.IsNull(dIdAttFromB.AppliedTraits.Item("is.linkedEntity.identifier"));
        }
        /// <summary>
        /// Validates the creation of an attribute group and return its definition
        /// </summary>
        /// <param name="attributes">The collection of attributes.</param>
        /// <param name="attributeGroupName">The attribute group name.</param>
        /// <param name="attributesSize">The expected size of the attributes collection.</param>
        /// <returns></returns>
        private CdmAttributeGroupDefinition ValidateAttributeGroup(CdmCollection <CdmAttributeItem> attributes, string attributeGroupName, int attributesSize = 1, int index = 0)
        {
            Assert.AreEqual(attributesSize, attributes.Count);
            Assert.AreEqual(CdmObjectType.AttributeGroupRef, attributes[index].ObjectType);
            CdmAttributeGroupReference attGroupReference = attributes[index] as CdmAttributeGroupReference;

            Assert.IsNotNull(attGroupReference.ExplicitReference);

            CdmAttributeGroupDefinition attGroupDefinition = attGroupReference.ExplicitReference as CdmAttributeGroupDefinition;

            Assert.AreEqual(attributeGroupName, attGroupDefinition.AttributeGroupName);

            return(attGroupDefinition);
        }
Пример #11
0
        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
            // Expand 1...3;
            // renameFormat = {m}{o};
            // alterTraits = { has.expansionInfo.list(expansionName: "{a}", ordinal: "{o}", memberAttribute: "{mo}") , "argumentsContainWildcards" : true }
            // addArtifactAttribute : "personCount"
            // alterTraits = { indicates.expansionInfo.count(expansionName: "{a}") , apply to "personCount" , "argumentsContainWildcards" : true }
            Assert.AreEqual(10, nonStructuredResolvedEntity.Attributes.Count);
            ProjectionTestUtils.ValidateExpansionInfoTrait(nonStructuredResolvedEntity.Attributes[0] as CdmTypeAttributeDefinition, "name1", 1, "ThreePeople", "name");
            ProjectionTestUtils.ValidateExpansionInfoTrait(nonStructuredResolvedEntity.Attributes[1] as CdmTypeAttributeDefinition, "age1", 1, "ThreePeople", "age");
            ProjectionTestUtils.ValidateExpansionInfoTrait(nonStructuredResolvedEntity.Attributes[2] as CdmTypeAttributeDefinition, "address1", 1, "ThreePeople", "address");
            ProjectionTestUtils.ValidateExpansionInfoTrait(nonStructuredResolvedEntity.Attributes[3] as CdmTypeAttributeDefinition, "name2", 2, "ThreePeople", "name");
            ProjectionTestUtils.ValidateExpansionInfoTrait(nonStructuredResolvedEntity.Attributes[4] as CdmTypeAttributeDefinition, "age2", 2, "ThreePeople", "age");
            ProjectionTestUtils.ValidateExpansionInfoTrait(nonStructuredResolvedEntity.Attributes[5] as CdmTypeAttributeDefinition, "address2", 2, "ThreePeople", "address");
            ProjectionTestUtils.ValidateExpansionInfoTrait(nonStructuredResolvedEntity.Attributes[6] as CdmTypeAttributeDefinition, "name3", 3, "ThreePeople", "name");
            ProjectionTestUtils.ValidateExpansionInfoTrait(nonStructuredResolvedEntity.Attributes[7] as CdmTypeAttributeDefinition, "age3", 3, "ThreePeople", "age");
            ProjectionTestUtils.ValidateExpansionInfoTrait(nonStructuredResolvedEntity.Attributes[8] as CdmTypeAttributeDefinition, "address3", 3, "ThreePeople", "address");
            Assert.AreEqual("personCount", (nonStructuredResolvedEntity.Attributes[9] as CdmTypeAttributeDefinition).Name);
            Assert.AreEqual("indicates.expansionInfo.count", nonStructuredResolvedEntity.Attributes[9].AppliedTraits[1].NamedReference);
            Assert.AreEqual("ThreePeople", (nonStructuredResolvedEntity.Attributes[9].AppliedTraits[1] as CdmTraitReference).Arguments[0].Value);

            // Original set of attributes: ["name", "age", "address"]
            // in structured form
            // alterTraits = { is.dataFormat.list }
            // addAttributeGroup: favoriteMusketeers
            CdmEntityDefinition structuredResolvedEntity = await ProjectionTestUtils.GetResolvedEntity(corpus, entity, new List <string> {
                "structured"
            });

            Assert.AreEqual(1, structuredResolvedEntity.Attributes.Count);
            CdmAttributeGroupDefinition attGroupDefinition = ProjectionTestUtils.ValidateAttributeGroup(structuredResolvedEntity.Attributes, "favoriteMusketeers");

            Assert.IsNotNull(attGroupDefinition.ExhibitsTraits.Item("is.dataFormat.list"));
        }
Пример #12
0
        public async Task TestReadingIsPrimaryKey()
        {
            var testInputPath          = TestHelper.GetInputFolderPath(testsSubpath, "TestReadingIsPrimaryKey");
            CdmCorpusDefinition corpus = new CdmCorpusDefinition();

            corpus.SetEventCallback(new EventCallback {
                Invoke = CommonDataModelLoader.ConsoleStatusReport
            }, CdmStatusLevel.Warning);
            corpus.Storage.Mount("local", new LocalAdapter(testInputPath));
            corpus.Storage.DefaultNamespace = "local";

            // Read from an unresolved entity schema.
            CdmEntityDefinition entity = await corpus.FetchObjectAsync <CdmEntityDefinition>("local:/TeamMembership.cdm.json/TeamMembership");

            CdmAttributeGroupReference  attributeGroupRef = (CdmAttributeGroupReference)entity.Attributes[0];
            CdmAttributeGroupDefinition attributeGroup    = (CdmAttributeGroupDefinition)attributeGroupRef.ExplicitReference;
            CdmTypeAttributeDefinition  typeAttribute     = (CdmTypeAttributeDefinition)attributeGroup.Members[0];

            Assert.IsTrue((bool)typeAttribute.IsPrimaryKey);

            // Check that the trait "is.identifiedBy" is created with the correct argument.
            CdmTraitReference isIdentifiedBy1 = typeAttribute.AppliedTraits[1];

            Assert.AreEqual("is.identifiedBy", isIdentifiedBy1.NamedReference);
            Assert.AreEqual("TeamMembership/(resolvedAttributes)/teamMembershipId", isIdentifiedBy1.Arguments[0].Value);

            // Read from a resolved entity schema.
            CdmEntityDefinition resolvedEntity = await corpus.FetchObjectAsync <CdmEntityDefinition>("local:/TeamMembership_Resolved.cdm.json/TeamMembership");

            CdmTypeAttributeDefinition resolvedTypeAttribute = (CdmTypeAttributeDefinition)resolvedEntity.Attributes[0];

            Assert.IsTrue((bool)resolvedTypeAttribute.IsPrimaryKey);

            // Check that the trait "is.identifiedBy" is created with the correct argument.
            CdmTraitReference isIdentifiedBy2 = resolvedTypeAttribute.AppliedTraits[6];

            Assert.AreEqual("is.identifiedBy", isIdentifiedBy2.NamedReference);

            CdmAttributeReference argumentValue = isIdentifiedBy2.Arguments[0].Value;

            Assert.AreEqual("TeamMembership/(resolvedAttributes)/teamMembershipId", argumentValue.NamedReference);
        }
        public async Task TestEntityAttributeProjUsingObjectModel()
        {
            string testName               = "TestEntityAttributeProjUsingObjectModel";
            CdmCorpusDefinition corpus    = ProjectionTestUtils.GetCorpus(testName, testsSubpath);
            CdmFolderDefinition localRoot = corpus.Storage.FetchRootFolder("local");

            // Create an entity
            CdmEntityDefinition entity = ProjectionTestUtils.CreateEntity(corpus, localRoot);

            // Create a projection
            CdmProjection projection = ProjectionTestUtils.CreateProjection(corpus, localRoot);

            // Create an AddAttributeGroup operation
            CdmOperationAddAttributeGroup addAttGroupOp = corpus.MakeObject <CdmOperationAddAttributeGroup>(CdmObjectType.OperationAddAttributeGroupDef);

            addAttGroupOp.AttributeGroupName = "PersonAttributeGroup";
            projection.Operations.Add(addAttGroupOp);

            // Create an entity reference to hold this projection
            CdmEntityReference projectionEntityRef = corpus.MakeObject <CdmEntityReference>(CdmObjectType.EntityRef, null);

            projectionEntityRef.ExplicitReference = projection;

            // Create an entity attribute that contains this projection and add this to the entity
            CdmEntityAttributeDefinition entityAttribute = corpus.MakeObject <CdmEntityAttributeDefinition>(CdmObjectType.EntityAttributeDef, "TestEntityAttribute");

            entityAttribute.Entity = projectionEntityRef;
            entity.Attributes.Add(entityAttribute);

            // Resolve the entity.
            CdmEntityDefinition resolvedEntity = await entity.CreateResolvedEntityAsync($"Resolved_{entity.EntityName}.cdm.json", null, localRoot);

            // Verify correctness of the resolved attributes after running the AddAttributeGroup operation
            // Original set of attributes: ["id", "name", "value", "date"]
            CdmAttributeGroupDefinition attGroupDefinition = this.ValidateAttributeGroup(resolvedEntity.Attributes, "PersonAttributeGroup");

            Assert.AreEqual(4, attGroupDefinition.Members.Count);
            Assert.AreEqual("id", (attGroupDefinition.Members[0] as CdmTypeAttributeDefinition).Name);
            Assert.AreEqual("name", (attGroupDefinition.Members[1] as CdmTypeAttributeDefinition).Name);
            Assert.AreEqual("value", (attGroupDefinition.Members[2] as CdmTypeAttributeDefinition).Name);
            Assert.AreEqual("date", (attGroupDefinition.Members[3] as CdmTypeAttributeDefinition).Name);
        }
Пример #14
0
        public static void ValidateAttributeGroupRef(AttributeExpectedValue expected, CdmAttributeGroupReference actual)
        {
            if (expected.AttributeGroupName != null || expected.Members != null)
            {
                if (actual.ExplicitReference != null)
                {
                    CdmAttributeGroupDefinition actualObj = ((CdmAttributeGroupDefinition)actual.ExplicitReference);

                    if (expected.AttributeGroupName != null)
                    {
                        Assert.AreEqual(expected.AttributeGroupName, actualObj.AttributeGroupName);
                    }
                    if (expected.AttributeContext != null)
                    {
                        Assert.AreEqual(expected.AttributeContext, actualObj.AttributeContext.NamedReference);
                    }
                    if (expected.Members != null)
                    {
                        Assert.AreEqual(expected.Members.Count, actualObj.Members.Count);
                        for (int i = 0; i < actualObj.Members.Count; i++)
                        {
                            if (actualObj.Members[i].GetType() == typeof(CdmTypeAttributeDefinition))
                            {
                                AttributeExpectedValue     exp = (AttributeExpectedValue)expected.Members[i];
                                CdmTypeAttributeDefinition act = (CdmTypeAttributeDefinition)actualObj.Members[i];
                                ValidateTypeAttributeDefinition(exp, act);
                            }
                            else if (actualObj.Members[i].GetType() == typeof(CdmAttributeGroupReference))
                            {
                                AttributeExpectedValue     exp = (AttributeExpectedValue)expected.Members[i];
                                CdmAttributeGroupReference act = (CdmAttributeGroupReference)actualObj.Members[i];
                                ValidateAttributeGroupRef(exp, act);
                            }
                            else
                            {
                                throw new NotImplementedException("Unknown type!");
                            }
                        }
                    }
                }
            }
        }
Пример #15
0
        public async Task TestReadingIsPrimaryKeyConstructedFromPurpose()
        {
            var testInputPath          = TestHelper.GetInputFolderPath(testsSubpath, "TestReadingIsPrimaryKeyConstructedFromPurpose");
            CdmCorpusDefinition corpus = new CdmCorpusDefinition();

            corpus.SetEventCallback(new EventCallback {
                Invoke = CommonDataModelLoader.ConsoleStatusReport
            }, CdmStatusLevel.Warning);
            corpus.Storage.Mount("local", new LocalAdapter(testInputPath));
            corpus.Storage.DefaultNamespace = "local";

            CdmEntityDefinition entity = await corpus.FetchObjectAsync <CdmEntityDefinition>("local:/TeamMembership.cdm.json/TeamMembership");

            CdmAttributeGroupReference  attributeGroupRef = (CdmAttributeGroupReference)entity.Attributes[0];
            CdmAttributeGroupDefinition attributeGroup    = (CdmAttributeGroupDefinition)attributeGroupRef.ExplicitReference;
            CdmTypeAttributeDefinition  typeAttribute     = (CdmTypeAttributeDefinition)attributeGroup.Members[0];

            Assert.AreEqual("identifiedBy", typeAttribute.Purpose.NamedReference);
            Assert.IsTrue((bool)typeAttribute.IsPrimaryKey);
        }
Пример #16
0
        /// <summary>
        /// Get the traits for all the attributes of a resolved entity
        /// </summary>
        /// <param name="resolvedEntity"></param>
        private void GetTraits(CdmCollection <CdmAttributeItem> attributes)
        {
            foreach (CdmAttributeItem attrib in attributes)
            {
                string attribCorpusPath = attrib.AtCorpusPath;
                bldr.AppendLine(attribCorpusPath);

                if (attrib is CdmAttributeGroupReference)
                {
                    CdmAttributeGroupDefinition attGroupDef = (CdmAttributeGroupDefinition)(attrib as CdmAttributeGroupReference).ExplicitReference;
                    bldr.AppendLine(attGroupDef.AtCorpusPath);
                    GetTraitCollection(attGroupDef.ExhibitsTraits);
                    GetTraits(attGroupDef.Members);
                }
                else
                {
                    GetTraitCollection(attrib.AppliedTraits);
                }
            }
        }
        public async Task TestConditionalProj()
        {
            string testName            = "TestConditionalProj";
            string entityName          = "NewPerson";
            CdmCorpusDefinition corpus = ProjectionTestUtils.GetCorpus(testName, testsSubpath);

            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 resolvedEntity = await ProjectionTestUtils.GetResolvedEntity(corpus, entity, new List <string> {
                "referenceOnly"
            });

            // Original set of attributes: ["name", "age", "address", "phoneNumber", "email"]
            // Condition not met, keep attributes in flat list
            Assert.AreEqual(5, resolvedEntity.Attributes.Count);
            Assert.AreEqual("name", (resolvedEntity.Attributes[0] as CdmTypeAttributeDefinition).Name);
            Assert.AreEqual("age", (resolvedEntity.Attributes[1] as CdmTypeAttributeDefinition).Name);
            Assert.AreEqual("address", (resolvedEntity.Attributes[2] as CdmTypeAttributeDefinition).Name);
            Assert.AreEqual("phoneNumber", (resolvedEntity.Attributes[3] as CdmTypeAttributeDefinition).Name);
            Assert.AreEqual("email", (resolvedEntity.Attributes[4] as CdmTypeAttributeDefinition).Name);

            CdmEntityDefinition resolvedEntity2 = await ProjectionTestUtils.GetResolvedEntity(corpus, entity, new List <string> {
                "structured"
            });

            // Original set of attributes: ["name", "age", "address", "phoneNumber", "email"]
            // Condition met, put all attributes in an attribute group
            CdmAttributeGroupDefinition attGroupDefinition = this.ValidateAttributeGroup(resolvedEntity2.Attributes, "PersonAttributeGroup");

            Assert.AreEqual(5, attGroupDefinition.Members.Count);
            Assert.AreEqual("name", (attGroupDefinition.Members[0] as CdmTypeAttributeDefinition).Name);
            Assert.AreEqual("age", (attGroupDefinition.Members[1] as CdmTypeAttributeDefinition).Name);
            Assert.AreEqual("address", (attGroupDefinition.Members[2] as CdmTypeAttributeDefinition).Name);
            Assert.AreEqual("phoneNumber", (attGroupDefinition.Members[3] as CdmTypeAttributeDefinition).Name);
            Assert.AreEqual("email", (attGroupDefinition.Members[4] as CdmTypeAttributeDefinition).Name);
        }
Пример #18
0
        public async Task TestCircularReference()
        {
            CdmCorpusDefinition cdmCorpus = TestHelper.GetLocalCorpus(testsSubpath, "TestCircularReference");
            CdmEntityDefinition customer  = await cdmCorpus.FetchObjectAsync <CdmEntityDefinition>("local:/Customer.cdm.json/Customer");

            CdmEntityDefinition resCustomerStructured = await customer.CreateResolvedEntityAsync("resCustomer", new ResolveOptions(
                                                                                                     customer.InDocument,
                                                                                                     new AttributeResolutionDirectiveSet(new HashSet <string> {
                "normalized", "structured", "noMaxDepth"
            })
                                                                                                     ));

            // check that the circular reference attribute has a single id attribute
            CdmAttributeGroupDefinition storeGroupAtt =
                ((CdmAttributeGroupReference)resCustomerStructured.Attributes[1]).ExplicitReference as CdmAttributeGroupDefinition;
            CdmAttributeGroupDefinition customerGroupAtt =
                ((CdmAttributeGroupReference)storeGroupAtt.Members[1]).ExplicitReference as CdmAttributeGroupDefinition;

            Assert.AreEqual(1, customerGroupAtt.Members.Count);
            Assert.AreEqual("customerId", ((CdmTypeAttributeDefinition)customerGroupAtt.Members[0]).Name);
        }
Пример #19
0
        public async Task TestReadingIsPrimaryKey()
        {
            CdmCorpusDefinition corpus = TestHelper.GetLocalCorpus(testsSubpath, "TestReadingIsPrimaryKey");

            var resOpt = new ResolveOptions()
            {
                StrictValidation = true
            };
            // Read from an unresolved entity schema.
            CdmEntityDefinition entity = await corpus.FetchObjectAsync <CdmEntityDefinition>("local:/TeamMembership.cdm.json/TeamMembership", null, resOpt);

            CdmAttributeGroupReference  attributeGroupRef = (CdmAttributeGroupReference)entity.Attributes[0];
            CdmAttributeGroupDefinition attributeGroup    = (CdmAttributeGroupDefinition)attributeGroupRef.ExplicitReference;
            CdmTypeAttributeDefinition  typeAttribute     = (CdmTypeAttributeDefinition)attributeGroup.Members[0];

            Assert.IsTrue((bool)typeAttribute.IsPrimaryKey);

            // Check that the trait "is.identifiedBy" is created with the correct argument.
            CdmTraitReference isIdentifiedBy1 = typeAttribute.AppliedTraits[1];

            Assert.AreEqual("is.identifiedBy", isIdentifiedBy1.NamedReference);
            Assert.AreEqual("TeamMembership/(resolvedAttributes)/teamMembershipId", isIdentifiedBy1.Arguments[0].Value);

            // Read from a resolved entity schema.
            CdmEntityDefinition resolvedEntity = await corpus.FetchObjectAsync <CdmEntityDefinition>("local:/TeamMembership_Resolved.cdm.json/TeamMembership", null, resOpt);

            CdmTypeAttributeDefinition resolvedTypeAttribute = (CdmTypeAttributeDefinition)resolvedEntity.Attributes[0];

            Assert.IsTrue((bool)resolvedTypeAttribute.IsPrimaryKey);

            // Check that the trait "is.identifiedBy" is created with the correct argument.
            CdmTraitReference isIdentifiedBy2 = resolvedTypeAttribute.AppliedTraits[6];

            Assert.AreEqual("is.identifiedBy", isIdentifiedBy2.NamedReference);

            CdmAttributeReference argumentValue = isIdentifiedBy2.Arguments[0].Value;

            Assert.AreEqual("TeamMembership/(resolvedAttributes)/teamMembershipId", argumentValue.NamedReference);
        }
        public async Task TestMultipleOpProj()
        {
            string testName            = "TestMultipleOpProj";
            string entityName          = "NewPerson";
            CdmCorpusDefinition corpus = ProjectionTestUtils.GetCorpus(testName, testsSubpath);

            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 resolvedEntity = await ProjectionTestUtils.GetResolvedEntity(corpus, entity, new List <string> {
            });

            // Original set of attributes: ["name", "age", "address", "phoneNumber", "email"]
            // This will result in two attribute groups with the same set of attributes being generated
            CdmAttributeGroupDefinition attGroup1 = this.ValidateAttributeGroup(resolvedEntity.Attributes, "PersonAttributeGroup", 2);

            Assert.AreEqual(5, attGroup1.Members.Count);
            Assert.AreEqual("name", (attGroup1.Members[0] as CdmTypeAttributeDefinition).Name);
            Assert.AreEqual("age", (attGroup1.Members[1] as CdmTypeAttributeDefinition).Name);
            Assert.AreEqual("address", (attGroup1.Members[2] as CdmTypeAttributeDefinition).Name);
            Assert.AreEqual("phoneNumber", (attGroup1.Members[3] as CdmTypeAttributeDefinition).Name);
            Assert.AreEqual("email", (attGroup1.Members[4] as CdmTypeAttributeDefinition).Name);

            CdmAttributeGroupDefinition attGroup2 = this.ValidateAttributeGroup(resolvedEntity.Attributes, "SecondAttributeGroup", 2, 1);

            Assert.AreEqual(5, attGroup2.Members.Count);
            Assert.AreEqual("name", (attGroup2.Members[0] as CdmTypeAttributeDefinition).Name);
            Assert.AreEqual("age", (attGroup2.Members[1] as CdmTypeAttributeDefinition).Name);
            Assert.AreEqual("address", (attGroup2.Members[2] as CdmTypeAttributeDefinition).Name);
            Assert.AreEqual("phoneNumber", (attGroup2.Members[3] as CdmTypeAttributeDefinition).Name);
            Assert.AreEqual("email", (attGroup2.Members[4] as CdmTypeAttributeDefinition).Name);
        }
Пример #21
0
        public async Task TestSymbolResolution()
        {
            CdmCorpusDefinition corpus = TestHelper.GetLocalCorpus(TestsSubpath, "TestSymbolResolution");

            // load the file
            CdmEntityDefinition ent = await corpus.FetchObjectAsync <CdmEntityDefinition>("local:/symbolEntity.cdm.json/symbolEnt");

            ResolveOptions resOpt = new ResolveOptions(ent.InDocument);

            // resolve a reference to the trait object
            CdmObjectBase traitDef = corpus.ResolveSymbolReference(
                resOpt,
                ent.InDocument,
                "symbolEnt/exhibitsTraits/someTraitOnEnt",
                CdmObjectType.TraitDef,
                false
                );

            Assert.IsTrue(traitDef is CdmTraitDefinition);

            // resolve a path to the reference object that contains the trait
            CdmObjectBase traitRef = corpus.ResolveSymbolReference(
                resOpt,
                ent.InDocument,
                "symbolEnt/exhibitsTraits/someTraitOnEnt/(ref)",
                CdmObjectType.TraitDef,
                false
                );

            Assert.IsTrue(traitRef is CdmTraitReference);

            // FetchObjectDefinition on a path to a reference should fetch the actual object
            CdmTraitDefinition traitRefDefinition = traitRef.FetchObjectDefinition <CdmTraitDefinition>(resOpt);
            CdmTraitDefinition traitDefDefinition = traitDef.FetchObjectDefinition <CdmTraitDefinition>(resOpt);

            Assert.AreEqual(traitRefDefinition, traitDef);
            Assert.AreEqual(traitDefDefinition, traitDef);

            CdmObjectBase groupRef = corpus.ResolveSymbolReference(
                resOpt,
                ent.InDocument,
                "symbolEnt/hasAttributes/someGroupRef/(ref)",
                CdmObjectType.AttributeGroupDef,
                false
                );

            Assert.IsTrue(groupRef is CdmAttributeGroupReference);

            CdmObjectBase groupDef = corpus.ResolveSymbolReference(
                resOpt,
                ent.InDocument,
                "symbolEnt/hasAttributes/someGroupRef",
                CdmObjectType.AttributeGroupDef,
                false
                );

            Assert.IsTrue(groupDef is CdmAttributeGroupDefinition);

            // calling FetchObjectDefinition on a symbol to a ref or def should both give the definition
            CdmAttributeGroupDefinition groupRefDefinition = groupRef.FetchObjectDefinition <CdmAttributeGroupDefinition>(resOpt);
            CdmAttributeGroupDefinition groupDefDefinition = groupDef.FetchObjectDefinition <CdmAttributeGroupDefinition>(resOpt);

            Assert.AreEqual(groupRefDefinition, groupDef);
            Assert.AreEqual(groupDefDefinition, groupDef);

            CdmObjectBase typeAtt = corpus.ResolveSymbolReference(
                resOpt,
                ent.InDocument,
                "symbolEnt/hasAttributes/someGroupRef/members/someAttribute",
                CdmObjectType.AttributeGroupDef,
                false
                );

            Assert.IsTrue(typeAtt is CdmTypeAttributeDefinition);
        }
Пример #22
0
        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"));
        }
        public async Task TestConditionalProjUsingObjectModel()
        {
            string testName               = "TestConditionalProjUsingObjectModel";
            CdmCorpusDefinition corpus    = ProjectionTestUtils.GetCorpus(testName, testsSubpath);
            CdmFolderDefinition localRoot = corpus.Storage.FetchRootFolder("local");

            // Create an entity.
            CdmEntityDefinition entity = ProjectionTestUtils.CreateEntity(corpus, localRoot);

            // Create a projection with a condition that states the operation should only execute when the resolution directive is 'structured'.
            CdmProjection projection = ProjectionTestUtils.CreateProjection(corpus, localRoot);

            projection.Condition = "structured==true";

            // Create an AddAttributeGroup operation
            CdmOperationAddAttributeGroup addAttGroupOp = corpus.MakeObject <CdmOperationAddAttributeGroup>(CdmObjectType.OperationAddAttributeGroupDef);

            addAttGroupOp.AttributeGroupName = "PersonAttributeGroup";
            projection.Operations.Add(addAttGroupOp);

            // Create an entity reference to hold this projection.
            CdmEntityReference projectionEntityRef = corpus.MakeObject <CdmEntityReference>(CdmObjectType.EntityRef, null);

            projectionEntityRef.ExplicitReference = projection;

            // Create an entity attribute that contains this projection and add this to the entity.
            CdmEntityAttributeDefinition entityAttribute = corpus.MakeObject <CdmEntityAttributeDefinition>(CdmObjectType.EntityAttributeDef, "TestEntityAttribute");

            entityAttribute.Entity = projectionEntityRef;
            entity.Attributes.Add(entityAttribute);

            // Create resolution options with the 'referenceOnly' directive.
            ResolveOptions resOpt = new ResolveOptions(entity.InDocument)
            {
                Directives = new AttributeResolutionDirectiveSet(new HashSet <string> {
                    "referenceOnly"
                })
            };

            // Resolve the entity with 'referenceOnly'
            CdmEntityDefinition resolvedEntityWithReferenceOnly = await entity.CreateResolvedEntityAsync($"Resolved_{entity.EntityName}.cdm.json", resOpt, localRoot);

            // Verify correctness of the resolved attributes after running the AddAttributeGroup operation
            // Original set of attributes: ["id", "name", "value", "date"]
            // Condition not met, keep attributes in flat list
            Assert.AreEqual(4, resolvedEntityWithReferenceOnly.Attributes.Count);
            Assert.AreEqual("id", (resolvedEntityWithReferenceOnly.Attributes[0] as CdmTypeAttributeDefinition).Name);
            Assert.AreEqual("name", (resolvedEntityWithReferenceOnly.Attributes[1] as CdmTypeAttributeDefinition).Name);
            Assert.AreEqual("value", (resolvedEntityWithReferenceOnly.Attributes[2] as CdmTypeAttributeDefinition).Name);
            Assert.AreEqual("date", (resolvedEntityWithReferenceOnly.Attributes[3] as CdmTypeAttributeDefinition).Name);

            // Now resolve the entity with the 'structured' directive
            resOpt.Directives = new AttributeResolutionDirectiveSet(new HashSet <string> {
                "structured"
            });
            CdmEntityDefinition resolvedEntityWithStructured = await entity.CreateResolvedEntityAsync($"Resolved_{entity.EntityName}.cdm.json", resOpt, localRoot);

            // Verify correctness of the resolved attributes after running the AddAttributeGroup operation
            // Original set of attributes: ["id", "name", "value", "date"]
            // Condition met, put all attributes in an attribute group
            CdmAttributeGroupDefinition attGroupDefinition = this.ValidateAttributeGroup(resolvedEntityWithStructured.Attributes, "PersonAttributeGroup");

            Assert.AreEqual(4, attGroupDefinition.Members.Count);
            Assert.AreEqual("id", (attGroupDefinition.Members[0] as CdmTypeAttributeDefinition).Name);
            Assert.AreEqual("name", (attGroupDefinition.Members[1] as CdmTypeAttributeDefinition).Name);
            Assert.AreEqual("value", (attGroupDefinition.Members[2] as CdmTypeAttributeDefinition).Name);
            Assert.AreEqual("date", (attGroupDefinition.Members[3] as CdmTypeAttributeDefinition).Name);
        }