public void ClosingDocumentOnWindowClosingShouldntThrow()
        {
            Window.Show();
            DispatcherHelper.DoEvents();
            BindingTestClass          testClass = new BindingTestClass();
            WindowedDocumentUIService service   = CreateService();

            Interaction.GetBehaviors(Window).Add(service);
            IDocumentManagerService iService = service;

            IDocument document = null;

            WindowedDocumentUIService.WindowDocument typedDocument = null;
            var content = new TestDocumentContent();

            document      = iService.CreateDocument("View1", content);
            typedDocument = (WindowedDocumentUIService.WindowDocument)document;
            document.Show();
            DispatcherHelper.DoEvents();

            Window window = typedDocument.Window.RealWindow;

            content.onClose = () => document.Close();
            window.Close();
            DispatcherHelper.DoEvents();
        }
        void DoCloseTest(bool?allowClose, bool destroyOnClose, bool destroyed, Action <IDocument, bool> closeMethod)
        {
            Window.Show();
            DispatcherHelper.DoEvents();
            IDocumentManagerService service = null;
            bool      closeChecked          = false;
            bool      destroyCalled         = false;
            IDocument document = null;

            WindowedDocumentUIService windowedDocumentUIService = CreateService();

            Interaction.GetBehaviors(Window).Add(windowedDocumentUIService);
            service = windowedDocumentUIService;
            TestDocumentContent viewModel = new TestDocumentContent(() => {
                closeChecked = true;
                return(allowClose != null && allowClose.Value);
            }, () => {
                destroyCalled = true;
            });

            document = service.CreateDocument("EmptyView", viewModel);
            document.Show();
            DispatcherHelper.DoEvents();

            document.DestroyOnClose = destroyOnClose;
            closeMethod(document, allowClose == null);
            Assert.AreEqual(allowClose != null, closeChecked);
            Assert.AreEqual(destroyed, destroyCalled);
            Assert.AreEqual(!destroyed, service.Documents.Contains(document));
        }
コード例 #3
0
 void DoCloseTest(bool? allowClose, bool destroyOnClose, bool destroyed, Action<IDocument, bool> closeMethod) {
     EnqueueShowWindow();
     IDocumentManagerService service = null;
     bool closeChecked = false;
     bool destroyCalled = false;
     IDocument document = null;
     EnqueueCallback(() => {
         WindowedDocumentUIService windowedDocumentUIService = new WindowedDocumentUIService();
         Interaction.GetBehaviors(Window).Add(windowedDocumentUIService);
         service = windowedDocumentUIService;
         TestDocumentContent viewModel = new TestDocumentContent(() => {
             closeChecked = true;
             return allowClose != null && allowClose.Value;
         }, () => {
             destroyCalled = true;
         });
         document = service.CreateDocument("EmptyView", viewModel);
         document.Show();
     });
     EnqueueWindowUpdateLayout();
     EnqueueCallback(() => {
         document.DestroyOnClose = destroyOnClose;
         closeMethod(document, allowClose == null);
         Assert.AreEqual(allowClose != null, closeChecked);
         Assert.AreEqual(destroyed, destroyCalled);
         Assert.AreEqual(!destroyed, service.Documents.Contains(document));
     });
     EnqueueTestComplete();
 }