Пример #1
0
        public void TestCreateInstanceCore()
        {
            StubBehavior action = new StubBehavior();

            SysWindows.Freezable freezable = action.GetCreateInstanceCore();
            Assert.AreEqual(freezable.GetType(), typeof(StubBehavior), "freezable.GetType() == typeof(StubBehavior)");
        }
        public void Invoke_LegalCommandName_InvokesCommand()
        {
            InvokeCommandAction invokeCommandAction = CreateInvokeCommandActionWithCommandName("StubCommand");
            StubBehavior        stubBehavior        = CreateStubBehavior();
            StubTrigger         trigger             = AttachActionToObject(invokeCommandAction, stubBehavior);

            trigger.FireStubTrigger();
            Assert.AreEqual(stubBehavior.ExecutionCount, 1, "stubBehavior.ExecutionCount == 1");
        }
        public void Invoke_ActionWithCommandParameter_UsesParameterCorrectly()
        {
            Rectangle           triggerParameter    = CreateRectangle();
            Button              behaviorParameter   = CreateButton();
            InvokeCommandAction invokeCommandAction = CreateInvokeCommandActionWithCommandNameAndParameter("StubCommandWithParameter", behaviorParameter);
            StubBehavior        stubBehavior        = CreateStubBehavior();
            StubTrigger         trigger             = AttachActionToObject(invokeCommandAction, stubBehavior);

            trigger.FireStubTrigger(triggerParameter);
            Assert.AreEqual(stubBehavior.LastParameter, behaviorParameter, "stubBehavior.LastParameter == button");
        }
Пример #4
0
        public void AttachDetachTest()
        {
            StubBehavior stubBehavior = new StubBehavior();

            BehaviorTestUtilities.TestIAttachedObject <Button>((IAttachedObject)stubBehavior);

            Rectangle          rectangle          = new Rectangle();
            StubBehavior       behavior           = new StubBehavior();
            BehaviorCollection behaviorCollection = Interaction.GetBehaviors(rectangle);

            behaviorCollection.Add(behavior);
            behaviorCollection.Detach();
            BehaviorTestUtilities.TestIAttachedObject <Button>((IAttachedObject)behaviorCollection);
        }
Пример #5
0
        public void Invoke_ActionWithPassEventArgsToCommandFalse_DoesNotPassEventArgsToCommand()
        {
            StubBehavior stubBehavior = CreateStubBehavior();

            InvokeCommandAction invokeCommandAction = CreateInvokeCommandAction();

            invokeCommandAction.Command = stubBehavior.StubCommandWithParameter;
            invokeCommandAction.PassEventArgsToCommand = false;

            StubTrigger trigger = AttachActionToObject(invokeCommandAction, stubBehavior);

            var args = new EventArgsMock();

            trigger.FireStubTrigger(args);

            Assert.IsNull(stubBehavior.LastParameter);
        }
Пример #6
0
        public void AttachBehaviorsTest()
        {
            StubBehavior behavior1 = new StubBehavior();
            StubBehavior behavior2 = new StubBehavior();

            Button button1 = new Button();

            BehaviorCollection behaviors1 = Interaction.GetBehaviors(button1);

            Assert.AreEqual(behaviors1.Count, 0, "behaviors.Count == 0");
            behaviors1.Add(behavior1);
            Assert.AreEqual(behaviors1.Count, 1, "behaviors.Count == 1");
            Assert.AreEqual(behavior1.AttachedObject, button1, "behavior1.AssociatedObject == button");
            behaviors1.Add(behavior2);
            Assert.AreEqual(behaviors1.Count, 2, "behaviors.Count == 2");
            Assert.AreEqual(behavior2.AttachedObject, button1, "behavior2.AssociatedObject == button");
        }
Пример #7
0
        public void Invoke_ActionWithPassEventArgsToCommandTrue_PassesEventArgsToCommand()
        {
            StubBehavior stubBehavior = CreateStubBehavior();

            InvokeCommandAction invokeCommandAction = CreateInvokeCommandAction();

            invokeCommandAction.Command = stubBehavior.StubCommandWithParameter;
            invokeCommandAction.PassEventArgsToCommand = true;

            StubTrigger trigger = AttachActionToObject(invokeCommandAction, stubBehavior);

            var args = new EventArgsMock();

            trigger.FireStubTrigger(args);

            Assert.IsNotNull(stubBehavior.LastParameter);
            Assert.IsInstanceOfType(stubBehavior.LastParameter, typeof(EventArgsMock));
        }
Пример #8
0
        public void Invoke_ActionWithEventArgsConverter_PassesConvertedValueToCommand()
        {
            StubBehavior stubBehavior = CreateStubBehavior();

            InvokeCommandAction invokeCommandAction = CreateInvokeCommandAction();

            invokeCommandAction.Command            = stubBehavior.StubCommandWithParameter;
            invokeCommandAction.EventArgsConverter = new EventArgsMockConverter();

            StubTrigger trigger = AttachActionToObject(invokeCommandAction, stubBehavior);

            var args = new EventArgsMock();

            trigger.FireStubTrigger(args);

            Assert.IsNotNull(stubBehavior.LastParameter);
            Assert.AreEqual("convertedValue", stubBehavior.LastParameter);
        }
Пример #9
0
        public void Invoke_ActionWithEventArgsParameterPath_PassesNestedEventArgsValueToCommand()
        {
            StubBehavior stubBehavior = CreateStubBehavior();

            InvokeCommandAction invokeCommandAction = CreateInvokeCommandAction();

            invokeCommandAction.Command = stubBehavior.StubCommandWithParameter;
            invokeCommandAction.EventArgsParameterPath = "Poco.Child.Name";

            StubTrigger trigger = AttachActionToObject(invokeCommandAction, stubBehavior);

            var args = new EventArgsMock("value");

            trigger.FireStubTrigger(args);

            Assert.IsNotNull(stubBehavior.LastParameter);
            Assert.AreEqual("value", stubBehavior.LastParameter);
        }
Пример #10
0
        public void AttachBehaviorMultipleElements_ShouldThrow()
        {
            StubBehavior behavior = new StubBehavior();

            Button             button1    = new Button();
            BehaviorCollection behaviors1 = Interaction.GetBehaviors(button1);

            Button             button2    = new Button();
            BehaviorCollection behaviors2 = Interaction.GetBehaviors(button2);

            behaviors1.Add(behavior);

            try
            {
                behaviors2.Add(behavior);
                Assert.Fail("InvalidOperationexception should be thrown if same behavior is attached to two elements");
            }
            catch (InvalidOperationException)
            {
            }
        }
        private static StubBehavior CreateStubBehavior()
        {
            StubBehavior stubBehavior = new StubBehavior();

            return(stubBehavior);
        }