Ejemplo n.º 1
0
        public void FiresOneEventOnlyIfSmartPartIsShownMultipleTimes()
        {
            TestableRootWorkItem workItem   = new TestableRootWorkItem();
            WindowWorkspace      workspace  = workItem.Workspaces.AddNew <WindowWorkspace>();
            MockWPFSmartPart     smartPartA = workItem.SmartParts.AddNew <MockWPFSmartPart>();
            MockWPFSmartPart     smartPartB = workItem.SmartParts.AddNew <MockWPFSmartPart>();

            workspace.Show(smartPartA);
            workspace.Show(smartPartB);

            int    activatedCalled        = 0;
            object lastActivatedSmartPart = null;

            workspace.SmartPartActivated += delegate(object sender, WorkspaceEventArgs e)
            {
                activatedCalled++;
                lastActivatedSmartPart = e.SmartPart;
            };

            workspace.Show(smartPartA);

            Assert.AreEqual(1, activatedCalled);
            Assert.AreSame(smartPartA, lastActivatedSmartPart);

            workspace.Windows[smartPartA.ElementHost].Close();
            workspace.Windows[smartPartB.ElementHost].Close();
        }
Ejemplo n.º 2
0
        public void ShowTwiceReusesForm()
        {
            TestableRootWorkItem workItem  = new TestableRootWorkItem();
            WindowWorkspace      workspace = workItem.Workspaces.AddNew <WindowWorkspace>();
            MockSmartPart        smartPart = new MockSmartPart();

            workspace.Show(smartPart);
            workspace.Show(smartPart);

            Assert.AreEqual(1, workspace.Windows.Count);
        }
Ejemplo n.º 3
0
        public void ShowTwiceReusesForm()
        {
            TestableRootWorkItem workItem  = new TestableRootWorkItem();
            WindowWorkspace      workspace = workItem.Workspaces.AddNew <WindowWorkspace>();
            MockWPFSmartPart     smartPart = workItem.SmartParts.AddNew <MockWPFSmartPart>();

            workspace.Show(smartPart);
            workspace.Show(smartPart);

            Assert.AreEqual(1, workspace.Windows.Count);

            workspace.Windows[smartPart.ElementHost].Close();
        }
Ejemplo n.º 4
0
        public void ShowExistingFormBringsToFront()
        {
            TestableRootWorkItem workItem   = new TestableRootWorkItem();
            WindowWorkspace      workspace  = workItem.Workspaces.AddNew <WindowWorkspace>();
            MockSmartPart        smartPart  = workItem.SmartParts.AddNew <MockSmartPart>();
            MockSmartPart        smartPart2 = workItem.SmartParts.AddNew <MockSmartPart>();

            workspace.Show(smartPart);
            workspace.Show(smartPart2);
            workspace.Show(smartPart);

            Assert.IsTrue(smartPart.Focused);
        }
Ejemplo n.º 5
0
        public void CanShowSameWindowAfterHidden()
        {
            TestableRootWorkItem workItem  = new TestableRootWorkItem();
            WindowWorkspace      workspace = workItem.Workspaces.AddNew <WindowWorkspace>();
            MockSmartPart        smartPart = workItem.SmartParts.AddNew <MockSmartPart>();

            workspace.Show(smartPart);
            workspace.Hide(smartPart);

            workspace.Show(smartPart);

            Assert.IsNotNull(workspace.Windows[smartPart]);
            Assert.IsTrue(smartPart.Visible);
        }
Ejemplo n.º 6
0
        public void CanShowModalWithOwner()
        {
            TestableRootWorkItem workItem = new TestableRootWorkItem();
            Form            owner         = new Form();
            WindowWorkspace workspace     = new WindowWorkspace(owner);

            workItem.Workspaces.Add(workspace);
            MockSmartPart smartPart = workItem.SmartParts.AddNew <MockSmartPart>();

            WindowSmartPartInfo info = new WindowSmartPartInfo();

            info.Title = "Mock Smart Part";
            info.Modal = true;

            Thread thread = new Thread(new ThreadStart(delegate
            {
                workspace.Show(smartPart, info);
            }));

            try
            {
                thread.Start();
                Thread.Sleep(1000);

                Assert.IsTrue(workspace.Windows[smartPart].Visible);
                Assert.AreSame(owner, workspace.Windows[smartPart].Owner);
            }
            finally
            {
                thread.Abort();
            }
        }
