public void CloseTabPageAddedAtDesignTime()
        {
            // Create new instance to simulate design-time creation.
            workspace = new TabWorkspace();
            workItem.Items.Add(workspace);
            MockWPFSmartPart sp1 = new MockWPFSmartPart();

            workItem.Items.Add(sp1);

            TabPage page = new TabPage();
            IWPFUIElementAdapter catalog = workItem.Services.Get <IWPFUIElementAdapter>();
            Control wrapper = catalog.Wrap(sp1);

            page.Controls.Add(wrapper);
            page.Name = Guid.NewGuid().ToString();
            workspace.TabPages.Add(page);

            owner = new Form();
            owner.Controls.Add(workspace);
            owner.Show();

            workspace.Close(sp1);

            Assert.AreEqual(0, workspace.TabPages.Count);
        }
        public void AddingSmartPartAtBeginningFiresOneActivatedEvent()
        {
            MockWPFSmartPart smartPartA = new MockWPFSmartPart();
            MockWPFSmartPart smartPartB = new MockWPFSmartPart();

            TabSmartPartInfo smartPartInfoA = new TabSmartPartInfo();

            smartPartInfoA.Title    = "Smart Part A";
            smartPartInfoA.Position = TabPosition.Beginning;

            TabSmartPartInfo smartPartInfoB = new TabSmartPartInfo();

            smartPartInfoB.Title = "Smart Part B";

            workspace.Show(smartPartB, smartPartInfoB);

            int activatedCalled = 0;

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

            workspace.Show(smartPartA, smartPartInfoA);

            Assert.AreEqual(1, activatedCalled);
        }
        public void SelectingTabFiresSmartPartActivatedEvent()
        {
            int              activated  = 0;
            WorkItem         wi         = workItem.Items.AddNew <WorkItem>();
            MockWPFSmartPart smartPart1 = new MockWPFSmartPart();

            smartPart1.Name = "SP1";
            MockWPFSmartPart smartPart2 = new MockWPFSmartPart();

            smartPart1.Name = "SP2";
            wi.Items.Add(smartPart1);
            wi.Items.Add(smartPart2);

            Form form = new Form();

            form.Controls.Add(workspace);
            workspace.Dock = DockStyle.Fill;
            form.Show();

            workspace.Show(smartPart1);
            workspace.Show(smartPart2);

            workspace.SmartPartActivated += delegate { activated++; };
            workspace.SelectedIndex       = 0;

            Assert.AreEqual(1, activated);
        }
        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();
        }
        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();
        }
        public void RemovingSelectedTabFiresSelection()
        {
            int              activated = 0;
            WorkItem         cc        = workItem.Items.AddNew <WorkItem>();
            MockWPFSmartPart smartPart = new MockWPFSmartPart();

            smartPart.Name = "SP";
            MockWPFSmartPart smartPart2 = new MockWPFSmartPart();

            smartPart2.Name = "SP2";
            cc.Items.Add(smartPart);
            cc.Items.Add(smartPart2);

            Form form = new Form();

            form.Controls.Add(workspace);
            workspace.Dock = DockStyle.Fill;
            form.Show();

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

            workspace.SmartPartActivated += delegate { activated++; };
            workspace.Close(smartPart2);

            Assert.AreEqual(1, activated);
        }
        public void SPIsRemovedFromWorkspaceWhenDisposed1()
        {
            MockWPFSmartPart smartPartA = new MockWPFSmartPart();

            TabSmartPartInfo spInfoA = new TabSmartPartInfo();

            spInfoA.Title = "Smart Part A";

            workItem.SmartParts.Add(smartPartA);

            workspace.Show(smartPartA, spInfoA);

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

            //smartPartA.Dispose();
            IWPFUIElementAdapter catalog = workItem.Services.Get <IWPFUIElementAdapter>();
            Control wrapper = catalog.Wrap(smartPartA);

            wrapper.Dispose();

            Assert.AreEqual(0, workspace.TabPages.Count);

            // Returns 1
            Assert.AreEqual(0, workspace.SmartParts.Count);
        }
Exemplo n.º 8
0
        public void UIElementCannotBeWrappedAfterDisposal()
        {
            MockWPFSmartPart smartPart = new MockWPFSmartPart();

            Wf.Control wrapper = catalog.Wrap(smartPart);
            smartPart.Dispose();
            Wf.Control wrapper2 = catalog.Wrap(smartPart);
        }
        public void CloseNonExistControlThrows()
        {
            TestableRootWorkItem workItem  = new TestableRootWorkItem();
            WindowWorkspace      workspace = workItem.Workspaces.AddNew <WindowWorkspace>();
            MockWPFSmartPart     smartPart = workItem.SmartParts.AddNew <MockWPFSmartPart>();

            workspace.Close(smartPart);
        }
Exemplo n.º 10
0
        //[ExpectedException(typeof(ArgumentException))]
        public void CloseNonExistControlThrows()
        {
            TestableRootWorkItem workItem  = new TestableRootWorkItem();
            WindowWorkspace      workspace = workItem.Workspaces.AddNew <WindowWorkspace>();
            MockWPFSmartPart     smartPart = workItem.SmartParts.AddNew <MockWPFSmartPart>();

            //workspace.Close(smartPart);
            Assert.That(() => workspace.Close(smartPart),
                        Throws.TypeOf <ArgumentException>());
        }
Exemplo n.º 11
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));
        }
