Exemple #1
0
        public async Task TestProjectionTrait()
        {
            string testName   = "TestProjectionTrait";
            string entityName = testName;

            CdmCorpusDefinition   corpus   = TestHelper.GetLocalCorpus(testsSubpath, testName);
            CdmManifestDefinition manifest = await corpus.FetchObjectAsync <CdmManifestDefinition>($"local:/default.manifest.cdm.json");

            string expectedOutputPath = TestHelper.GetExpectedOutputFolderPath(testsSubpath, testName);

            CdmEntityDefinition entTestProjectionTrait = await corpus.FetchObjectAsync <CdmEntityDefinition>($"local:/{entityName}.cdm.json/{entityName}", manifest);

            Assert.IsNotNull(entTestProjectionTrait);
            CdmEntityDefinition resolvedTestProjectionTrait = await TestUtils.GetResolvedEntity(corpus, entTestProjectionTrait, new List <string> {
            });

            Assert.IsNotNull(resolvedTestProjectionTrait);
            AttributeContextUtil.ValidateAttributeContext(corpus, expectedOutputPath, entityName, resolvedTestProjectionTrait);
            {
                // Attribute Name
                Assert.AreEqual("TestProjectionAttribute", ((CdmTypeAttributeDefinition)resolvedTestProjectionTrait.Attributes[0]).Name);
                // Trait Name
                Assert.AreEqual("does.haveDefault", ((CdmTypeAttributeDefinition)resolvedTestProjectionTrait.Attributes[0]).AppliedTraits[3].NamedReference);

                // Trait Name
                Assert.AreEqual("testTrait", ((CdmTypeAttributeDefinition)resolvedTestProjectionTrait.Attributes[0]).AppliedTraits[4].NamedReference);
                // Trait Param Name
                Assert.AreEqual("testTraitParam1", ((CdmArgumentDefinition)((CdmTypeAttributeDefinition)resolvedTestProjectionTrait.Attributes[0]).AppliedTraits[4].Arguments[0]).ResolvedParameter.Name);
                // Trait Param Default Value
                Assert.AreEqual("TestTrait Param 1 DefaultValue", ((CdmArgumentDefinition)((CdmTypeAttributeDefinition)resolvedTestProjectionTrait.Attributes[0]).AppliedTraits[4].Arguments[0]).Value);
            }
        }
        /// <summary>
        /// Common test code for these test cases
        /// </summary>
        /// <param name="testName"></param>
        /// <param name="entityName"></param>
        private void TestRun(string testName, string entityName)
        {
            CdmCorpusDefinition corpus  = TestHelper.GetLocalCorpus(testsSubpath, testName);
            string inputFolder          = TestHelper.GetInputFolderPath(testsSubpath, testName);
            string expectedOutputFolder = TestHelper.GetExpectedOutputFolderPath(testsSubpath, testName);
            string actualOutputFolder   = TestHelper.GetActualOutputFolderPath(testsSubpath, testName);

            if (!Directory.Exists(actualOutputFolder))
            {
                Directory.CreateDirectory(actualOutputFolder);
            }

            CdmManifestDefinition manifest = corpus.FetchObjectAsync <CdmManifestDefinition>($"local:/default.manifest.cdm.json").GetAwaiter().GetResult();

            Assert.IsNotNull(manifest);
            CdmEntityDefinition entity = corpus.FetchObjectAsync <CdmEntityDefinition>($"local:/{entityName}.cdm.json/{entityName}", manifest).GetAwaiter().GetResult();

            Assert.IsNotNull(entity);
            CdmEntityDefinition resolvedEntity = TestUtils.GetResolvedEntity(corpus, entity, new List <string> {
                "referenceOnly"
            }).GetAwaiter().GetResult();

            AttributeContextUtil.ValidateAttributeContext(corpus, expectedOutputFolder, entityName, resolvedEntity);

            corpus.CalculateEntityGraphAsync(manifest).GetAwaiter().GetResult();
            manifest.PopulateManifestRelationshipsAsync().GetAwaiter().GetResult();
            string actualRelationshipsString = ListRelationships(corpus, entity, actualOutputFolder, entityName);

            string expectedRelationshipsStringFilePath = Path.GetFullPath(Path.Combine(expectedOutputFolder, $"REL_{entityName}.txt"));
            string expectedRelationshipsString         = File.ReadAllText(expectedRelationshipsStringFilePath);

            Assert.AreEqual(expectedRelationshipsString, actualRelationshipsString);

            CdmFolderDefinition outputFolder = corpus.Storage.FetchRootFolder("output");

            outputFolder.Documents.Add(manifest);

            string manifestFileName = $"saved.manifest.cdm.json";

            manifest.SaveAsAsync(manifestFileName, saveReferenced: true).GetAwaiter().GetResult();
            string actualManifestPath = Path.Combine(actualOutputFolder, manifestFileName);

            if (!File.Exists(actualManifestPath))
            {
                Assert.Fail("Unable to save manifest with relationship");
            }
            else
            {
                CdmManifestDefinition savedManifest = corpus.FetchObjectAsync <CdmManifestDefinition>($"output:/{manifestFileName}").GetAwaiter().GetResult();
                string actualSavedManifestRel       = GetRelationshipStrings(savedManifest.Relationships);
                string expectedSavedManifestRel     = File.ReadAllText(Path.Combine(expectedOutputFolder, $"MANIFEST_REL_{entityName}.txt"));
                Assert.AreEqual(expectedSavedManifestRel, actualSavedManifestRel);
            }
        }
        /// <summary>
        /// Loads an entity, resolves it, and then validates the generated attribute contexts
        /// </summary>
        private async Task LoadEntityForResolutionOptionAndSave(CdmCorpusDefinition corpus, string testName, string entityName, List <string> resOpts)
        {
            string expectedOutputPath = TestHelper.GetExpectedOutputFolderPath(testsSubpath, testName);
            string fileNameSuffix     = TestUtils.GetResolutionOptionNameSuffix(resOpts);

            CdmEntityDefinition entity = await corpus.FetchObjectAsync <CdmEntityDefinition>($"local:/{entityName}.cdm.json/{entityName}");

            CdmEntityDefinition resolvedEntity = await TestUtils.GetResolvedEntity(corpus, entity, resOpts, true);

            AttributeContextUtil.ValidateAttributeContext(corpus, expectedOutputPath, $"{entityName}{fileNameSuffix}", resolvedEntity);
        }
