Beispiel #1
0
        public async Task LoadFileWithImplicitModel()
        {
            FilePath tempFile = Path.GetTempFileName();

            try {
                File.Move(tempFile, tempFile + ".txt");
                tempFile = tempFile + ".txt";
                File.WriteAllText(tempFile, "Test");

                var file = new TestFileDocumentController();
                await file.Initialize(new FileDescriptor (tempFile, null, null));

                Assert.IsFalse(file.IsNewDocument);
                Assert.IsFalse(file.HasUnsavedChanges);
                Assert.AreEqual(tempFile, file.FilePath);
                Assert.AreEqual("text/plain", file.MimeType);
                Assert.AreEqual(Encoding.UTF8, file.Encoding);
                Assert.IsInstanceOf <TextFileModel> (file.Model);
                Assert.IsTrue(file.Model.IsLinked);
                Assert.IsFalse(file.Model.IsLoaded);
                Assert.AreEqual(tempFile, file.FileModel.FilePath);
                Assert.AreEqual(tempFile.FileName, file.DocumentTitle);

                await file.Model.Load();

                // Verify that the model is now shared
                var registry = await Runtime.GetService <DocumentModelRegistry> ();

                var copy = await registry.GetSharedModel <TextFileModel> (tempFile);

                await copy.Load();

                Assert.AreEqual("Test", copy.GetText());

                await file.FileModel.SetContent(TestHelper.ToStream("Test Changed"));

                Assert.IsTrue(file.HasUnsavedChanges);

                Assert.AreEqual("Test Changed", copy.GetText());

                await file.Save();

                Assert.IsFalse(file.HasUnsavedChanges);

                Assert.AreEqual("Test Changed", File.ReadAllText(tempFile));
            } finally {
                File.Delete(tempFile);
            }
        }
Beispiel #2
0
        public async Task InferMimeType()
        {
            FilePath filePath = "foo.txt";
            var      file     = new TestFileDocumentController();
            await file.Initialize(new FileDescriptor (filePath, null, null));

            Assert.AreEqual("foo.txt", file.FilePath.FileName);
            Assert.AreEqual("text/plain", file.MimeType);

            file.MimeType = "text/xml";
            Assert.AreEqual("text/xml", file.MimeType);

            file.MimeType = null;
            Assert.AreEqual("text/plain", file.MimeType);
        }