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 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); }
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(); }
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); }
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); }
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(); } }
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); }
public void ShowingNonControlThrows() { TestableRootWorkItem workItem = new TestableRootWorkItem(); WindowWorkspace workspace = workItem.Workspaces.AddNew <WindowWorkspace>(); workspace.Show(new object()); }
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 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(); } }
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(); }
//[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>()); }
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); }
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); }
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)); }
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 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); }
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 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); }
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); }
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"); }
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); }
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); }
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); }
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 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); }
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); }
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 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 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); }