Ejemplo n.º 1
0
        public void Dispose_ViewHostWithMultipleViews_ViewsClearedActiveDocumentViewSetToNullAndActiveViewEventsFired()
        {
            // Setup
            var testView1 = new TestView();
            var testView2 = new TestView();
            var testView3 = new TestView();
            var testView4 = new TestView();
            var activeDocumentViewChangingCounter = 0;
            var activeDocumentViewChangedCounter  = 0;
            var activeViewChangedCounter          = 0;

            var avalonDockViewHost = new AvalonDockViewHost();

            avalonDockViewHost.AddDocumentView(testView1, string.Empty, string.Empty, null);
            avalonDockViewHost.AddDocumentView(testView2, string.Empty, string.Empty, null);
            avalonDockViewHost.AddToolView(testView3, ToolViewLocation.Left, string.Empty, string.Empty, null);
            avalonDockViewHost.AddToolView(testView4, ToolViewLocation.Left, string.Empty, string.Empty, null);

            SetActiveView(avalonDockViewHost, testView1);

            CollectionAssert.AreEqual(
                new[]
            {
                testView3,
                testView4
            },
                avalonDockViewHost.ToolViews);

            avalonDockViewHost.ActiveDocumentViewChanging += (sender, args) => activeDocumentViewChangingCounter++;
            avalonDockViewHost.ActiveDocumentViewChanged  += (sender, args) => activeDocumentViewChangedCounter++;
            avalonDockViewHost.ActiveViewChanged          += (sender, args) => activeViewChangedCounter++;

            // Call
            avalonDockViewHost.Dispose();

            // Assert
            CollectionAssert.IsEmpty(avalonDockViewHost.DocumentViews);
            CollectionAssert.IsEmpty(avalonDockViewHost.ToolViews);
            Assert.AreNotEqual(0, activeDocumentViewChangingCounter);
            Assert.AreNotEqual(0, activeDocumentViewChangedCounter);
            Assert.AreNotEqual(0, activeViewChangedCounter);
            Assert.IsNull(avalonDockViewHost.ActiveDocumentView);
            Assert.IsFalse(IsAnyViewActive(avalonDockViewHost));
        }
Ejemplo n.º 2
0
        public void Remove_ToolViewInViewHostWithMultipleOtherViews_ActiveDocumentViewNotAffectedAndNoActiveViewEventsFired()
        {
            // Setup
            var testView1 = new TestView();
            var testView2 = new TestView();
            var testView3 = new TestView();
            var testView4 = new TestView();
            var testView5 = new TestView();
            var activeDocumentViewChangingCounter = 0;
            var activeDocumentViewChangedCounter  = 0;
            var activeViewChangedCounter          = 0;

            using (var avalonDockViewHost = new AvalonDockViewHost())
            {
                avalonDockViewHost.AddDocumentView(testView1, string.Empty, string.Empty, null);
                avalonDockViewHost.AddDocumentView(testView2, string.Empty, string.Empty, null);
                avalonDockViewHost.AddDocumentView(testView3, string.Empty, string.Empty, null);
                avalonDockViewHost.AddDocumentView(testView4, string.Empty, string.Empty, null);
                avalonDockViewHost.AddToolView(testView5, ToolViewLocation.Left, string.Empty, string.Empty, null);

                SetActiveView(avalonDockViewHost, testView3);
                SetActiveView(avalonDockViewHost, testView5);

                // Precondition
                Assert.AreSame(testView3, avalonDockViewHost.ActiveDocumentView);

                avalonDockViewHost.ActiveDocumentViewChanging += (sender, args) => activeDocumentViewChangingCounter++;
                avalonDockViewHost.ActiveDocumentViewChanged  += (sender, args) => activeDocumentViewChangedCounter++;
                avalonDockViewHost.ActiveViewChanged          += (sender, args) => activeViewChangedCounter++;

                // Call
                avalonDockViewHost.Remove(testView5);

                // Assert
                Assert.AreEqual(0, activeDocumentViewChangingCounter);
                Assert.AreEqual(0, activeDocumentViewChangedCounter);
                Assert.AreEqual(0, activeViewChangedCounter);
                Assert.AreSame(testView3, avalonDockViewHost.ActiveDocumentView);
            }
        }
