Exemplo n.º 1
0
        /// <summary>
        /// List the incoming and outgoing relationships
        /// </summary>
        /// <param name="corpus"></param>
        /// <param name="entity"></param>
        /// <param name="actualOutputFolder"></param>
        /// <param name="entityName"></param>
        /// <returns></returns>
        private static string ListRelationships(CdmCorpusDefinition corpus, CdmEntityDefinition entity, string actualOutputFolder, string entityName)
        {
            StringBuilder    bldr     = new StringBuilder();
            HashSet <string> relCache = new HashSet <string>();

            bldr.AppendLine($"Incoming Relationships For: {entity.EntityName}:");
            // Loop through all the relationships where other entities point to this entity.
            foreach (CdmE2ERelationship relationship in corpus.FetchIncomingRelationships(entity))
            {
                string cacheKey = GetRelationshipString(relationship);
                if (!relCache.Contains(cacheKey))
                {
                    bldr.AppendLine(PrintRelationship(relationship));
                    relCache.Add(cacheKey);
                }
            }

            Console.WriteLine($"Outgoing Relationships For: {entity.EntityName}:");
            // Now loop through all the relationships where this entity points to other entities.
            foreach (CdmE2ERelationship relationship in corpus.FetchOutgoingRelationships(entity))
            {
                string cacheKey = GetRelationshipString(relationship);
                if (!relCache.Contains(cacheKey))
                {
                    bldr.AppendLine(PrintRelationship(relationship));
                    relCache.Add(cacheKey);
                }
            }

            return(bldr.ToString());
        }
Exemplo n.º 2
0
 static void ListRelationships(CdmCorpusDefinition cdmCorpus, CdmEntityDefinition entity)
 {
     Console.WriteLine($"\nList of all relationships for the entity {entity.EntityName}:");
     // Loop through all the relationships where other entities point to this entity.
     foreach (CdmE2ERelationship relationship in cdmCorpus.FetchIncomingRelationships(entity))
     {
         PrintRelationship(relationship);
     }
     // Now loop through all the relationships where this entity points to other entities.
     foreach (CdmE2ERelationship relationship in cdmCorpus.FetchOutgoingRelationships(entity))
     {
         PrintRelationship(relationship);
     }
 }
