Esempio n. 1
0
        public async Task TestAllOperations()
        {
            string testName            = "TestAllOperations";
            string entityName          = testName;
            CdmCorpusDefinition corpus = TestHelper.GetLocalCorpus(testsSubpath, testName);

            corpus.SetEventCallback(new EventCallback
            {
                Invoke = (CdmStatusLevel statusLevel, string message) =>
                {
                    if (!message.Contains("Projection operation not implemented yet."))
                    {
                        Assert.Fail($"'Some unexpected failure - {message}!");
                    }
                }
            }, CdmStatusLevel.Error);
            string expectedOutputPath = TestHelper.GetExpectedOutputFolderPath(testsSubpath, testName);

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

            Assert.IsNotNull(entTestEntityStringReference);
            CdmEntityDefinition resolvedTestEntityStringReference = await ProjectionTestUtils.GetResolvedEntity(corpus, entTestEntityStringReference, new List <string> {
                "referenceOnly"
            });

            Assert.IsNotNull(resolvedTestEntityStringReference);
            await AttributeContextUtil.ValidateAttributeContext(corpus, expectedOutputPath, entityName, resolvedTestEntityStringReference);
        }
Esempio n. 2
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 ProjectionTestUtils.GetResolvedEntity(corpus, entTestProjectionTrait, new List <string> {
            });

            Assert.IsNotNull(resolvedTestProjectionTrait);
            await 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);
            }
        }
Esempio n. 3
0
        /// <summary>
        /// A function to validate if the attribute context tree & traits generated for a resolved entity is the same as the expected and saved attribute context tree & traits for a test case
        /// </summary>
        /// <param name="expectedOutputPath"></param>
        /// <param name="entityName"></param>
        /// <param name="resolvedEntity"></param>
        public static async Task ValidateAttributeContext(string expectedOutputPath, string entityName, CdmEntityDefinition resolvedEntity, bool updateExpectedOutput = false)
        {
            if (resolvedEntity.AttributeContext != null)
            {
                AttributeContextUtil attrCtxUtil = new AttributeContextUtil();

                // Actual
                string actualStringFilePath = Path.GetFullPath(Path.Combine(expectedOutputPath, "..", TestHelper.GetTestActualOutputFolderName(), $"AttrCtx_{entityName}.txt"));

                // Save Actual AttrCtx_*.txt and Resolved_*.cdm.json
                string actualText = attrCtxUtil.GetAttributeContextStrings(resolvedEntity);
                File.WriteAllText(actualStringFilePath, actualText);
                await resolvedEntity.InDocument.SaveAsAsync($"Resolved_{entityName}.cdm.json", saveReferenced : false);

                // Expected
                string expectedStringFilePath = Path.GetFullPath(Path.Combine(expectedOutputPath, $"AttrCtx_{entityName}.txt"));

                if (updateExpectedOutput)
                {
                    File.WriteAllText(expectedStringFilePath, File.ReadAllText(actualStringFilePath));
                }

                string expectedText = File.ReadAllText(expectedStringFilePath);

                // Test if Actual is Equal to Expected
                Assert.AreEqual(expectedText.Replace("\r\n", "\n"), actualText.Replace("\r\n", "\n"));
            }
        }
Esempio n. 4
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     = ProjectionTestUtils.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);
            await AttributeContextUtil.ValidateAttributeContext(corpus, expectedOutputPath, $"{entityName}{fileNameSuffix}", resolvedSalesForeignKeyProjection);
        }
Esempio n. 5
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 ProjectionTestUtils.GetResolvedEntity(corpus, entTestEntityProjection, new List <string> {
            });

            Assert.IsNotNull(resolvedTestEntityProjection);
            await AttributeContextUtil.ValidateAttributeContext(corpus, expectedOutputPath, entityName, resolvedTestEntityProjection);
        }
Esempio n. 6
0
        /// <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));

            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);

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