Beispiel #1
0
        public async Task TestDeeperCircularImportWithMoniker()
        {
            var corpus = TestHelper.GetLocalCorpus("", "");
            var folder = corpus.Storage.FetchRootFolder("local");

            var docA = new CdmDocumentDefinition(corpus.Ctx, "A.cdm.json");

            folder.Documents.Add(docA);
            docA.Imports.Add("B.cdm.json");

            var docB = new CdmDocumentDefinition(corpus.Ctx, "B.cdm.json");

            folder.Documents.Add(docB);
            docB.Imports.Add("C.cdm.json", "moniker");

            var docC = new CdmDocumentDefinition(corpus.Ctx, "C.cdm.json");

            folder.Documents.Add(docC);
            docC.Imports.Add("D.cdm.json");

            var docD = new CdmDocumentDefinition(corpus.Ctx, "D.cdm.json");

            folder.Documents.Add(docD);
            docD.Imports.Add("C.cdm.json");

            // indexIfNeeded will internally call prioritizeImports on every document.
            await docA.IndexIfNeeded(new ResolveOptions(), true);

            Assert.AreEqual(4, docA.ImportPriorities.ImportPriority.Count);
            AssertImportInfo(docA.ImportPriorities.ImportPriority[docA], 0, false);
            AssertImportInfo(docA.ImportPriorities.ImportPriority[docB], 1, false);
            AssertImportInfo(docA.ImportPriorities.ImportPriority[docD], 2, false);
            AssertImportInfo(docA.ImportPriorities.ImportPriority[docC], 3, false);

            // reset the importsPriorities.
            MarkDocumentsToIndex(folder.Documents);

            // force docC to be indexed first, so the priorityList will be read from the cache this time.
            await docC.IndexIfNeeded(new ResolveOptions(), true);

            await docA.IndexIfNeeded(new ResolveOptions(), true);

            Assert.AreEqual(4, docA.ImportPriorities.ImportPriority.Count);

            // indexes the rest of the documents.
            await docB.IndexIfNeeded(new ResolveOptions(), true);

            await docD.IndexIfNeeded(new ResolveOptions(), true);

            Assert.IsFalse(docA.ImportPriorities.hasCircularImport);
            Assert.IsFalse(docB.ImportPriorities.hasCircularImport);
            Assert.IsTrue(docC.ImportPriorities.hasCircularImport);
            Assert.IsTrue(docD.ImportPriorities.hasCircularImport);
        }
Beispiel #2
0
        public async Task TestCircularImportWithMoniker()
        {
            var corpus = TestHelper.GetLocalCorpus("", "");
            var folder = corpus.Storage.FetchRootFolder("local");

            var docA = new CdmDocumentDefinition(corpus.Ctx, "A.cdm.json");

            folder.Documents.Add(docA);
            docA.Imports.Add("B.cdm.json", "moniker");

            var docB = new CdmDocumentDefinition(corpus.Ctx, "B.cdm.json");

            folder.Documents.Add(docB);
            docB.Imports.Add("C.cdm.json");

            var docC = new CdmDocumentDefinition(corpus.Ctx, "C.cdm.json");

            folder.Documents.Add(docC);
            docC.Imports.Add("B.cdm.json");

            // forces docB to be indexed first.
            await docB.IndexIfNeeded(new ResolveOptions(), true);

            await docA.IndexIfNeeded(new ResolveOptions(), true);

            // should contain A, B and C.
            Assert.AreEqual(3, docA.ImportPriorities.ImportPriority.Count);

            Assert.IsFalse(docA.ImportPriorities.hasCircularImport);

            // docB and docC should have the hasCircularImport set to true.
            Assert.IsTrue(docB.ImportPriorities.hasCircularImport);
            Assert.IsTrue(docC.ImportPriorities.hasCircularImport);
        }