Exemple #4
0
        public async Task TestAppliedTraitsInAttributes()
        {
            CdmCorpusDefinition corpus  = TestHelper.GetLocalCorpus(testsSubpath, "TestAppliedTraitsInAttributes");
            string expectedOutputFolder = TestHelper.GetExpectedOutputFolderPath(testsSubpath, "TestAppliedTraitsInAttributes");
            CdmEntityDefinition entity  = await corpus.FetchObjectAsync <CdmEntityDefinition>("local:/Sales.cdm.json/Sales");

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

            await AttributeContextUtil.ValidateAttributeContext(expectedOutputFolder, "Sales", resolvedEntity);
        }
Exemple #5
0
        private async Task LoadEntityForResolutionOptionAndSave(string testName, string entityName, List <string> resOpts)
        {
            CdmCorpusDefinition   corpus   = TestHelper.GetLocalCorpus(testsSubpath, testName);
            CdmManifestDefinition manifest = await corpus.FetchObjectAsync <CdmManifestDefinition>($"local:/default.manifest.cdm.json");

            string expectedOutputPath = TestHelper.GetExpectedOutputFolderPath(testsSubpath, testName);
            string fileNameSuffix     = GetResolutionOptionNameSuffix(resOpts);

            CdmEntityDefinition entSalesForeignKeyProjection = await corpus.FetchObjectAsync <CdmEntityDefinition>($"local:/{entityName}.cdm.json/{entityName}", manifest);

            Assert.IsNotNull(entSalesForeignKeyProjection);
            CdmEntityDefinition resolvedSalesForeignKeyProjection = await SaveResolved(corpus, manifest, testName, entSalesForeignKeyProjection, resOpts);

            Assert.IsNotNull(resolvedSalesForeignKeyProjection);
            AttributeContextUtil.ValidateAttributeContext(corpus, expectedOutputPath, $"{entityName}{fileNameSuffix}", resolvedSalesForeignKeyProjection);
        }
Exemple #6
0
        public async Task TestEntityProjection()
        {
            string testName   = "TestEntityProjection";
            string entityName = testName;

            CdmCorpusDefinition   corpus   = TestHelper.GetLocalCorpus(testsSubpath, testName);
            CdmManifestDefinition manifest = await corpus.FetchObjectAsync <CdmManifestDefinition>($"local:/default.manifest.cdm.json");

            string expectedOutputPath = TestHelper.GetExpectedOutputFolderPath(testsSubpath, testName);

            CdmEntityDefinition entTestEntityProjection = await corpus.FetchObjectAsync <CdmEntityDefinition>($"local:/{entityName}.cdm.json/{entityName}", manifest);

            Assert.IsNotNull(entTestEntityProjection);
            CdmEntityDefinition resolvedTestEntityProjection = await TestUtils.GetResolvedEntity(corpus, entTestEntityProjection, new List <string> {
            });

            Assert.IsNotNull(resolvedTestEntityProjection);
            AttributeContextUtil.ValidateAttributeContext(corpus, expectedOutputPath, entityName, resolvedTestEntityProjection);
        }
        /// <summary>
        /// Loads an entity, resolves it, and then validates the generated attribute contexts
        /// </summary>
        private async Task LoadEntityForResolutionOptionAndSave(string testName, string entityName, List <string> resOpts)
        {
            string expectedOutputPath = TestHelper.GetExpectedOutputFolderPath(testsSubpath, testName);
            string fileNameSuffix     = ProjectionTestUtils.GetResolutionOptionNameSuffix(resOpts);

            CdmCorpusDefinition corpus = TestHelper.GetLocalCorpus(testsSubpath, testName);

            corpus.Storage.Mount("expected", new LocalAdapter(expectedOutputPath));
            CdmManifestDefinition manifest = await corpus.FetchObjectAsync <CdmManifestDefinition>($"local:/default.manifest.cdm.json");

            CdmEntityDefinition entity = await corpus.FetchObjectAsync <CdmEntityDefinition>($"local:/{entityName}.cdm.json/{entityName}");

            Assert.IsNotNull(entity);
            CdmEntityDefinition resolvedEntity = await ProjectionTestUtils.GetResolvedEntity(corpus, entity, resOpts, true);

            Assert.IsNotNull(resolvedEntity);

            await ValidateResolvedAttributes(corpus, resolvedEntity, entityName, fileNameSuffix);

            AttributeContextUtil.ValidateAttributeContext(corpus, expectedOutputPath, $"{entityName}{fileNameSuffix}", resolvedEntity);
        }