public async Task UnlinkSharedFileKeepSharedData()
        {
            // Two different models for same file. One is loaded and modified.
            // The other is not loaded. Unlinking the modified should assign
            // data to unloaded model.

            FilePath filePath = "test.txt";
            var      file     = new CustomFileModel();

            file.CreateNew();
            file.SetText("Foo");
            await file.LinkToFile(filePath);

            await registry.ShareModel(file);

            Assert.AreEqual(1, CustomFileModel.LiveBackends);

            var file2 = await registry.GetSharedModel <TextFileModel> (filePath);

            Assert.IsFalse(file2.IsLoaded);

            await file.ConvertToUnsaved();

            // Unsaved file content should have been migrated to second file
            await file2.Load();

            Assert.AreEqual("Foo", file2.GetText());
        }
        public async Task UnlinkSharedFile()
        {
            FilePath filePath = "test.txt";
            var      file     = new CustomFileModel();

            file.CreateNew();
            file.SetText("Foo");
            await file.LinkToFile(filePath);

            await registry.ShareModel(file);

            Assert.AreEqual(1, CustomFileModel.LiveBackends);

            var file2 = await registry.GetSharedModel <CustomFileModel> (filePath);

            await file2.Load();

            Assert.AreEqual(1, CustomFileModel.LiveBackends);
            Assert.AreEqual("Foo", file2.GetText());

            await file.ConvertToUnsaved();

            Assert.AreEqual(2, CustomFileModel.LiveBackends);
            Assert.IsNull(file.Id);
            file.SetText("Bar");
            Assert.AreEqual("Foo", file2.GetText());

            file.Dispose();
            Assert.AreEqual(1, CustomFileModel.LiveBackends);

            file2.Dispose();
            Assert.AreEqual(0, CustomFileModel.LiveBackends);
        }
        public async Task RegisterNew()
        {
            FilePath filePath = "test.txt";

            CustomFileModel.LiveBackends = 0;

            var file = new CustomFileModel();

            file.CreateNew();
            file.SetText("Foo");
            await file.LinkToFile(filePath);

            Assert.AreEqual(1, CustomFileModel.LiveBackends);

            await registry.ShareModel(file);

            Assert.AreEqual(1, CustomFileModel.LiveBackends);

            var otherFile = await registry.GetSharedModel <CustomFileModel> (filePath);

            Assert.AreNotSame(file, otherFile);
            Assert.IsFalse(otherFile.IsLoaded);
            Assert.AreEqual(1, CustomFileModel.LiveBackends);

            await otherFile.Load();

            Assert.AreEqual("Foo", otherFile.GetText());
            Assert.AreEqual(1, CustomFileModel.LiveBackends);

            // Backend is shared

            file.SetText("Bar");
            Assert.AreEqual("Bar", otherFile.GetText());

            otherFile.SetText("Bar2");
            Assert.AreEqual("Bar2", file.GetText());

            file.Dispose();
            Assert.AreEqual(1, CustomFileModel.LiveBackends);
            otherFile.Dispose();
            Assert.AreEqual(0, CustomFileModel.LiveBackends);
        }