public void CloseTest() { using (Form f = new Form()) { IRawElementProviderFragment provider = (IRawElementProviderFragment)ProviderFactory.GetProvider(f); IWindowProvider pattern = (IWindowProvider)provider.GetPatternProvider(WindowPatternIdentifiers.Pattern.Id); f.Show(); Thread.Sleep(500); Assert.AreEqual(WindowInteractionState.ReadyForUserInteraction, pattern.InteractionState, "Interaction state while running normally"); var dialog = new Form(); WindowInteractionState interactionState = (WindowInteractionState)(-1); dialog.Activated += delegate { interactionState = pattern.InteractionState; Thread.Sleep(1000); dialog.Close(); }; dialog.ShowDialog(); Assert.AreEqual(WindowInteractionState.BlockedByModalWindow, interactionState, "Interaction state while blocked by modal dialog"); bool formClosed = false; bool formClosingChecked = false; f.Closed += delegate(Object sender, EventArgs e) { formClosed = true; }; f.Closing += delegate(Object sender, CancelEventArgs e) { Assert.AreEqual(WindowInteractionState.Closing, pattern.InteractionState, "Interaction state while closing"); formClosingChecked = true; }; bridge.ResetEventLists(); pattern.Close(); Assert.IsTrue(formClosed, "Form closed event didn't fire."); Assert.IsTrue(formClosingChecked, "Interaction state while closing never confirmed."); Assert.AreEqual(1, bridge.StructureChangedEvents.Count, "event count"); Assert.AreSame(provider, bridge.StructureChangedEvents [0].provider, "event provider"); Assert.AreEqual(StructureChangeType.ChildRemoved, bridge.StructureChangedEvents [0].e.StructureChangeType, "event change type"); Application.DoEvents(); } }
public void Close() { provider.Close(); }