Пример #1
0
        public async Task ReuseFileDocumentWithNoReuseFlag()
        {
            var f1 = new ReusableFileControllerFactory();
            var f2 = new ReusableFileControllerFactory();

            documentControllerService.RegisterFactory(f1);
            documentControllerService.RegisterFactory(f2);

            f1.Enabled = true;
            f2.Enabled = false;

            var project = Services.ProjectService.CreateDotNetProject("C#");

            var file = GetTempFile(".dll_test");

            try {
                var doc = await documentManager.OpenDocument(new FileOpenInformation (file, project));

                Assert.NotNull(doc);
                var controller = (ReusableFileController)doc.DocumentController;
                controller.AllowReuse = false;

                // If the reusable flag is set, reuse the doc since even if TryReuseDocument returns false, the file names match.

                var doc2 = await documentManager.OpenDocument(new FileOpenInformation (file, project) { Options = OpenDocumentOptions.TryToReuseViewer });

                Assert.AreSame(doc, doc2);

                // If the reusable flag is not set, the document can't be reused, even if names match

                doc2 = await documentManager.OpenDocument(new FileOpenInformation (file, project) { Options = OpenDocumentOptions.None });

                Assert.AreNotSame(doc, doc2);

                // The old non-reusable document must have been closed
                Assert.AreEqual(1, documentManager.Documents.Count);
            } finally {
                documentControllerService.UnregisterFactory(f1);
                documentControllerService.UnregisterFactory(f2);
                project.Dispose();
                File.Delete(file);
            }
        }
Пример #2
0
        public async Task ReuseFileDocumentChangingOwner()
        {
            var f2 = new ReusableFileControllerFactory();

            documentControllerService.RegisterFactory(f2);
            var project  = Services.ProjectService.CreateDotNetProject("C#");
            var project2 = Services.ProjectService.CreateDotNetProject("C#");

            var file = GetTempFile(".dll_test");

            try {
                var doc = await documentManager.OpenDocument(new FileOpenInformation (file, project));

                Assert.NotNull(doc);
                Assert.AreSame(project, doc.DocumentController.Owner);

                // Reuse

                var doc2 = await documentManager.OpenDocument(new FileOpenInformation (file, project));

                Assert.AreSame(doc, doc2);
                Assert.AreSame(project, doc.DocumentController.Owner);

                // Reuse, changing owner

                doc2 = await documentManager.OpenDocument(new FileOpenInformation (file, project2));

                Assert.AreSame(doc, doc2);
                Assert.AreSame(project2, doc.DocumentController.Owner);
            } finally {
                documentControllerService.UnregisterFactory(f2);
                project.Dispose();
                project2.Dispose();
                File.Delete(file);
            }
        }
Пример #3
0
        public async Task ReuseFileDocument()
        {
            var f1 = new ReusableControllerFactory();
            var f2 = new ReusableFileControllerFactory();

            documentControllerService.RegisterFactory(f1);
            documentControllerService.RegisterFactory(f2);

            var foo_dll_test = GetTempFile(".dll_test");
            var bar_dll_test = GetTempFile(".dll_test");
            var bar_exe_test = GetTempFile(".exe_test");
            var foo_txt      = GetTempFile(".txt");

            try {
                var controller = new ReusableFileController();
                var descriptor = new FileDescriptor(foo_dll_test, null, null);
                await controller.Initialize(descriptor);

                var doc = await documentManager.OpenDocument(controller);

                Assert.NotNull(doc);

                var doc2 = await documentManager.OpenDocument(new FileDescriptor (foo_dll_test, null, null));

                Assert.AreSame(doc, doc2);

                doc2 = await documentManager.OpenDocument(new FileDescriptor (bar_dll_test, null, null));

                Assert.AreSame(doc, doc2);

                doc2 = await documentManager.OpenDocument(new FileDescriptor (bar_exe_test, null, null));

                Assert.AreSame(doc, doc2);

                doc2 = await documentManager.OpenDocument(new FileDescriptor (foo_txt, null, null));

                Assert.AreNotSame(doc, doc2);
                await doc2.Close();

                doc2 = await documentManager.OpenDocument(new FileOpenInformation (foo_dll_test));

                Assert.AreSame(doc, doc2);

                doc2 = await documentManager.OpenDocument(new FileOpenInformation (bar_dll_test));

                Assert.AreSame(doc, doc2);

                doc2 = await documentManager.OpenDocument(new FileOpenInformation (bar_exe_test));

                Assert.AreSame(doc, doc2);

                doc2 = await documentManager.OpenDocument(new FileOpenInformation (foo_txt));

                Assert.AreNotSame(doc, doc2);
                await doc2.Close();

                await documentManager.CloseAllDocuments(false);

                doc2 = await documentManager.OpenDocument(new FileOpenInformation (foo_dll_test) { Options = OpenDocumentOptions.None });

                Assert.AreNotSame(doc, doc2);
                await doc2.Close();

                doc2 = await documentManager.OpenDocument(new FileOpenInformation (bar_dll_test) { Options = OpenDocumentOptions.None });

                Assert.AreNotSame(doc, doc2);
                await doc2.Close();

                doc2 = await documentManager.OpenDocument(new FileOpenInformation (bar_exe_test) { Options = OpenDocumentOptions.None });

                Assert.AreNotSame(doc, doc2);
                await doc2.Close();

                doc2 = await documentManager.OpenDocument(new FileOpenInformation (foo_txt) { Options = OpenDocumentOptions.None });

                Assert.AreNotSame(doc, doc2);
                await doc2.Close();
            } finally {
                documentControllerService.UnregisterFactory(f1);
                documentControllerService.UnregisterFactory(f2);
                File.Delete(foo_dll_test);
                File.Delete(bar_dll_test);
                File.Delete(bar_exe_test);
                File.Delete(foo_txt);
            }
        }