Ejemplo n.º 3
0
        public void AddToolView_DocumentViewSetAsActiveView_ActiveDocumentViewNotAffected()
        {
            // Setup
            var testToolView     = new TestView();
            var testDocumentView = new TestView();

            using (var avalonDockViewHost = new AvalonDockViewHost())
            {
                avalonDockViewHost.AddDocumentView(testDocumentView, string.Empty, string.Empty, null);
                SetActiveView(avalonDockViewHost, testDocumentView);

                // Call
                avalonDockViewHost.AddToolView(testToolView, ToolViewLocation.Left, string.Empty, string.Empty, null);

                // Assert
                Assert.AreSame(testDocumentView, avalonDockViewHost.ActiveDocumentView);
                Assert.IsTrue(IsActiveView(avalonDockViewHost, testDocumentView));
            }
        }
Ejemplo n.º 4
0
        public void SetTitle_DocumentView_TitleSet()
        {
            // Setup
            const string titleToSet = "Random title";

            var testView = new TestView();

            using (var avalonDockViewHost = new AvalonDockViewHost())
            {
                avalonDockViewHost.AddDocumentView(testView, string.Empty, string.Empty, null);

                // Precondition
                Assert.IsFalse(AvalonDockViewHostTestHelper.IsTitleSet(avalonDockViewHost, testView, titleToSet));

                // Call
                avalonDockViewHost.SetTitle(testView, titleToSet);

                // Assert
                Assert.IsTrue(AvalonDockViewHostTestHelper.IsTitleSet(avalonDockViewHost, testView, titleToSet));
            }
        }
Ejemplo n.º 5
0
        public void AddDocumentView_WithAllParameters_ViewAddedWithExpectedProperties()
        {
            // Setup
            using (var avalonDockViewHost = new AvalonDockViewHost())
            {
                const string title      = "Random title";
                const string symbol     = "Random symbol";
                var          fontFamily = new FontFamily();

                var testView = new TestView();

                // Call
                avalonDockViewHost.AddDocumentView(testView, title, symbol, fontFamily);

                // Assert
                CustomLayoutDocument layoutDocument = GetLayoutDocument(avalonDockViewHost, testView);
                Assert.AreEqual(title, layoutDocument.Title);
                Assert.AreEqual(symbol, layoutDocument.Symbol);
                Assert.AreSame(fontFamily, layoutDocument.FontFamily);
            }
        }
Ejemplo n.º 6
0
        public void Remove_DocumentView_ViewClosedEventsFired()
        {
            // Setup
            var testView          = new TestView();
            var viewClosedCounter = 0;

            using (var avalonDockViewHost = new AvalonDockViewHost())
            {
                avalonDockViewHost.AddDocumentView(testView, string.Empty, string.Empty, null);

                avalonDockViewHost.ViewClosed += (sender, args) =>
                {
                    Assert.AreSame(testView, args.View);

                    viewClosedCounter++;
                };

                // Call
                avalonDockViewHost.Remove(testView);

                // Assert
                Assert.AreEqual(1, viewClosedCounter);
            }
        }
Ejemplo n.º 7
0
        public void AddDocumentView_NonControlView_ViewNotAddedAndNoViewOpenedEventFired()
        {
            // Setup
            var mocks    = new MockRepository();
            var testView = mocks.StrictMock <IView>();

            mocks.ReplayAll();

            using (var avalonDockViewHost = new AvalonDockViewHost())
            {
                var viewOpenedCounter = 0;
                avalonDockViewHost.ViewOpened += (sender, args) => viewOpenedCounter++;

                // Call
                avalonDockViewHost.AddDocumentView(testView, string.Empty, string.Empty, null);

                // Assert
                CollectionAssert.IsEmpty(avalonDockViewHost.DocumentViews);
                Assert.IsFalse(IsDocumentViewPresent(avalonDockViewHost, testView));
                Assert.AreEqual(0, viewOpenedCounter);
            }

            mocks.VerifyAll();
        }