"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 internal_1 = require("../../../../internal");
const ManifestPersistence_1 = require("../../../../Persistence/CdmFolder/ManifestPersistence");
const testHelper_1 = require("../../../testHelper");
describe('Persistence.CdmFolder.CdmFolderPersistence', () => {
    /// <summary>
    /// The path between TestDataPath and TestName.
    /// </summary>
    const testsSubpath = 'Persistence/CdmFolder/CdmFolderPersistence';
    it('TestFromAndToData', () => __awaiter(void 0, void 0, void 0, function* () {
        const expectedLogCodes = new Set([internal_1.cdmLogCode.ErrResolveReferenceFailure]);
        const corpus = testHelper_1.testHelper.getLocalCorpus(testsSubpath, 'TestFromAndToData', undefined, false, expectedLogCodes);
        const folder = corpus.storage.fetchRootFolder("local");
        const manifest = yield corpus.fetchObjectAsync(`default${internal_1.CdmConstants.manifestExtension}`, folder);
        const actualData = ManifestPersistence_1.ManifestPersistence.toData(manifest, undefined, undefined);
        manifest.entities.allItems.forEach((entity) => __awaiter(void 0, void 0, void 0, function* () {
            yield corpus.fetchObjectAsync(entity.entityPath, manifest);
        }));
        corpus.storage.fetchRootFolder("output").documents.push(manifest);
        yield manifest.saveAsAsync(`default${internal_1.CdmConstants.manifestExtension}`, true);
        testHelper_1.testHelper.expectCdmLogCodeEquality(corpus, internal_1.cdmLogCode.ErrResolveReferenceFailure, true);
        var expected_data = testHelper_1.testHelper.getExpectedOutputFileContent(testsSubpath, 'TestFromAndToData', `default${internal_1.CdmConstants.manifestExtension}`);
        testHelper_1.testHelper.assertSameObjectWasSerialized(expected_data, JSON.stringify(actualData));
    }));
});
//# sourceMappingURL=CdmFolderPersistence.test.js.map