Beispiel #3
0
        public async Task TestMonikeredImportIsNotAdded()
        {
            var corpus = TestHelper.GetLocalCorpus("", "");
            var folder = corpus.Storage.FetchRootFolder("local");

            var docA = new CdmDocumentDefinition(corpus.Ctx, "A.cdm.json");

            folder.Documents.Add(docA);
            docA.Imports.Add("B.cdm.json", "moniker");

            var docB = new CdmDocumentDefinition(corpus.Ctx, "B.cdm.json");

            folder.Documents.Add(docB);
            docB.Imports.Add("C.cdm.json");

            var docC = new CdmDocumentDefinition(corpus.Ctx, "C.cdm.json");

            folder.Documents.Add(docC);

            // forces docB to be indexed first, so the priorityList will be read from the cache this time.
            await docB.IndexIfNeeded(new ResolveOptions(docB), true);

            await docA.IndexIfNeeded(new ResolveOptions(docA), true);

            // should only contain docA and docC, docB should be excluded.
            Assert.AreEqual(2, docA.ImportPriorities.ImportPriority.Count);

            Assert.IsFalse(docA.ImportPriorities.hasCircularImport);
            Assert.IsFalse(docB.ImportPriorities.hasCircularImport);
            Assert.IsFalse(docC.ImportPriorities.hasCircularImport);
        }
Beispiel #4
0
        public async Task TestReadingCachedImportPriority()
        {
            var corpus = TestHelper.GetLocalCorpus("", "");
            var folder = corpus.Storage.FetchRootFolder("local");

            var docA = new CdmDocumentDefinition(corpus.Ctx, "A.cdm.json");

            folder.Documents.Add(docA);
            docA.Imports.Add("B.cdm.json");

            var docB = new CdmDocumentDefinition(corpus.Ctx, "B.cdm.json");

            folder.Documents.Add(docB);
            docB.Imports.Add("C.cdm.json", "moniker");

            var docC = new CdmDocumentDefinition(corpus.Ctx, "C.cdm.json");

            folder.Documents.Add(docC);
            docC.Imports.Add("D.cdm.json");

            var docD = new CdmDocumentDefinition(corpus.Ctx, "D.cdm.json");

            folder.Documents.Add(docD);

            // index docB first and check its import priorities.
            await docB.IndexIfNeeded(new ResolveOptions(), true);

            Assert.AreEqual(3, docB.ImportPriorities.ImportPriority.Count);
            AssertImportInfo(docB.ImportPriorities.ImportPriority[docB], 0, false);
            AssertImportInfo(docB.ImportPriorities.ImportPriority[docD], 1, false);
            AssertImportInfo(docB.ImportPriorities.ImportPriority[docC], 2, true);

            // now index docA, which should read docB's priority list from the cache.
            await docA.IndexIfNeeded(new ResolveOptions(), true);

            Assert.AreEqual(3, docA.ImportPriorities.ImportPriority.Count);
            AssertImportInfo(docA.ImportPriorities.ImportPriority[docA], 0, false);
            AssertImportInfo(docA.ImportPriorities.ImportPriority[docB], 1, false);
            AssertImportInfo(docA.ImportPriorities.ImportPriority[docD], 2, false);
        }
Beispiel #5
0
        public async Task TestMonikeredImportIsAddedToEnd()
        {
            var corpus = TestHelper.GetLocalCorpus("", "");
            var folder = corpus.Storage.FetchRootFolder("local");

            var docA = new CdmDocumentDefinition(corpus.Ctx, "A.cdm.json");

            folder.Documents.Add(docA);
            docA.Imports.Add("B.cdm.json", "moniker");

            var docB = new CdmDocumentDefinition(corpus.Ctx, "B.cdm.json");

            folder.Documents.Add(docB);
            docB.Imports.Add("C.cdm.json");

            var docC = new CdmDocumentDefinition(corpus.Ctx, "C.cdm.json");

            folder.Documents.Add(docC);

            // forces docB to be indexed first, so the priorityList will be read from the cache this time.
            await docB.IndexIfNeeded(new ResolveOptions(docB), true);

            await docA.IndexIfNeeded(new ResolveOptions(docA), true);

            // should contain all three documents.
            Assert.AreEqual(3, docA.ImportPriorities.ImportPriority.Count);
            AssertImportInfo(docA.ImportPriorities.ImportPriority[docA], 0, false);
            AssertImportInfo(docA.ImportPriorities.ImportPriority[docC], 1, false);
            // docB is monikered so it should appear at the end of the list.
            AssertImportInfo(docA.ImportPriorities.ImportPriority[docB], 2, true);

            // make sure that the has circular import is set to false.
            Assert.IsFalse(docA.ImportPriorities.hasCircularImport);
            Assert.IsFalse(docB.ImportPriorities.hasCircularImport);
            Assert.IsFalse(docC.ImportPriorities.hasCircularImport);
        }