Exemplo n.º 12
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);
        }
        public void SetUp()
        {
            workItem  = new TestableRootWorkItem();
            workspace = new TabWorkspace();
            workItem.Workspaces.Add(workspace);
            workItem.Services.Add(typeof(IWorkItemActivationService), new SimpleWorkItemActivationService());
            sp = new MockWPFSmartPart();

            owner = new Form();
            owner.Controls.Add(workspace);
            owner.Show();
        }
        public void HideActivatesPreviousSmartPartIfThereIsOne()
        {
            MockWPFSmartPart smartPartA = workItem.SmartParts.AddNew <MockWPFSmartPart>();
            MockWPFSmartPart smartPartB = workItem.SmartParts.AddNew <MockWPFSmartPart>();

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

            workspace.Hide(smartPartB);

            Assert.AreSame(workspace.ActiveSmartPart, smartPartA);
        }
        public void CloseTabPage()
        {
            MockWPFSmartPart sampleSmartPart = new MockWPFSmartPart();

            workItem.Items.Add(sampleSmartPart, "SampleSmartPart");
            workItem.Items.Add(workspace);
            workspace.Show(sampleSmartPart);

            workspace.Close(sampleSmartPart);

            Assert.AreEqual(0, workspace.TabPages.Count);
        }
Exemplo n.º 16
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);
        }
        public void ShowTabWithNewInfo()
        {
            MockWPFSmartPart part = new MockWPFSmartPart();

            workItem.Items.Add(part);
            TabSmartPartInfo info = new TabSmartPartInfo();

            info.Title = "Updated";

            workspace.Show(part, info);

            Assert.AreEqual("Updated", workspace.SelectedTab.Text);
        }
        public void CanCancelSmartPartClosing()
        {
            MockWPFSmartPart smartPart = new MockWPFSmartPart();

            smartPart.Name = "SP";
            workItem.Items.Add(smartPart);
            workspace.Show(smartPart);
            workspace.SmartPartClosing += delegate(object sender, WorkspaceCancelEventArgs args) { args.Cancel = true; };

            workspace.Close(smartPart);

            Assert.IsFalse(smartPart.IsDisposed);
        }
        public void CreatingTabWithDefaultSPIFiresSmartPartActivedEvent()
        {
            bool             activated = false;
            MockWPFSmartPart smartPart = new MockWPFSmartPart();

            smartPart.Name = "SP";
            workItem.Items.Add(smartPart);
            workspace.SmartPartActivated += delegate { activated = true; };

            workspace.Show(smartPart);

            Assert.IsTrue(activated);
        }
Exemplo n.º 20
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);
        }
        public void HideActivatesFollowingSiblingIfItIsFirstOne()
        {
            MockWPFSmartPart smartPartA = workItem.SmartParts.AddNew <MockWPFSmartPart>();
            MockWPFSmartPart smartPartB = workItem.SmartParts.AddNew <MockWPFSmartPart>();

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

            workspace.Hide(smartPartA);

            Assert.AreSame(workspace.ActiveSmartPart, smartPartB);
        }
Exemplo n.º 22
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();
        }
Exemplo n.º 23
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);
        }
        public void CanRetrieveSmartPartFromEventArgs()
        {
            object           smartPartObject1 = null;
            MockWPFSmartPart smartPart        = new MockWPFSmartPart();

            smartPart.Name = "SP";
            workItem.Items.Add(smartPart);
            workspace.Show(smartPart);
            workspace.SmartPartClosing += delegate(object sender, WorkspaceCancelEventArgs args) { smartPartObject1 = args.SmartPart; };

            workspace.Close(smartPart);

            Assert.AreEqual(smartPart, smartPartObject1);
        }
Exemplo n.º 25
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);
        }
        public void SmartPartActivatePassesCorrectEventArgs()
        {
            object           argsSmartPart = null;
            MockWPFSmartPart smartPart     = new MockWPFSmartPart();

            smartPart.Name = "SP";
            workItem.Items.Add(smartPart);
            workspace.SmartPartActivated +=
                delegate(object sender, WorkspaceEventArgs args) { argsSmartPart = args.SmartPart; };

            workspace.Show(smartPart);

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

            WPFSmartPartInfo info = new WPFSmartPartInfo();

            info.Title = "Foo";

            workspace.Show(smartPart, info);

            workspace.Windows[smartPart.ElementHost].Close();
        }
        public void WorkspaceFiresSmartPartClosing()
        {
            bool             closing   = false;
            MockWPFSmartPart smartPart = new MockWPFSmartPart();

            smartPart.Name = "SP";
            workItem.Items.Add(smartPart);
            workspace.Show(smartPart);
            workspace.SmartPartClosing += delegate { closing = true; };

            workspace.Close(smartPart);

            Assert.IsTrue(closing);
        }
Exemplo n.º 29
0
        public void ClosedDoesNotFireIfNoControlsOnForm()
        {
            TestableRootWorkItem workItem  = new TestableRootWorkItem();
            WindowWorkspace      workspace = workItem.Workspaces.AddNew <WindowWorkspace>();
            MockWPFSmartPart     smartPart = workItem.SmartParts.AddNew <MockWPFSmartPart>();

            bool closing = false;

            workspace.Show(smartPart);
            workspace.SmartPartClosing += delegate { closing = true; };

            workspace.Windows[smartPart.ElementHost].Controls.Clear();

            Assert.IsFalse(closing);
        }
Exemplo n.º 30
0
        public void ClosedIsCalledWhenClosed()
        {
            TestableRootWorkItem workItem  = new TestableRootWorkItem();
            WindowWorkspace      workspace = workItem.Workspaces.AddNew <WindowWorkspace>();
            MockWPFSmartPart     smartPart = workItem.SmartParts.AddNew <MockWPFSmartPart>();

            bool closed = false;

            workspace.Show(smartPart);
            workspace.SmartPartClosing += delegate { closed = true; };

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

            Assert.IsTrue(closed);
        }