protected EventTester(TSender sender, Type senderType, string eventName, Action <object, TEventArgs> action, EventTesterOptions options, bool setBVTflags) { this.eventName = eventName; this.eventData = new List <Tuple <object, TEventArgs> >(); this.sender = sender; this.resetEvent = new AutoResetEvent(false); this.Action = action; this.options = options; if (setBVTflags) { this.options |= EventTesterOptions.BVTEvent; } this.senderType = senderType; var delegateType = GetDelegateType(eventName); Type eventArgType = delegateType.GetTypeInfo().GetDeclaredMethod("Invoke").GetParameters()[1].ParameterType; // Check to ensure that the caller passed in the correct event args. if (typeof(TEventArgs) != eventArgType) { throw new ArgumentException($"The event arg '{typeof(TEventArgs).Name}' does not match the event arg for {typeof(TSender)}.{eventName}. Expected '{eventArgType.Name}"); } // Because we use different Event Handlers for different events (i.e. GotFocus uses RoutedEventHandler while Flyout.Click uses EventHandler<object>), // we need to convert them to a delegate and use the delegate as our handler. Action <object, TEventArgs> handler = this.OnEventFired; MethodInfo handlerInvoke = handler.GetType().GetRuntimeMethod("Invoke", new[] { typeof(object), typeof(TEventArgs) }); this.handlerInvocationDelegate = handlerInvoke.CreateDelegate(delegateType, handler); UIExecutor.Execute(() => { this.AddEvent(); }); if (this.options.HasFlag(EventTesterOptions.CaptureWindowBefore)) { this.CaptureWindowAsync("Before").Wait(this.Timeout); } if (this.options.HasFlag(EventTesterOptions.CaptureScreenBefore)) { this.CaptureScreenAsync("Before").Wait(this.Timeout); } }
public EventTester(TSender sender, string eventName, EventTesterOptions options, bool setBVTflags) : this(sender, sender.GetType(), eventName, (s, e) => { }, options, setBVTflags) { }
protected EventTester(TSender sender, Type senderType, string eventName, Action <object, TEventArgs> action, EventTesterOptions options) : this(sender, senderType, eventName, action, options, true) { }