Ejemplo n.º 7
0
        public void CanSetWindowOptions()
        {
            TestableRootWorkItem workItem  = new TestableRootWorkItem();
            WindowWorkspace      workspace = workItem.Workspaces.AddNew <WindowWorkspace>();
            MockSmartPart        smartPart = workItem.SmartParts.AddNew <MockSmartPart>();

            WindowSmartPartInfo info = new WindowSmartPartInfo();

            info.Title       = "Mock Smart Part";
            info.ControlBox  = false;
            info.MinimizeBox = false;
            info.MaximizeBox = false;
            Icon     icon = null;
            Assembly asm  = Assembly.GetExecutingAssembly();

            using (Stream imgStream =
                       asm.GetManifestResourceStream("Microsoft.Practices.CompositeUI.WinForms.Tests.test.ico"))
            {
#pragma warning disable CA1416 // Validate platform compatibility
                icon = new Icon(imgStream);
#pragma warning restore CA1416 // Validate platform compatibility
            }
            info.Icon = icon;

            workspace.Show(smartPart, info);

            Assert.IsFalse(workspace.Windows[smartPart].ControlBox);
            Assert.IsFalse(workspace.Windows[smartPart].MinimizeBox);
            Assert.IsFalse(workspace.Windows[smartPart].MaximizeBox);
            Assert.AreSame(icon, workspace.Windows[smartPart].Icon);
        }
Ejemplo n.º 8
0
        public void ShowingNonControlThrows()
        {
            TestableRootWorkItem workItem  = new TestableRootWorkItem();
            WindowWorkspace      workspace = workItem.Workspaces.AddNew <WindowWorkspace>();

            workspace.Show(new object());
        }
Ejemplo n.º 9
0
        public void CanSetWindowOptions()
        {
            TestableRootWorkItem workItem  = new TestableRootWorkItem();
            WindowWorkspace      workspace = workItem.Workspaces.AddNew <WindowWorkspace>();
            MockWPFSmartPart     smartPart = workItem.SmartParts.AddNew <MockWPFSmartPart>();

            WindowSmartPartInfo info = new WindowSmartPartInfo();

            info.Title       = "Mock Smart Part";
            info.ControlBox  = false;
            info.MinimizeBox = false;
            info.MaximizeBox = false;
            Icon     icon = null;
            Assembly asm  = Assembly.GetExecutingAssembly();

            using (Stream imgStream =
                       asm.GetManifestResourceStream("Microsoft.Practices.CompositeUI.WPF.Tests.test.ico"))
            {
                icon = new Icon(imgStream);
            }
            info.Icon = icon;

            workspace.Show(smartPart, info);

            Assert.IsFalse(workspace.Windows[smartPart.ElementHost].ControlBox);
            Assert.IsFalse(workspace.Windows[smartPart.ElementHost].MinimizeBox);
            Assert.IsFalse(workspace.Windows[smartPart.ElementHost].MaximizeBox);
            Assert.AreSame(icon, workspace.Windows[smartPart.ElementHost].Icon);

            workspace.Windows[smartPart.ElementHost].Close();
        }
Ejemplo n.º 10
0
        public void CanShowModal()
        {
            TestableRootWorkItem workItem  = new TestableRootWorkItem();
            WindowWorkspace      workspace = workItem.Workspaces.AddNew <WindowWorkspace>();
            MockSmartPart        smartPart = workItem.SmartParts.AddNew <MockSmartPart>();

            WindowSmartPartInfo info = new WindowSmartPartInfo();

            info.Title = "Mock Smart Part";
            info.Modal = true;

            Thread thread = new Thread(new ThreadStart(delegate
            {
                workspace.Show(smartPart, info);
            }));

            try
            {
                thread.Start();
                Thread.Sleep(1000);

                Assert.IsTrue(workspace.Windows[smartPart].Visible);
            }
            finally
            {
                thread.Interrupt();
            }
        }
Ejemplo n.º 11
0
        public void CanShowSameWindowAfterHidden()
        {
            TestableRootWorkItem workItem  = new TestableRootWorkItem();
            WindowWorkspace      workspace = workItem.Workspaces.AddNew <WindowWorkspace>();
            MockWPFSmartPart     smartPart = workItem.SmartParts.AddNew <MockWPFSmartPart>();

            workspace.Show(smartPart);
            workspace.Hide(smartPart);

            workspace.Show(smartPart);

            Assert.IsNotNull(workspace.Windows[smartPart.ElementHost]);
            //Assert.IsTrue(smartPart.Visible);
            Assert.AreNotEqual(System.Windows.Visibility.Hidden, smartPart.Visibility);

            workspace.Windows[smartPart.ElementHost].Close();
        }