Exemplo n.º 3
0
        public async Task TestCalculateRelationshipsOnResolvedEntities()
        {
            var expectedResolvedManifestRels    = JToken.Parse(TestHelper.GetExpectedOutputFileContent(testsSubpath, "TestCalculateRelationshipsOnResolvedEntities", "expectedResolvedManifestRels.json")).ToObject <List <E2ERelationship> >();
            var expectedResolvedSubManifestRels = JToken.Parse(TestHelper.GetExpectedOutputFileContent(testsSubpath, "TestCalculateRelationshipsOnResolvedEntities", "expectedResolvedSubManifestRels.json")).ToObject <List <E2ERelationship> >();

            CdmCorpusDefinition corpus = TestHelper.GetLocalCorpus(testsSubpath, "TestCalculateRelationshipsOnResolvedEntities");

            var rootManifest = await corpus.FetchObjectAsync <CdmManifestDefinition>("local:/default.manifest.cdm.json");

            var resolvedManifest = await LoadAndResolveManifest(corpus, rootManifest, "-resolved");

            string subManifestPath            = corpus.Storage.CreateAbsoluteCorpusPath(resolvedManifest.SubManifests[0].Definition);
            CdmManifestDefinition subManifest = await corpus.FetchObjectAsync <CdmManifestDefinition>(subManifestPath) as CdmManifestDefinition;

            // using createResolvedManifest will only populate exclusive relationships
            Assert.AreEqual(expectedResolvedManifestRels.Count, resolvedManifest.Relationships.Count);
            Assert.AreEqual(expectedResolvedSubManifestRels.Count, subManifest.Relationships.Count);

            // check that each relationship has been created correctly
            foreach (E2ERelationship expectedRel in expectedResolvedManifestRels)
            {
                List <CdmE2ERelationship> found = resolvedManifest.Relationships.Where(x =>
                                                                                       x.FromEntity == expectedRel.FromEntity &&
                                                                                       x.FromEntityAttribute == expectedRel.FromEntityAttribute &&
                                                                                       x.ToEntity == expectedRel.ToEntity &&
                                                                                       x.ToEntityAttribute == expectedRel.ToEntityAttribute
                                                                                       ).ToList();
                Assert.AreEqual(1, found.Count);
            }

            foreach (E2ERelationship expectedSubRel in expectedResolvedSubManifestRels)
            {
                List <CdmE2ERelationship> found = subManifest.Relationships.Where(x =>
                                                                                  x.FromEntity == expectedSubRel.FromEntity &&
                                                                                  x.FromEntityAttribute == expectedSubRel.FromEntityAttribute &&
                                                                                  x.ToEntity == expectedSubRel.ToEntity &&
                                                                                  x.ToEntityAttribute == expectedSubRel.ToEntityAttribute
                                                                                  ).ToList();
                Assert.AreEqual(1, found.Count);
            }

            // it is not enough to check if the relationships are correct.
            // We need to check if the incoming and outgoing relationships are
            // correct as well. One being correct can cover up the other being wrong

            // A
            var aEnt = await corpus.FetchObjectAsync <CdmEntityDefinition>(resolvedManifest.Entities[0].EntityPath, resolvedManifest);

            var aInRels  = corpus.FetchIncomingRelationships(aEnt);
            var aOutRels = corpus.FetchOutgoingRelationships(aEnt);

            Assert.AreEqual(0, aInRels.Count);
            Assert.AreEqual(1, aOutRels.Count);
            Assert.AreEqual("local:/A-resolved.cdm.json/A", aOutRels[0].FromEntity);
            Assert.AreEqual("local:/B-resolved.cdm.json/B", aOutRels[0].ToEntity);

            // B
            var bEnt = await corpus.FetchObjectAsync <CdmEntityDefinition>(resolvedManifest.Entities[1].EntityPath, resolvedManifest);

            var bInRels  = corpus.FetchIncomingRelationships(bEnt);
            var bOutRels = corpus.FetchOutgoingRelationships(bEnt);

            Assert.AreEqual(1, bInRels.Count);
            Assert.AreEqual("local:/A-resolved.cdm.json/A", bInRels[0].FromEntity);
            Assert.AreEqual("local:/B-resolved.cdm.json/B", bInRels[0].ToEntity);
            Assert.AreEqual(0, bOutRels.Count);

            // C
            var cEnt = await corpus.FetchObjectAsync <CdmEntityDefinition>(subManifest.Entities[0].EntityPath, subManifest);

            var cInRels  = corpus.FetchIncomingRelationships(cEnt);
            var cOutRels = corpus.FetchOutgoingRelationships(cEnt);

            Assert.AreEqual(0, cInRels.Count);
            Assert.AreEqual(2, cOutRels.Count);
            Assert.AreEqual("local:/sub/C-resolved.cdm.json/C", cOutRels[0].FromEntity);
            // TODO: this should point to the resolved entity, currently an open bug
            Assert.AreEqual("local:/B.cdm.json/B", cOutRels[0].ToEntity);
            Assert.AreEqual("local:/sub/C-resolved.cdm.json/C", cOutRels[1].FromEntity);
            Assert.AreEqual("local:/sub/D-resolved.cdm.json/D", cOutRels[1].ToEntity);

            // D
            var dEnt = await corpus.FetchObjectAsync <CdmEntityDefinition>(subManifest.Entities[1].EntityPath, subManifest);

            var dInRels  = corpus.FetchIncomingRelationships(dEnt);
            var dOutRels = corpus.FetchOutgoingRelationships(dEnt);

            Assert.AreEqual(1, dInRels.Count);
            Assert.AreEqual("local:/sub/C-resolved.cdm.json/C", dInRels[0].FromEntity);
            Assert.AreEqual("local:/sub/D-resolved.cdm.json/D", dInRels[0].ToEntity);
            Assert.AreEqual(0, dOutRels.Count);
        }
