Esempio n. 1
0
        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);
        }
Esempio n. 2
0
        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);
        }
Esempio n. 3
0
        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);
        }
Esempio n. 4
0
        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);
        }
Esempio n. 5
0
        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);
        }
Esempio n. 6
0
        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);
        }
Esempio n. 7
0
        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);
        }
Esempio n. 8
0
        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);
        }
Esempio n. 9
0
        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);
        }
Esempio n. 10
0
        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);
        }
Esempio n. 11
0
        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);
        }
Esempio n. 12
0
        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());
        }