Ejemplo n.º 12
0
        //[ExpectedException(typeof(ArgumentException))]
        public void ShowingNonControlThrows()
        {
            TestableRootWorkItem workItem  = new TestableRootWorkItem();
            WindowWorkspace      workspace = workItem.Workspaces.AddNew <WindowWorkspace>();

            //workspace.Show(new object());
            Assert.That(() => workspace.Show(new object()),
                        Throws.TypeOf <ArgumentException>());
        }
Ejemplo n.º 13
0
        public void WindowActivatedFiresCorrectNumberOfTimes()
        {
            TestableRootWorkItem workItem  = new TestableRootWorkItem();
            WindowWorkspace      workspace = workItem.Workspaces.AddNew <WindowWorkspace>();
            MockSmartPart        smartPart = workItem.SmartParts.AddNew <MockSmartPart>();

            int           activated  = 0;
            MockSmartPart smartPart2 = workItem.SmartParts.AddNew <MockSmartPart>();

            workspace.SmartPartActivated +=
                delegate(object sender, WorkspaceEventArgs args) { activated++; };

            workspace.Show(smartPart2);
            workspace.Show(smartPart);
            workspace.Windows[smartPart2].Focus();

            Assert.AreEqual(3, activated);
        }
Ejemplo n.º 14
0
        public void SettingFocusOnWindowFiresActivated()
        {
            TestableRootWorkItem workItem  = new TestableRootWorkItem();
            WindowWorkspace      workspace = workItem.Workspaces.AddNew <WindowWorkspace>();
            MockSmartPart        smartPart = workItem.SmartParts.AddNew <MockSmartPart>();

            object        argsSmartPart = null;
            MockSmartPart smartPart2    = workItem.SmartParts.AddNew <MockSmartPart>();

            workspace.Show(smartPart2);
            workspace.Show(smartPart);

            workspace.SmartPartActivated +=
                delegate(object sender, WorkspaceEventArgs args) { argsSmartPart = args.SmartPart; };

            workspace.Windows[smartPart2].Focus();

            Assert.AreEqual(smartPart2, argsSmartPart);
        }
Ejemplo n.º 15
0
        public void CloseRemovesWindow()
        {
            TestableRootWorkItem workItem  = new TestableRootWorkItem();
            WindowWorkspace      workspace = workItem.Workspaces.AddNew <WindowWorkspace>();
            MockWPFSmartPart     smartPart = workItem.SmartParts.AddNew <MockWPFSmartPart>();

            workspace.Show(smartPart);
            workspace.Close(smartPart);

            Assert.IsFalse(workspace.Windows.ContainsKey(smartPart.ElementHost));
        }
Ejemplo n.º 16
0
        public void CloseSmartPartDoesNotDisposeIt()
        {
            TestableRootWorkItem workItem  = new TestableRootWorkItem();
            WindowWorkspace      workspace = workItem.Workspaces.AddNew <WindowWorkspace>();
            MockWPFSmartPart     smartPart = workItem.SmartParts.AddNew <MockWPFSmartPart>();

            workspace.Show(smartPart);
            workspace.Close(smartPart);

            Assert.IsFalse(smartPart.IsDisposed);
        }
Ejemplo n.º 17
0
        public void CanShowIfSPINotWindowSPI()
        {
            TestableRootWorkItem workItem  = new TestableRootWorkItem();
            WindowWorkspace      workspace = workItem.Workspaces.AddNew <WindowWorkspace>();
            MockSmartPart        smartPart = workItem.SmartParts.AddNew <MockSmartPart>();

            WPFSmartPartInfo info = new WPFSmartPartInfo();

            info.Title = "Foo";

            workspace.Show(smartPart, info);
        }
Ejemplo n.º 18
0
        public void CloseRemovesEntriesInWindowsAndSmartParts()
        {
            TestableRootWorkItem workItem  = new TestableRootWorkItem();
            WindowWorkspace      workspace = workItem.Workspaces.AddNew <WindowWorkspace>();
            MockWPFSmartPart     smartPart = workItem.SmartParts.AddNew <MockWPFSmartPart>();

            workspace.Show(smartPart);

            workspace.Close(smartPart);

            Assert.AreEqual(0, workspace.Windows.Count);
        }