Exemplo n.º 4
0
        public async Task TestCalculateRelationshipsOnResolvedEntities()
        {
            var expectedResolvedManifestRels       = JToken.Parse(TestHelper.GetExpectedOutputFileContent(testsSubpath, "TestCalculateRelationshipsOnResolvedEntities", "expectedResolvedManifestRels.json")).ToObject <List <E2ERelationship> >();
            var expectedResolvedSubManifestRels    = JToken.Parse(TestHelper.GetExpectedOutputFileContent(testsSubpath, "TestCalculateRelationshipsOnResolvedEntities", "expectedResolvedSubManifestRels.json")).ToObject <List <E2ERelationship> >();
            var expectedResolvedExcManifestRels    = JToken.Parse(TestHelper.GetExpectedOutputFileContent(testsSubpath, "TestCalculateRelationshipsOnResolvedEntities", "expectedResolvedExcManifestRels.json")).ToObject <List <E2ERelationship> >();
            var expectedResolvedExcSubManifestRels = JToken.Parse(TestHelper.GetExpectedOutputFileContent(testsSubpath, "TestCalculateRelationshipsOnResolvedEntities", "expectedResolvedExcSubManifestRels.json")).ToObject <List <E2ERelationship> >();

            CdmCorpusDefinition corpus = TestHelper.GetLocalCorpus(testsSubpath, "TestCalculateRelationshipsOnResolvedEntities");

            var rootManifest = await corpus.FetchObjectAsync <CdmManifestDefinition>("local:/default.manifest.cdm.json");

            var resolvedManifest = await LoadAndResolveManifest(corpus, rootManifest, "-resolved");

            string subManifestPath            = corpus.Storage.CreateAbsoluteCorpusPath(resolvedManifest.SubManifests[0].Definition);
            CdmManifestDefinition subManifest = await corpus.FetchObjectAsync <CdmManifestDefinition>(subManifestPath) as CdmManifestDefinition;

            // using createResolvedManifest will only populate exclusive relationships
            VerifyRelationships(resolvedManifest, expectedResolvedExcManifestRels);
            VerifyRelationships(subManifest, expectedResolvedExcSubManifestRels);

            // check that each relationship has been created correctly with the all flag
            await resolvedManifest.PopulateManifestRelationshipsAsync();

            await subManifest.PopulateManifestRelationshipsAsync();

            VerifyRelationships(resolvedManifest, expectedResolvedManifestRels);
            VerifyRelationships(subManifest, expectedResolvedSubManifestRels);

            // it is not enough to check if the relationships are correct.
            // We need to check if the incoming and outgoing relationships are
            // correct as well. One being correct can cover up the other being wrong

            // A
            var aEnt = await corpus.FetchObjectAsync <CdmEntityDefinition>(resolvedManifest.Entities[0].EntityPath, resolvedManifest);

            var aInRels  = corpus.FetchIncomingRelationships(aEnt);
            var aOutRels = corpus.FetchOutgoingRelationships(aEnt);

            Assert.AreEqual(0, aInRels.Count);
            Assert.AreEqual(1, aOutRels.Count);
            Assert.AreEqual("local:/A-resolved.cdm.json/A", aOutRels[0].FromEntity);
            Assert.AreEqual("local:/B-resolved.cdm.json/B", aOutRels[0].ToEntity);

            // B
            var bEnt = await corpus.FetchObjectAsync <CdmEntityDefinition>(resolvedManifest.Entities[1].EntityPath, resolvedManifest);

            var bInRels  = corpus.FetchIncomingRelationships(bEnt);
            var bOutRels = corpus.FetchOutgoingRelationships(bEnt);

            Assert.AreEqual(2, bInRels.Count);
            Assert.AreEqual("local:/A-resolved.cdm.json/A", bInRels[0].FromEntity);
            Assert.AreEqual("local:/B-resolved.cdm.json/B", bInRels[0].ToEntity);
            Assert.AreEqual("local:/sub/C-resolved.cdm.json/C", bInRels[1].FromEntity);
            Assert.AreEqual("local:/B-resolved.cdm.json/B", bInRels[1].ToEntity);
            Assert.AreEqual(0, bOutRels.Count);

            // C
            var cEnt = await corpus.FetchObjectAsync <CdmEntityDefinition>(subManifest.Entities[0].EntityPath, subManifest);

            var cInRels  = corpus.FetchIncomingRelationships(cEnt);
            var cOutRels = corpus.FetchOutgoingRelationships(cEnt);

            Assert.AreEqual(0, cInRels.Count);
            Assert.AreEqual(2, cOutRels.Count);
            Assert.AreEqual("local:/sub/C-resolved.cdm.json/C", cOutRels[0].FromEntity);
            Assert.AreEqual("local:/B-resolved.cdm.json/B", cOutRels[0].ToEntity);
            Assert.AreEqual("local:/sub/C-resolved.cdm.json/C", cOutRels[1].FromEntity);
            Assert.AreEqual("local:/sub/D-resolved.cdm.json/D", cOutRels[1].ToEntity);

            // D
            var dEnt = await corpus.FetchObjectAsync <CdmEntityDefinition>(subManifest.Entities[1].EntityPath, subManifest);

            var dInRels  = corpus.FetchIncomingRelationships(dEnt);
            var dOutRels = corpus.FetchOutgoingRelationships(dEnt);

            Assert.AreEqual(1, dInRels.Count);
            Assert.AreEqual("local:/sub/C-resolved.cdm.json/C", dInRels[0].FromEntity);
            Assert.AreEqual("local:/sub/D-resolved.cdm.json/D", dInRels[0].ToEntity);
            Assert.AreEqual(0, dOutRels.Count);

            // E
            var eEnt = await corpus.FetchObjectAsync <CdmEntityDefinition>(resolvedManifest.Entities[2].EntityPath, resolvedManifest);

            var eInRels  = corpus.FetchIncomingRelationships(eEnt);
            var eOutRels = corpus.FetchOutgoingRelationships(eEnt);

            Assert.AreEqual(1, eInRels.Count);
            Assert.AreEqual(0, eOutRels.Count);
            Assert.AreEqual("local:/sub/F-resolved.cdm.json/F", eInRels[0].FromEntity);
            Assert.AreEqual("local:/E-resolved.cdm.json/E", eInRels[0].ToEntity);

            // F
            var fEnt = await corpus.FetchObjectAsync <CdmEntityDefinition>(subManifest.Entities[2].EntityPath, subManifest);

            var fInRels  = corpus.FetchIncomingRelationships(fEnt);
            var fOutRels = corpus.FetchOutgoingRelationships(fEnt);

            Assert.AreEqual(0, fInRels.Count);
            Assert.AreEqual(1, fOutRels.Count);
            Assert.AreEqual("local:/sub/F-resolved.cdm.json/F", fOutRels[0].FromEntity);
            Assert.AreEqual("local:/E-resolved.cdm.json/E", fOutRels[0].ToEntity);
        }
