"use strict";
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License. See License.txt in the project root for license information.
Object.defineProperty(exports, "__esModule", { value: true });
const cdmObjectType_1 = require("../../../Enums/cdmObjectType");
const internal_1 = require("../../../internal");
const CdmCollectionHelperFunctions_1 = require("./CdmCollectionHelperFunctions");
describe('Cdm.CdmCollection.CdmDefinitionCollection', () => {
    it('TestCdmDefinitionCollectionAdd', () => {
        const document = (0, CdmCollectionHelperFunctions_1.generateManifest)();
        document.isDirty = false;
        const attribute = new internal_1.CdmAttributeContext(document.ctx, 'the attribute');
        const folder = new internal_1.CdmFolderDefinition(document.ctx, 'The folder');
        const trait = new internal_1.CdmTraitDefinition(document.ctx, 'the Trait');
        const addedAttribute = document.definitions.push(attribute);
        const addedfolder = document.definitions.push(folder);
        const addedTrait = document.definitions.push(trait);
        expect(document.isDirty)
            .toBeTruthy();
        expect(document.definitions.length)
            .toEqual(3);
        expect(addedAttribute)
            .toEqual(attribute);
        expect(addedfolder)
            .toEqual(folder);
        expect(addedTrait)
            .toEqual(trait);
        expect(document.definitions.allItems[0])
            .toEqual(attribute);
        expect(document.definitions.allItems[1])
            .toEqual(folder);
        expect(document.definitions.allItems[2])
            .toEqual(trait);
        expect(attribute.inDocument)
            .toEqual(document);
        expect(trait.inDocument)
            .toEqual(document);
        expect(attribute.owner)
            .toEqual(document);
        expect(folder.owner)
            .toEqual(document);
        expect(trait.owner)
            .toEqual(document);
    });
    it('TestCdmDefinitionCollectionInsert', () => {
        const document = (0, CdmCollectionHelperFunctions_1.generateManifest)();
        const ent1 = document.definitions.push('ent1');
        const ent2 = document.definitions.push('ent2');
        document.isDirty = false;
        const attribute = new internal_1.CdmAttributeContext(document.ctx, 'the attribute');
        document.definitions.insert(0, attribute);
        expect(document.definitions.length)
            .toEqual(3);
        expect(document.isDirty)
            .toEqual(true);
        expect(document.definitions.allItems[0])
            .toEqual(attribute);
        expect(attribute.inDocument)
            .toEqual(document);
        expect(attribute.owner)
            .toEqual(document);
        expect(document.definitions.allItems[1])
            .toEqual(ent1);
        expect(document.definitions.allItems[2])
            .toEqual(ent2);
    });
    it('TestCdmDefinitionCollectionAddEntityByProvidingName', () => {
        const document = (0, CdmCollectionHelperFunctions_1.generateManifest)();
        document.isDirty = false;
        const entity = document.definitions.push('TheNameOfTheEntity');
        expect(document.isDirty)
            .toBeTruthy();
        expect(document.definitions.allItems[0])
            .toEqual(entity);
        expect(entity.inDocument)
            .toEqual(document);
        expect(entity.owner)
            .toEqual(document);
        expect(entity.entityName)
            .toEqual('TheNameOfTheEntity');
    });
    it('TestCdmDefinitionCollectionAddByProvidingTypeAndName', () => {
        const document = (0, CdmCollectionHelperFunctions_1.generateManifest)();
        document.isDirty = false;
        const attribute = document.definitions.push(cdmObjectType_1.cdmObjectType.attributeContextDef, 'attrctx');
        const trait = document.definitions.push(cdmObjectType_1.cdmObjectType.traitDef, 'traitname');
        expect(document.isDirty)
            .toEqual(true);
        expect(document.definitions.allItems[0])
            .toEqual(attribute);
        expect(document.definitions.allItems[1])
            .toEqual(trait);
        expect(attribute.inDocument)
            .toEqual(document);
        expect(attribute.owner)
            .toEqual(document);
        expect(trait.inDocument)
            .toEqual(document);
    });
    it('TestCdmDefinitionCollectionAddRange', () => {
        const document = (0, CdmCollectionHelperFunctions_1.generateManifest)();
        document.isDirty = false;
        const attribute = new internal_1.CdmAttributeContext(document.ctx, 'the attribute');
        const folder = new internal_1.CdmFolderDefinition(document.ctx, 'The folder');
        const trait = new internal_1.CdmTraitDefinition(document.ctx, 'the Trait');
        const definitionsList = [
            attribute,
            folder,
            trait
        ];
        document.definitions.concat(definitionsList);
        expect(document.isDirty)
            .toEqual(true);
        expect(document.definitions.length)
            .toEqual(3);
        expect(document.definitions.allItems[0])
            .toEqual(attribute);
        expect(document.definitions.allItems[1])
            .toEqual(folder);
        expect(document.definitions.allItems[2])
            .toEqual(trait);
        expect(attribute.inDocument)
            .toEqual(document);
        expect(trait.inDocument)
            .toEqual(document);
        expect(attribute.owner)
            .toEqual(document);
        expect(folder.owner)
            .toEqual(document);
        expect(trait.owner)
            .toEqual(document);
    });
});
//# sourceMappingURL=CdmDefinitionCollection.test.js.map