"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 Persistence_1 = require("../../../Persistence");
const internal_1 = require("../../../internal");
const testHelper_1 = require("../../testHelper");
const modelJsonUnitTestLocalAdapter_1 = require("../../modelJsonUnitTestLocalAdapter");
/**
 *
 */
describe('Cdm/ReferencedEntityDeclarationTest', () => {
    /**
     * The path between TestDataPath and TestName.
     */
    const testsSubpath = 'Cdm/ReferencedEntityDeclaration';
    /**
     * Test that ReferencedEntity is correctly found with path separator as "/" or "\"
     */
    it('TestRefEntityWithSlashPath', () => __awaiter(void 0, void 0, void 0, function* () {
        const slashCorpus = testHelper_1.testHelper.getLocalCorpus(testsSubpath, 'TestRefEntityWithSlashPath');
        const slashLocalPath = slashCorpus.storage.namespaceAdapters.get('local').root;
        var slashAdapter = new modelJsonUnitTestLocalAdapter_1.ModelJsonUnitTestLocalAdapter(slashLocalPath);
        slashCorpus.storage.mount("slash", slashAdapter);
        slashCorpus.storage.defaultNamespace = "slash";
        // load model.json files with paths generated using both '/' and '\'
        var slashManifest = yield slashCorpus.fetchObjectAsync('slash:/model.json');
        // manually add the reference model location, path will vary on each machine
        var refModelTrait = slashManifest.exhibitsTraits.item('is.modelConversion.referenceModelMap');
        var entityPath = slashManifest.entities.allItems[0].entityPath;
        refModelTrait.arguments.allItems[0].value[0].location = slashAdapter.createAdapterPath(entityPath.substring(0, entityPath.lastIndexOf('/')));
        var slashModel = yield Persistence_1.ModelJson.ManifestPersistence.toData(slashManifest, new internal_1.resolveOptions(), new internal_1.copyOptions());
        expect(slashModel)
            .not.toBeUndefined();
        expect(slashModel.entities.length)
            .toBe(1);
        const backSlashCorpus = testHelper_1.testHelper.getLocalCorpus(testsSubpath, 'TestRefEntityWithSlashPath');
        var backSlashLocalPath = backSlashCorpus.storage.namespaceAdapters.get('local').root;
        var backSlashAdapter = new modelJsonUnitTestLocalAdapter_1.ModelJsonUnitTestLocalAdapter(backSlashLocalPath);
        backSlashCorpus.storage.mount('backslash', backSlashAdapter);
        backSlashCorpus.storage.defaultNamespace = 'backslash';
        var backSlashManifest = yield backSlashCorpus.fetchObjectAsync('backslash:/model.json');
        // manually add the reference model location, path will vary on each machine
        var backSlashRefModelTrait = backSlashManifest.exhibitsTraits.item('is.modelConversion.referenceModelMap');
        var backSlashEntityPath = backSlashManifest.entities.allItems[0].entityPath;
        backSlashRefModelTrait.arguments.allItems[0].value[0].location = backSlashAdapter.createAdapterPath(backSlashEntityPath.substring(0, backSlashEntityPath.lastIndexOf('/')))
            .replace(/\//g, '\\\\');
        const backSlashModel = yield Persistence_1.ModelJson.ManifestPersistence.toData(backSlashManifest, new internal_1.resolveOptions(), new internal_1.copyOptions());
        expect(backSlashModel)
            .not.toBeUndefined();
        expect(backSlashModel.entities.length)
            .toBe(1);
    }));
});
//# sourceMappingURL=ReferencedEntityDeclaration.test.js.map