"use strict";
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License. See License.txt in the project root for license information.
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
    function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
    return new (P || (P = Promise))(function (resolve, reject) {
        function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
        function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
        function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
        step((generator = generator.apply(thisArg, _arguments || [])).next());
    });
};
Object.defineProperty(exports, "__esModule", { value: true });
const testHelper_1 = require("../../testHelper");
const projectionTestUtils_1 = require("../../Utilities/projectionTestUtils");
/**
 * A test class to verify the attribute context tree and traits generated for various resolution scenarios given a default resolution option/directive.
 */
describe('Cdm/Projection/ProjectionAttributeContext', () => {
    /**
     * The path between TestDataPath and TestName.
     */
    const testsSubpath = 'Cdm/Projection/ProjectionAttributeContextTest';
    /**
     * Extends entity with a string reference
     */
    it('TestEntityStringReference', () => __awaiter(void 0, void 0, void 0, function* () {
        const testName = 'TestEntityStringReference';
        const entityName = 'TestEntStrRef';
        const corpus = testHelper_1.testHelper.getLocalCorpus(testsSubpath, testName);
        yield projectionTestUtils_1.projectionTestUtils.loadEntityForResolutionOptionAndSave(corpus, testName, testsSubpath, entityName, []);
    }));
    /**
     * Extends entity with an entity reference
     */
    it('TestEntityEntityReference', () => __awaiter(void 0, void 0, void 0, function* () {
        const testName = 'TestEntityEntityReference';
        const entityName = 'TestEntEntRef';
        const corpus = testHelper_1.testHelper.getLocalCorpus(testsSubpath, testName);
        yield projectionTestUtils_1.projectionTestUtils.loadEntityForResolutionOptionAndSave(corpus, testName, testsSubpath, entityName, []);
    }));
    /**
     * Extends entity with a projection
     */
    it('TestEntityProjection', () => __awaiter(void 0, void 0, void 0, function* () {
        const testName = 'TestEntityProjection';
        const entityName = testName;
        const corpus = testHelper_1.testHelper.getLocalCorpus(testsSubpath, testName);
        yield projectionTestUtils_1.projectionTestUtils.loadEntityForResolutionOptionAndSave(corpus, testName, testsSubpath, entityName, []);
    }));
    /**
     * Extends entity with a nested projection
     */
    it('TestEntityNestedProjection', () => __awaiter(void 0, void 0, void 0, function* () {
        const testName = 'TestEntityNestedProjection';
        const entityName = 'NestedProjection';
        const corpus = testHelper_1.testHelper.getLocalCorpus(testsSubpath, testName);
        yield projectionTestUtils_1.projectionTestUtils.loadEntityForResolutionOptionAndSave(corpus, testName, testsSubpath, entityName, []);
    }));
    /**
     * Entity attribute referenced with a string
     */
    it('TestEntityAttributeStringReference', () => __awaiter(void 0, void 0, void 0, function* () {
        const testName = 'TestEntityAttributeStringReference';
        const entityName = 'TestEntAttrStrRef';
        const corpus = testHelper_1.testHelper.getLocalCorpus(testsSubpath, testName);
        yield projectionTestUtils_1.projectionTestUtils.loadEntityForResolutionOptionAndSave(corpus, testName, testsSubpath, entityName, []);
    }));
    /**
     * Entity attribute referenced with an entity reference
     */
    it('TestEntityAttributeEntityReference', () => __awaiter(void 0, void 0, void 0, function* () {
        const testName = 'TestEntityAttributeEntityReference';
        const entityName = 'TestEntAttrEntRef';
        const corpus = testHelper_1.testHelper.getLocalCorpus(testsSubpath, testName);
        yield projectionTestUtils_1.projectionTestUtils.loadEntityForResolutionOptionAndSave(corpus, testName, testsSubpath, entityName, []);
    }));
    /**
     * Entity attribute referenced with a projection
     */
    it('TestEntityAttributeProjection', () => __awaiter(void 0, void 0, void 0, function* () {
        const testName = 'TestEntityAttributeProjection';
        const entityName = 'TestEntAttrProj';
        const corpus = testHelper_1.testHelper.getLocalCorpus(testsSubpath, testName);
        yield projectionTestUtils_1.projectionTestUtils.loadEntityForResolutionOptionAndSave(corpus, testName, testsSubpath, entityName, []);
    }));
    /**
     * Entity attribute referenced with a nested projection
     */
    it('TestEntityAttributeNestedProjection', () => __awaiter(void 0, void 0, void 0, function* () {
        const testName = 'TestEntityAttributeNestedProjection';
        const entityName = 'NestedProjection';
        const corpus = testHelper_1.testHelper.getLocalCorpus(testsSubpath, testName);
        yield projectionTestUtils_1.projectionTestUtils.loadEntityForResolutionOptionAndSave(corpus, testName, testsSubpath, entityName, []);
    }));
    /**
     * Entity that exhibits custom traits
     */
    it('TestEntityTrait', () => __awaiter(void 0, void 0, void 0, function* () {
        const testName = 'TestEntityTrait';
        const entityName = testName;
        const corpus = testHelper_1.testHelper.getLocalCorpus(testsSubpath, testName);
        const resolvedEntity = yield projectionTestUtils_1.projectionTestUtils.loadEntityForResolutionOptionAndSave(corpus, testName, testsSubpath, entityName, []);
        // Attribute Name
        expect(resolvedEntity.attributes.allItems[0].name)
            .toEqual('TestAttribute');
        // Trait Name
        expect(resolvedEntity.attributes.allItems[0].appliedTraits.allItems[3].namedReference)
            .toEqual('does.haveDefault');
        // Trait Name
        expect(resolvedEntity.attributes.allItems[0].appliedTraits.allItems[4].namedReference)
            .toEqual('testTrait');
        // Trait Param Name
        expect(resolvedEntity.attributes.allItems[0].appliedTraits.allItems[4].arguments.allItems[0].resolvedParameter.name)
            .toEqual('testTraitParam1');
        // Trait Param Default Value
        expect((resolvedEntity.attributes.allItems[0].appliedTraits.allItems[4].arguments.allItems[0]).value)
            .toEqual('TestTrait Param 1 DefaultValue');
    }));
    /**
     * Entity that extends and exhibits custom traits
     */
    it('TestEntityExtendsTrait', () => __awaiter(void 0, void 0, void 0, function* () {
        const testName = 'TestEntityExtendsTrait';
        const entityName = 'ExtendsTrait';
        const corpus = testHelper_1.testHelper.getLocalCorpus(testsSubpath, testName);
        const resolvedEntity = yield projectionTestUtils_1.projectionTestUtils.loadEntityForResolutionOptionAndSave(corpus, testName, testsSubpath, entityName, []);
        // Attribute Name
        expect(resolvedEntity.attributes.allItems[0].name)
            .toEqual('TestExtendsTraitAttribute');
        // Trait Name
        expect(resolvedEntity.attributes.allItems[0].appliedTraits.allItems[3].namedReference)
            .toEqual('does.haveDefault');
        // Trait Name
        expect(resolvedEntity.attributes.allItems[0].appliedTraits.allItems[4].namedReference)
            .toEqual('testTraitDerived');
        // Trait Param Name
        expect((resolvedEntity.attributes.allItems[0].appliedTraits.allItems[4].arguments.allItems[0]).resolvedParameter.name)
            .toEqual('testTraitParam1');
        // Trait Param Default Value
        expect((resolvedEntity.attributes.allItems[0].appliedTraits.allItems[4].arguments.allItems[0]).value)
            .toEqual('TestTrait Param 1 DefaultValue');
    }));
    /**
     * Entity with projection that exhibits custom traits
     */
    it('TestProjectionTrait', () => __awaiter(void 0, void 0, void 0, function* () {
        const testName = 'TestProjectionTrait';
        const entityName = testName;
        const corpus = testHelper_1.testHelper.getLocalCorpus(testsSubpath, testName);
        const resolvedEntity = yield projectionTestUtils_1.projectionTestUtils.loadEntityForResolutionOptionAndSave(corpus, testName, testsSubpath, entityName, []);
        // Attribute Name
        expect(resolvedEntity.attributes.allItems[0].name)
            .toEqual('TestProjectionAttribute');
        // Trait Name
        expect(resolvedEntity.attributes.allItems[0].appliedTraits.allItems[3].namedReference)
            .toEqual('does.haveDefault');
        // Trait Name
        expect(resolvedEntity.attributes.allItems[0].appliedTraits.allItems[4].namedReference)
            .toEqual('testTrait');
        // Trait Param Name
        expect((resolvedEntity.attributes.allItems[0].appliedTraits.allItems[4].arguments.allItems[0]).resolvedParameter.name)
            .toEqual('testTraitParam1');
        // Trait Param Default Value
        expect((resolvedEntity.attributes.allItems[0].appliedTraits.allItems[4].arguments.allItems[0]).value)
            .toEqual('TestTrait Param 1 DefaultValue');
    }));
    /**
     * Entity with projection that extends and exhibits custom traits
     */
    it('TestProjectionExtendsTrait', () => __awaiter(void 0, void 0, void 0, function* () {
        const testName = 'TestProjectionExtendsTrait';
        const entityName = 'ExtendsTrait';
        const corpus = testHelper_1.testHelper.getLocalCorpus(testsSubpath, testName);
        const resolvedEntity = yield projectionTestUtils_1.projectionTestUtils.loadEntityForResolutionOptionAndSave(corpus, testName, testsSubpath, entityName, []);
        // Attribute Name
        expect(resolvedEntity.attributes.allItems[0].name)
            .toEqual('TestProjectionAttribute');
        // Trait Name
        expect(resolvedEntity.attributes.allItems[0].appliedTraits.allItems[3].namedReference)
            .toEqual('does.haveDefault');
        // Trait Name
        expect(resolvedEntity.attributes.allItems[0].appliedTraits.allItems[4].namedReference)
            .toEqual('testTrait');
        // Trait Param Name
        expect((resolvedEntity.attributes.allItems[0].appliedTraits.allItems[4].arguments.allItems[0]).resolvedParameter.name)
            .toEqual('testTraitParam1');
        // Trait Param Default Value
        expect((resolvedEntity.attributes.allItems[0].appliedTraits.allItems[4].arguments.allItems[0]).value)
            .toEqual('TestTrait Param 1 DefaultValue');
        // Attribute Name
        expect(resolvedEntity.attributes.allItems[1].name)
            .toEqual('TestProjectionAttributeB');
        // Trait Name
        expect(resolvedEntity.attributes.allItems[1].appliedTraits.allItems[3].namedReference)
            .toEqual('does.haveDefault');
        // Trait Name
        expect(resolvedEntity.attributes.allItems[1].appliedTraits.allItems[4].namedReference)
            .toEqual('testTrait');
        // Trait Param Name
        expect((resolvedEntity.attributes.allItems[1].appliedTraits.allItems[4].arguments.allItems[0]).resolvedParameter.name)
            .toEqual('testTraitParam1');
        // Trait Param Default Value
        expect((resolvedEntity.attributes.allItems[1].appliedTraits.allItems[4].arguments.allItems[0]).value)
            .toEqual('TestTrait Param 1 DefaultValue');
        // Trait Name
        expect(resolvedEntity.attributes.allItems[1].appliedTraits.allItems[5].namedReference)
            .toEqual('testExtendsTraitB');
        // Trait Param Name
        expect((resolvedEntity.attributes.allItems[1].appliedTraits.allItems[5].arguments.allItems[0]).resolvedParameter.name)
            .toEqual('testTraitParam1');
        // Trait Param Default Value
        expect((resolvedEntity.attributes.allItems[1].appliedTraits.allItems[5].arguments.allItems[0]).value)
            .toEqual('TestTrait Param 1 DefaultValue');
        // Trait Param Name
        expect((resolvedEntity.attributes.allItems[1].appliedTraits.allItems[5].arguments.allItems[1]).resolvedParameter.name)
            .toEqual('testExtendsTraitBParam1');
        // Trait Param Default Value
        expect((resolvedEntity.attributes.allItems[1].appliedTraits.allItems[5].arguments.allItems[1]).value)
            .toEqual('TestExtendsTraitB Param 1 DefaultValue');
    }));
});
//# sourceMappingURL=ProjectionAttributeContext.test.js.map