Ejemplo n.º 19
0
        public void FormSizeIsCorrectSize()
        {
            TestableRootWorkItem workItem  = new TestableRootWorkItem();
            WindowWorkspace      workspace = workItem.Workspaces.AddNew <WindowWorkspace>();
            MockSmartPart        smartPart = workItem.SmartParts.AddNew <MockSmartPart>();

            smartPart.Size = new System.Drawing.Size(150, 125);

            workspace.Show(smartPart);

            Assert.AreEqual(150, workspace.Windows[smartPart].Size.Width);
            Assert.AreEqual(145, workspace.Windows[smartPart].Size.Height);
        }
Ejemplo n.º 20
0
        public void FiresOneEventOnlyIfSmartPartIsShownMultipleTimes()
        {
            TestableRootWorkItem workItem   = new TestableRootWorkItem();
            WindowWorkspace      workspace  = workItem.Workspaces.AddNew <WindowWorkspace>();
            MockSmartPart        smartPartA = new MockSmartPart();
            MockSmartPart        smartPartB = new MockSmartPart();

            workspace.Show(smartPartA);
            workspace.Show(smartPartB);

            int activatedCalled = 0;

            workspace.SmartPartActivated += delegate(object sender, WorkspaceEventArgs e)
            {
                activatedCalled++;
                Assert.AreSame(e.SmartPart, smartPartA);
            };

            workspace.Show(smartPartA);

            Assert.AreEqual(1, activatedCalled);
        }
Ejemplo n.º 21
0
        public void CanCancelSmartPartClosing()
        {
            TestableRootWorkItem workItem  = new TestableRootWorkItem();
            WindowWorkspace      workspace = workItem.Workspaces.AddNew <WindowWorkspace>();
            MockSmartPart        smartPart = workItem.SmartParts.AddNew <MockSmartPart>();

            workspace.Show(smartPart);
            workspace.SmartPartClosing += delegate(object sender, WorkspaceCancelEventArgs args) { args.Cancel = true; };

            workspace.Close(smartPart);

            Assert.IsFalse(smartPart.IsDisposed, "Smart Part Was Disposed");
        }
Ejemplo n.º 22
0
        public void CanHideWithSmartPart()
        {
            TestableRootWorkItem workItem  = new TestableRootWorkItem();
            WindowWorkspace      workspace = workItem.Workspaces.AddNew <WindowWorkspace>();
            MockSmartPart        smartPart = workItem.SmartParts.AddNew <MockSmartPart>();

            workspace.Show(smartPart);

            workspace.Hide(smartPart);

            Assert.IsFalse(workspace.Windows[smartPart].Visible);
            Assert.IsFalse(smartPart.Visible);
        }
Ejemplo n.º 23
0
        public void ShowSetsVisible()
        {
            TestableRootWorkItem workItem  = new TestableRootWorkItem();
            WindowWorkspace      workspace = workItem.Workspaces.AddNew <WindowWorkspace>();

            MockSmartPart smartPart = new MockSmartPart();

            smartPart.Visible = false;

            workspace.Show(smartPart);

            Assert.IsTrue(smartPart.Visible);
        }
Ejemplo n.º 24
0
        public void ShowingFiresActivatedEvent()
        {
            TestableRootWorkItem workItem  = new TestableRootWorkItem();
            WindowWorkspace      workspace = workItem.Workspaces.AddNew <WindowWorkspace>();
            MockSmartPart        smartPart = workItem.SmartParts.AddNew <MockSmartPart>();

            bool activated = false;

            workspace.SmartPartActivated += delegate { activated = true; };
            workspace.Show(smartPart);

            Assert.IsTrue(activated);
        }
Ejemplo n.º 25
0
        public void CanCancelCloseWhenFormClose()
        {
            TestableRootWorkItem workItem  = new TestableRootWorkItem();
            WindowWorkspace      workspace = workItem.Workspaces.AddNew <WindowWorkspace>();
            MockWPFSmartPart     smartPart = workItem.SmartParts.AddNew <MockWPFSmartPart>();

            workspace.Show(smartPart);
            workspace.SmartPartClosing += delegate(object sender, WorkspaceCancelEventArgs args) { args.Cancel = true; };

            workspace.Windows[smartPart.ElementHost].Close();

            Assert.IsFalse(smartPart.IsDisposed);
        }
