"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 ts_stopwatch_1 = require("ts-stopwatch");
const internal_1 = require("../../../internal");
const testHelper_1 = require("../../testHelper");
/**
 *  A test class for testing the performance of projection operations
 */
describe('Cdm/Projection/ProjectionPerformanceTest', () => {
    /**
     * The path between TestDataPath and TestName.
     */
    const testsSubpath = 'Cdm/Projection/ProjectionPerformanceTest';
    /**
     * Test the performance of loading an entity that contains a deeply nested projection
     */
    it('TestProjectionPerformanceOnLoad', () => __awaiter(void 0, void 0, void 0, function* () {
        var corpus = testHelper_1.testHelper.getLocalCorpus(testsSubpath, 'TestProjectionPerformanceOnLoad');
        var entity = yield corpus.fetchObjectAsync("largeProjectionEntity.cdm.json/largeProjectionEntity");
        var operation = entity.attributes.allItems[0].entity.explicitReference.operations.allItems[0];
        var attGroup = operation.newAttribute.explicitReference;
        // add a large number of attributes to the projection
        for (var i = 1; i < 10000; i++) {
            attGroup.members.push(new internal_1.CdmTypeAttributeDefinition(corpus.ctx, "a" + i));
        }
        const stopwatch = new ts_stopwatch_1.Stopwatch();
        stopwatch.start();
        // reindex the entity to run through the visit function
        yield entity.inDocument.indexIfNeeded(new internal_1.resolveOptions(entity.inDocument), true);
        stopwatch.stop();
        expect(stopwatch.getTime())
            .toBeLessThan(500);
    }));
});
//# sourceMappingURL=ProjectionPerformance.test.js.map