public void InvokingCommandCallsMethod() { var cmd = new EventAction(this.subject, null, this.eventInfo.EventHandlerType, "DoSomething", ActionUnavailableBehaviour.Enable, ActionUnavailableBehaviour.Enable); cmd.GetDelegate().DynamicInvoke(null, null); Assert.True(this.target.DoSomethingCalled); }
public void InvokingCommandDoesNothingIfActionIsNonExistent() { var cmd = new EventAction(this.subject, null, this.eventInfo.EventHandlerType, "DoSomething", ActionUnavailableBehaviour.Enable, ActionUnavailableBehaviour.Enable); View.SetActionTarget(this.subject, new Target2()); cmd.GetDelegate().DynamicInvoke(null, null); }
public void UsesExplicitTarget() { var cmd = new EventAction(this.target, this.eventInfo.EventHandlerType, "DoSomething", ActionUnavailableBehaviour.Throw, ActionUnavailableBehaviour.Throw); cmd.GetDelegate().DynamicInvoke(null, null); Assert.True(this.target.DoSomethingCalled); }
public void ExecuteThrowsIfActionTargetIsDefault() { View.SetActionTarget(this.subject, View.InitialActionTarget); var cmd = new EventAction(this.subject, null, this.eventInfo.EventHandlerType, "DoSomething", ActionUnavailableBehaviour.Throw, ActionUnavailableBehaviour.Throw); var e = Assert.Throws <TargetInvocationException>(() => cmd.GetDelegate().DynamicInvoke(null, null)); Assert.IsInstanceOf <ActionNotSetException>(e.InnerException); }
public void PropagatesActionException() { var cmd = new EventAction(this.subject, null, this.eventInfo.EventHandlerType, "DoSomethingUnsuccessfully", ActionUnavailableBehaviour.Enable, ActionUnavailableBehaviour.Enable); var e = Assert.Throws <TargetInvocationException>(() => cmd.GetDelegate().DynamicInvoke(null, null)); Assert.IsInstanceOf <InvalidOperationException>(e.InnerException); Assert.AreEqual("foo", e.InnerException.Message); }
public void InvokingCommandCallsMethodWithDependencyChangedEventArgs() { var cmd = new EventAction(this.subject, null, this.dependencyChangedEventInfo.EventHandlerType, "DoSomethingWithDependencyChangedEventArgs", ActionUnavailableBehaviour.Enable, ActionUnavailableBehaviour.Enable); var arg = new DependencyPropertyChangedEventArgs(); cmd.GetDelegate().DynamicInvoke(null, arg); Assert.AreEqual(arg, this.target.DependencyChangedEventArgs); }
public void ThrowsWhenClickedIfActionNonExistentBehaviourIsThrowAndActionIsNonExistent() { var cmd = new EventAction(this.subject, null, this.eventInfo.EventHandlerType, "DoSomething", ActionUnavailableBehaviour.Enable, ActionUnavailableBehaviour.Throw); Assert.DoesNotThrow(() => View.SetActionTarget(this.subject, new Target2())); var e = Assert.Throws <TargetInvocationException>(() => cmd.GetDelegate().DynamicInvoke(null, new RoutedEventArgs())); Assert.IsInstanceOf <ActionNotFoundException>(e.InnerException); }
public void SupportsStaticTargets() { var cmd = new EventAction(this.subject, null, this.eventInfo.EventHandlerType, "DoSomething", ActionUnavailableBehaviour.Throw, ActionUnavailableBehaviour.Throw); View.SetActionTarget(this.subject, typeof(StaticTarget)); cmd.GetDelegate().DynamicInvoke(null, null); Assert.True(StaticTarget.DidSomething); }
public void InvokingCommandCallsMethodWithSenderAndEventArgs() { var cmd = new EventAction(this.subject, null, this.eventInfo.EventHandlerType, "DoSomethingWithObjectAndEventArgs", ActionUnavailableBehaviour.Enable, ActionUnavailableBehaviour.Enable); var sender = new object(); var arg = new RoutedEventArgs(); cmd.GetDelegate().DynamicInvoke(sender, arg); Assert.AreEqual(sender, this.target.Sender); Assert.AreEqual(arg, this.target.EventArgs); }
public void OperatesAfterCollection() { var view = new DependencyObject(); var cmd = new EventAction(view, null, this.eventInfo.EventHandlerType, "DoSomething", ActionUnavailableBehaviour.Throw, ActionUnavailableBehaviour.Throw); GC.Collect(); View.SetActionTarget(view, this.target); cmd.GetDelegate().DynamicInvoke(null, null); Assert.IsTrue(this.target.DoSomethingCalled); }
public void UsesBackupSubjectIfActionTargetNotAvailable() { var view = new DependencyObject(); var backupView = new DependencyObject(); var cmd = new EventAction(view, backupView, this.eventInfo.EventHandlerType, "DoSomething", ActionUnavailableBehaviour.Throw, ActionUnavailableBehaviour.Throw); View.SetActionTarget(backupView, this.target); view.SetValue(FrameworkElement.DataContextProperty, this.target); cmd.GetDelegate().DynamicInvoke(null, null); Assert.IsTrue(this.target.DoSomethingCalled); }
public void BadEventHandlerSignatureThrows() { var cmd = new EventAction(this.subject, null, typeof(Subject).GetEvent("BadEventHandler").EventHandlerType, "DoSomething", ActionUnavailableBehaviour.Enable, ActionUnavailableBehaviour.Enable); Assert.Throws <ActionEventSignatureInvalidException>(() => cmd.GetDelegate()); }