Exemplo n.º 5
0
        public async Task TestCalculateRelationshipsOnResolvedEntities()
        {
            var expectedResolvedManifestRels    = JToken.Parse(TestHelper.GetExpectedOutputFileContent(testsSubpath, "TestCalculateRelationshipsOnResolvedEntities", "expectedResolvedManifestRels.json")).ToObject <List <E2ERelationship> >();
            var expectedResolvedSubManifestRels = JToken.Parse(TestHelper.GetExpectedOutputFileContent(testsSubpath, "TestCalculateRelationshipsOnResolvedEntities", "expectedResolvedSubManifestRels.json")).ToObject <List <E2ERelationship> >();

            var testInputPath          = TestHelper.GetInputFolderPath(testsSubpath, "TestCalculateRelationshipsOnResolvedEntities");
            CdmCorpusDefinition corpus = new CdmCorpusDefinition();

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

            var rootManifest = await corpus.FetchObjectAsync <CdmManifestDefinition>("local:/default.manifest.cdm.json");

            var resolvedManifest = await LoadAndResolveManifest(corpus, rootManifest, "-resolved");

            string subManifestPath            = corpus.Storage.CreateAbsoluteCorpusPath(resolvedManifest.SubManifests[0].Definition);
            CdmManifestDefinition subManifest = await corpus.FetchObjectAsync <CdmManifestDefinition>(subManifestPath) as CdmManifestDefinition;

            // using createResolvedManifest will only populate exclusive relationships
            Assert.AreEqual(resolvedManifest.Relationships.Count, expectedResolvedManifestRels.Count);
            Assert.AreEqual(subManifest.Relationships.Count, expectedResolvedSubManifestRels.Count);

            // check that each relationship has been created correctly
            foreach (E2ERelationship expectedRel in expectedResolvedManifestRels)
            {
                List <CdmE2ERelationship> found = resolvedManifest.Relationships.Where(x =>
                                                                                       x.FromEntity == expectedRel.FromEntity &&
                                                                                       x.FromEntityAttribute == expectedRel.FromEntityAttribute &&
                                                                                       x.ToEntity == expectedRel.ToEntity &&
                                                                                       x.ToEntityAttribute == expectedRel.ToEntityAttribute
                                                                                       ).ToList();
                Assert.AreEqual(found.Count, 1);
            }

            foreach (E2ERelationship expectedSubRel in expectedResolvedSubManifestRels)
            {
                List <CdmE2ERelationship> found = subManifest.Relationships.Where(x =>
                                                                                  x.FromEntity == expectedSubRel.FromEntity &&
                                                                                  x.FromEntityAttribute == expectedSubRel.FromEntityAttribute &&
                                                                                  x.ToEntity == expectedSubRel.ToEntity &&
                                                                                  x.ToEntityAttribute == expectedSubRel.ToEntityAttribute
                                                                                  ).ToList();
                Assert.AreEqual(found.Count, 1);
            }

            // it is not enough to check if the relationships are correct.
            // We need to check if the incoming and outgoing relationships are
            // correct as well. One being correct can cover up the other being wrong

            // A
            var aEnt = await corpus.FetchObjectAsync <CdmEntityDefinition>(resolvedManifest.Entities[0].EntityPath, resolvedManifest);

            var aInRels  = corpus.FetchIncomingRelationships(aEnt);
            var aOutRels = corpus.FetchOutgoingRelationships(aEnt);

            Assert.AreEqual(aInRels.Count, 0);
            Assert.AreEqual(aOutRels.Count, 1);
            Assert.AreEqual(aOutRels[0].FromEntity, "local:/A-resolved.cdm.json/A");
            Assert.AreEqual(aOutRels[0].ToEntity, "local:/B-resolved.cdm.json/B");

            // B
            var bEnt = await corpus.FetchObjectAsync <CdmEntityDefinition>(resolvedManifest.Entities[1].EntityPath, resolvedManifest);

            var bInRels  = corpus.FetchIncomingRelationships(bEnt);
            var bOutRels = corpus.FetchOutgoingRelationships(bEnt);

            Assert.AreEqual(bInRels.Count, 1);
            Assert.AreEqual(bInRels[0].FromEntity, "local:/A-resolved.cdm.json/A");
            Assert.AreEqual(bInRels[0].ToEntity, "local:/B-resolved.cdm.json/B");
            Assert.AreEqual(bOutRels.Count, 0);

            // C
            var cEnt = await corpus.FetchObjectAsync <CdmEntityDefinition>(subManifest.Entities[0].EntityPath, subManifest);

            var cInRels  = corpus.FetchIncomingRelationships(cEnt);
            var cOutRels = corpus.FetchOutgoingRelationships(cEnt);

            Assert.AreEqual(cInRels.Count, 0);
            Assert.AreEqual(cOutRels.Count, 2);
            Assert.AreEqual(cOutRels[0].FromEntity, "local:/sub/C-resolved.cdm.json/C");
            // TODO: this should point to the resolved entity, currently an open bug
            Assert.AreEqual(cOutRels[0].ToEntity, "local:/B.cdm.json/B");
            Assert.AreEqual(cOutRels[1].FromEntity, "local:/sub/C-resolved.cdm.json/C");
            Assert.AreEqual(cOutRels[1].ToEntity, "local:/sub/D-resolved.cdm.json/D");

            // D
            var dEnt = await corpus.FetchObjectAsync <CdmEntityDefinition>(subManifest.Entities[1].EntityPath, subManifest);

            var dInRels  = corpus.FetchIncomingRelationships(dEnt);
            var dOutRels = corpus.FetchOutgoingRelationships(dEnt);

            Assert.AreEqual(dInRels.Count, 1);
            Assert.AreEqual(dInRels[0].FromEntity, "local:/sub/C-resolved.cdm.json/C");
            Assert.AreEqual(dInRels[0].ToEntity, "local:/sub/D-resolved.cdm.json/D");
            Assert.AreEqual(dOutRels.Count, 0);
        }