public void Z_AutomationEventTest()
{
var automationEventsArray = new [] {
new { Sender = (object)null, Args = (AutomationEventArgs)null }
};
var automationEvents = automationEventsArray.ToList();
automationEvents.Clear();
AutomationEventHandler handler =
(o, e) => automationEvents.Add(new { Sender = o, Args = e });
SelectionItemPattern item1 = (SelectionItemPattern)child1Element.GetCurrentPattern(SelectionItemPatternIdentifiers.Pattern);
item1.Select();
AutomationEvent eventId = SelectionItemPattern.ElementSelectedEvent;
At.AddAutomationEventHandler(eventId,
treeView1Element, TreeScope.Descendants, handler);
SelectionItemPattern item2 = (SelectionItemPattern)child2Element.GetCurrentPattern(SelectionItemPatternIdentifiers.Pattern);
item2.Select();
Thread.Sleep(500);
At.RemoveAutomationEventHandler(eventId, treeView1Element, handler);
Assert.AreEqual(1, automationEvents.Count, "event count");
Assert.AreEqual(child2Element, automationEvents [0].Sender, "event sender");
Assert.AreEqual(SelectionItemPattern.ElementSelectedEvent, automationEvents [0].Args.EventId, "EventId");
automationEvents.Clear();
item1.Select();
Thread.Sleep(500);
Assert.AreEqual(0, automationEvents.Count, "event count");
}