Ejemplo n.º 26
0
        public void HidingSmartPartDoesNotAutomaticallyShowPreviousForm()
        {
            TestableRootWorkItem workItem   = new TestableRootWorkItem();
            WindowWorkspace      workspace  = workItem.Workspaces.AddNew <WindowWorkspace>();
            MockWPFSmartPart     smartPartA = workItem.SmartParts.AddNew <MockWPFSmartPart>();

            smartPartA.Visibility = System.Windows.Visibility.Hidden;
            MockWPFSmartPart smartPartB = workItem.SmartParts.AddNew <MockWPFSmartPart>();

            smartPartB.Visibility = System.Windows.Visibility.Hidden;

            WindowSmartPartInfo smartPartInfoB = new WindowSmartPartInfo();

            smartPartInfoB.Title = "Window SmartPart B";

            WindowSmartPartInfo smartPartInfoA = new WindowSmartPartInfo();

            smartPartInfoA.Title = "Window SmartPart A";

            workspace.Show(smartPartA, smartPartInfoA);
            //Assert.IsTrue(smartPartA.Visible);
            Assert.AreNotEqual(System.Windows.Visibility.Hidden, smartPartA.Visibility);

            // Force the form to non-visible so it doesn't fire
            // his own Activated event after we hide the following
            // smart part, therefore making the condition impossible
            // to test.

            workspace.Windows[smartPartA.ElementHost].Hide();

            workspace.Show(smartPartB, smartPartInfoB);
            //Assert.IsTrue(smartPartB.Visible);
            Assert.AreNotEqual(System.Windows.Visibility.Hidden, smartPartB.Visibility);

            workspace.Hide(smartPartB);

            Assert.IsNull(workspace.ActiveSmartPart);
        }
Ejemplo n.º 27
0
        public void ShowingSetFormTextFromWindowSmartPartInfo()
        {
            TestableRootWorkItem workItem  = new TestableRootWorkItem();
            WindowWorkspace      workspace = workItem.Workspaces.AddNew <WindowWorkspace>();
            MockSmartPart        smartPart = workItem.SmartParts.AddNew <MockSmartPart>();

            WindowSmartPartInfo info = new WindowSmartPartInfo();

            info.Title = "Mock Smart Part";
            workItem.RegisterSmartPartInfo(smartPart, info);
            workspace.Show(smartPart, info);

            Assert.AreEqual("Mock Smart Part", workspace.Windows[smartPart].Text);
        }
Ejemplo n.º 28
0
        public void FormSizeIsCorrectSize()
        {
            TestableRootWorkItem workItem  = new TestableRootWorkItem();
            WindowWorkspace      workspace = workItem.Workspaces.AddNew <WindowWorkspace>();
            MockWPFSmartPart     smartPart = workItem.SmartParts.AddNew <MockWPFSmartPart>();

            smartPart.Width  = 150;
            smartPart.Height = 125;

            workspace.Show(smartPart);

            Assert.AreEqual(150, workspace.Windows[smartPart.ElementHost].Size.Width);
            Assert.AreEqual(145, workspace.Windows[smartPart.ElementHost].Size.Height);
        }
Ejemplo n.º 29
0
        public void ControlIsRemovedWhenSmartPartIsDisposed()
        {
            TestableRootWorkItem workItem  = new TestableRootWorkItem();
            WindowWorkspace      workspace = workItem.Workspaces.AddNew <WindowWorkspace>();
            MockWPFSmartPart     smartPart = workItem.SmartParts.AddNew <MockWPFSmartPart>();

            workspace.Show(smartPart);
            Assert.AreEqual(1, workspace.Windows.Count);

            smartPart.Dispose();

            Assert.AreEqual(0, workspace.Windows.Count);
            Assert.AreEqual(0, workspace.SmartParts.Count);
        }
Ejemplo n.º 30
0
        public void ShowShowsNewFormWithControl()
        {
            TestableRootWorkItem workItem  = new TestableRootWorkItem();
            WindowWorkspace      workspace = workItem.Workspaces.AddNew <WindowWorkspace>();
            MockSmartPart        smartPart = workItem.SmartParts.AddNew <MockSmartPart>();

            workspace.Show(smartPart);

            Form form = workspace.Windows[smartPart];

            Assert.AreSame(smartPart, form.Controls[0]);
            Assert.IsTrue(workspace.Windows[smartPart].Visible);
            Assert.IsTrue(smartPart.Visible);
        }