public async Task ReuseDocumentIdentifiedByDescriptor() { var f1 = new ReusableControllerFactory(); documentControllerService.RegisterFactory(f1); try { var controller = new ReusableController(); var descriptor = new ReusableDescriptor(); await controller.Initialize(descriptor); var doc = await documentManager.OpenDocument(controller); Assert.NotNull(doc); var doc2 = await documentManager.OpenDocument(descriptor); Assert.AreSame(doc, doc2); var doc3 = await documentManager.OpenDocument(new ReusableDescriptor()); Assert.AreNotSame(doc, doc3); } finally { documentControllerService.UnregisterFactory(f1); } }
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); } }