Exemple #1
0
        public void TestCreateInstanceCore()
        {
            StubTrigger action = new StubTrigger();

            WindowsBase.Freezable freezable = action.GetCreateInstanceCore();
            Assert.AreEqual(freezable.GetType(), typeof(StubTrigger), "freezable.GetType() == typeof(StubTrigger)");
        }
        public void Invoke_NotAttached_IsNoOp()
        {
            StubTrigger          trigger = CreateStubTrigger();
            ChangePropertyAction action  = CreateChangePropertyAction("Foo", Brushes.Green);

            trigger.FireStubTrigger();
        }
        public void InvokeTriggerWithConditionalBehavior_TwoConditionsBothNotMetForwardChainingOr()
        {
            ConditionalExpression conditionalExpression = null;
            StubTrigger           trigger = null;
            StubAction            action  = null;

            SetupTriggerActionConditionBehavior(out conditionalExpression, out trigger, out action);

            // Resetting an non met condition
            conditionalExpression.Conditions.Add(new ComparisonCondition());
            conditionalExpression.Conditions[0].LeftOperand  = BehaviorTestUtilities.IntegerOperand4;
            conditionalExpression.Conditions[0].RightOperand = BehaviorTestUtilities.IntegerOperand5;
            conditionalExpression.Conditions[0].Operator     = ComparisonConditionType.GreaterThan;

            // Add the second condition
            conditionalExpression.Conditions.Add(new ComparisonCondition());
            Assert.IsTrue(conditionalExpression.Conditions.Count == 2, "We should have 2 conditions");

            // Creating a new condition
            conditionalExpression.Conditions[1].LeftOperand  = BehaviorTestUtilities.IntegerOperand5;
            conditionalExpression.Conditions[1].RightOperand = BehaviorTestUtilities.IntegerOperand6;
            conditionalExpression.Conditions[1].Operator     = ComparisonConditionType.GreaterThan;

            // Firing the trigger, forward chaining changed to OR.
            conditionalExpression.ForwardChaining = ForwardChaining.Or;
            trigger.FireStubTrigger();
            Assert.AreEqual(action.InvokeCount, 0, "action.InvokeCount == 0, both conditons are not met, forward chaining was Or");
        }
        public void InvokeTriggerWithConditionalBehavior_TwoConditionsOneNotMet()
        {
            ConditionalExpression conditionalExpression = null;
            StubTrigger           trigger = null;
            StubAction            action  = null;

            SetupTriggerActionConditionBehavior(out conditionalExpression, out trigger, out action);

            // Resetting an non met condition
            conditionalExpression.Conditions.Add(new ComparisonCondition());
            conditionalExpression.Conditions[0].LeftOperand  = BehaviorTestUtilities.IntegerOperand4;
            conditionalExpression.Conditions[0].RightOperand = BehaviorTestUtilities.IntegerOperand5;
            conditionalExpression.Conditions[0].Operator     = ComparisonConditionType.GreaterThan;

            // Add the second condition
            conditionalExpression.Conditions.Add(new ComparisonCondition());
            Assert.IsTrue(conditionalExpression.Conditions.Count == 2, "We should have 2 conditions");

            // Creating a new condition
            conditionalExpression.Conditions[1].LeftOperand  = BehaviorTestUtilities.IntegerOperand5;
            conditionalExpression.Conditions[1].RightOperand = BehaviorTestUtilities.IntegerOperand6;
            conditionalExpression.Conditions[1].Operator     = ComparisonConditionType.LessThan;


            // Firing the trigger, with one of the condition not met
            trigger.FireStubTrigger();
            Assert.AreEqual(action.InvokeCount, 0, "action.InvokeCount == 0, one conditon not met");
        }
        public void ReparentActionTest()
        {
            SysWindows.Shapes.Rectangle hostRectangle = new SysWindows.Shapes.Rectangle();
            // try parenting an action more than once; should throw
            StubAction  action   = new StubAction();
            StubTrigger trigger1 = new StubTrigger();
            StubTrigger trigger2 = new StubTrigger();

            trigger1.Attach(hostRectangle);
            trigger2.Attach(hostRectangle);
            trigger1.Actions.Add(action);
            try
            {
                trigger2.Actions.Add(action);
                Debug.Fail("Expected InvalidOperationException to be thrown after adding an action to a second trigger.");
            }
            catch (InvalidOperationException)
            {
            }

            // now try the same, properly unhooking before reparenting
            action   = new StubAction();
            trigger1 = new StubTrigger();
            trigger2 = new StubTrigger();
            trigger1.Actions.Add(action);
            trigger1.Actions.Remove(action);
            trigger2.Actions.Add(action);
            Assert.AreEqual(((IAttachedObject)action).AssociatedObject, trigger2.HostObject, "action.AssociatedObject == trigger2.Host");
            Assert.AreEqual(trigger2.Actions.Count, 1, "trigger2.Actions.Count == 1");
        }
        private StubTrigger AttachAction(CallMethodAction action, DependencyObject host)
        {
            StubTrigger trigger = CreateTrigger();

            trigger.Actions.Add(action);
            Interaction.GetTriggers(host).Add(trigger);
            return(trigger);
        }
        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");
        }
        private static StubTrigger AttachActionToObject(InvokeCommandAction invokeCommandAction, SysWindows.DependencyObject dependencyObject)
        {
            TriggerCollection triggersCollection = Interaction.GetTriggers(dependencyObject);
            StubTrigger       stubTrigger        = CreateTrigger();

            triggersCollection.Add(stubTrigger);
            stubTrigger.Actions.Add(invokeCommandAction);
            return(stubTrigger);
        }
        public void Invoke_NoPropertyName_IsNoOp()
        {
            StubTrigger          trigger = CreateStubTrigger();
            ChangePropertyAction action  = CreateChangePropertyAction(null, Brushes.Green);

            trigger.Actions.Add(action);

            trigger.FireStubTrigger();
        }
        public void Invoke_IncorrectParametersWithTargetSet_DoesNothing()
        {
            MethodObjectStub host    = CreateMethodObject();
            CallMethodAction action  = CreateCallMethodAction("IncompatibleParameters");
            StubTrigger      trigger = AttachAction(action, host);

            trigger.FireStubTrigger();
            Assert.AreEqual(host.LastMethodCalled, "None", "No method should be called");
        }
        public void Invoke_NonExistantMethodWithNoTarget_DoesNothing()
        {
            MethodObjectStub host    = CreateMethodObject();
            CallMethodAction action  = CreateCallMethodAction("NonExistantMethodName");
            StubTrigger      trigger = AttachAction(action, host);

            trigger.FireStubTrigger();
            Assert.AreEqual(host.LastMethodCalled, "None", "No method should be called");
        }
        public void Invoke_InvalidPropertyName_ThrowsArgumentException()
        {
            Rectangle            rectangle = CreateRectangle();
            StubTrigger          trigger   = CreateStubTrigger();
            ChangePropertyAction action    = CreateChangePropertyAction("Foo", Brushes.Green);

            AttachAction(rectangle, trigger, action);

            trigger.FireStubTrigger();
        }
        public void Invoke_WithCommand_InvokesCommand()
        {
            CommandHelper       commandHelper       = CreateCommandHelper();
            InvokeCommandAction invokeCommandAction = CreateInvokeCommandActionWithCommand(commandHelper.SuccessCommand);
            Button      button  = CreateButton();
            StubTrigger trigger = AttachActionToObject(invokeCommandAction, button);

            trigger.FireStubTrigger();
            Assert.IsTrue(commandHelper.Successful, "Command should have been invoked.");
        }
Exemple #14
0
        public void AttachDetachTest()
        {
            StubTrigger stubTrigger = new StubTrigger();

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

            StubEventTriggerBase stubEventTrigger = new StubEventTriggerBase();

            BehaviorTestUtilities.TestIAttachedObject <StubBehavior>((IAttachedObject)stubEventTrigger);
        }
        public void Invoke_NonExistantMethodWithTargetSet_ThrowsArgumentException()
        {
            Rectangle        host    = CreateRectangle();
            MethodObjectStub target  = CreateMethodObject();
            CallMethodAction action  = CreateCallMethodAction("NonExistantMethodName");
            StubTrigger      trigger = AttachAction(action, host);

            action.TargetObject = target;
            trigger.FireStubTrigger();
        }
        public void Invoke_MultipleMethodsWithSpecificParameter_MostDerivedSignatureIsCalled()
        {
            MethodObjectStub methodObject = CreateMethodObject();
            CallMethodAction action       = CreateCallMethodAction("DuplicatedMethod");
            StubTrigger      trigger      = AttachAction(action, methodObject);

            trigger.FireStubTrigger(new StubEventArgs());

            Assert.AreEqual(methodObject.LastMethodCalled, "DuplicatedMethodWithStubEventArgsSignature", "DuplicatedMethodWithStubEventArgsSignature was not called.");
        }
        public void Invoke_MultipleMethodsWithSameName_EventHandlerSignatureIsCalled()
        {
            MethodObjectStub methodObject = CreateMethodObject();
            CallMethodAction action       = CreateCallMethodAction("DuplicatedMethod");
            StubTrigger      trigger      = AttachAction(action, methodObject);

            trigger.FireStubTrigger(EventArgs.Empty);

            Assert.AreEqual(methodObject.LastMethodCalled, "DuplicatedMethodWithEventHandlerSignature", "DuplicatedMethodWithEventHandlerSignature was not called.");
        }
        public void Invoke_ReadOnlyProperty_ThrowsArgumentException()
        {
            Button               button  = CreateButton();
            StubTrigger          trigger = CreateStubTrigger();
            ChangePropertyAction action  = CreateChangePropertyAction("IsDefaulted", true);

            AttachAction(button, trigger, action);

            trigger.FireStubTrigger();
        }
        public void Invoke_IncompatiblePropertyWithValueType_ThrowsArgumentException()
        {
            Rectangle            rectangle = CreateRectangle();
            StubTrigger          trigger   = CreateStubTrigger();
            ChangePropertyAction action    = CreateChangePropertyAction("Width", Brushes.Green);

            AttachAction(rectangle, trigger, action);

            trigger.FireStubTrigger();
        }
        private StubTrigger SetupRemoveAction(DependencyObject target)
        {
            StubTrigger         trigger = new StubTrigger();
            RemoveElementAction action  = new RemoveElementAction();

            trigger.Actions.Add(action);

            trigger.Attach(target);
            return(trigger);
        }
        public void RemoveFromInvalidComponent()
        {
            Rectangle   rectangle = new Rectangle();
            StubTrigger trigger   = SetupRemoveAction(rectangle);

            RichTextBox textBox = new RichTextBox();

            textBox.Document.Blocks.Add(new BlockUIContainer(rectangle));
            trigger.FireStubTrigger();
        }
        public void Invoke_InvalidPropertyFormatString_ThrowsException()
        {
            Rectangle            rectangle = CreateRectangle();
            StubTrigger          trigger   = CreateStubTrigger();
            ChangePropertyAction action    = CreateChangePropertyAction("Width", "0.0.0.0");

            AttachAction(rectangle, trigger, action);

            trigger.FireStubTrigger();
        }
        public void Invoke_UniqueMethodWithNoParameters_IsCalled()
        {
            MethodObjectStub methodObject = CreateMethodObject();
            CallMethodAction action       = CreateCallMethodAction("UniqueMethodWithNoParameters");
            StubTrigger      trigger      = AttachAction(action, methodObject);

            trigger.FireStubTrigger();

            Assert.AreEqual(methodObject.LastMethodCalled, "UniqueMethodWithNoParameters", "UniqueMethodWithNoParameters was not called.");
        }
        public void Invoke_AnimatedObjectChange_Changes()
        {
            Ellipse e = new Ellipse();
            ChangePropertyAction c = CreateChangePropertyAction("Fill", Brushes.Gray);
            StubTrigger          t = CreateStubTrigger();

            AttachAction(e, t, c);
            c.Duration = TimeSpan.FromMilliseconds(5);
            t.FireStubTrigger();
        }
        public void Invoke_IncorrectParametersWithTargetSet_ThrowsArgumentException()
        {
            Rectangle        host    = CreateRectangle();
            MethodObjectStub target  = CreateMethodObject();
            CallMethodAction action  = CreateCallMethodAction("IncompatibleParameters");
            StubTrigger      trigger = AttachAction(action, host);

            action.TargetObject = target;
            trigger.FireStubTrigger();
        }
        public void Invoke_AnimatedColorChange_Changes()
        {
            SolidColorBrush      brush = new SolidColorBrush(Colors.Red);
            ChangePropertyAction c     = CreateChangePropertyAction("Color", Colors.Gray);
            StubTrigger          t     = CreateStubTrigger();

            AttachAction(brush, t, c);
            c.Duration = TimeSpan.FromMilliseconds(5);
            t.FireStubTrigger();
        }
        public void Invoke_AnimatedPointChange_Changes()
        {
            Ellipse e = new Ellipse();
            ChangePropertyAction c = CreateChangePropertyAction("RenderTransformOrigin", new System.Windows.Point(0.3, 0.3));
            StubTrigger          t = CreateStubTrigger();

            AttachAction(e, t, c);
            c.Duration = TimeSpan.FromMilliseconds(5);
            t.FireStubTrigger();
        }
        public void Invoke_AnimatedDoubleChange_Changes()
        {
            Ellipse e = new Ellipse();
            ChangePropertyAction c = CreateChangePropertyAction("Opacity", 0.0d);
            StubTrigger          t = CreateStubTrigger();

            AttachAction(e, t, c);
            c.Duration = TimeSpan.FromMilliseconds(5);
            t.FireStubTrigger();
        }
        public void Invoke_RedFillToGreen_ChangesToGreen()
        {
            Rectangle            rectangle = CreateRectangle();
            StubTrigger          trigger   = CreateStubTrigger();
            ChangePropertyAction action    = CreateChangePropertyAction("Fill", Brushes.Green);

            AttachAction(rectangle, trigger, action);
            trigger.FireStubTrigger();

            Assert.AreEqual(rectangle.Fill, Brushes.Green, "rectangle.Fill == Green");
        }
        public void Invoke_InaccessibleProperty_ThrowsArgumentException()
        {
            Button      button  = CreateButton();
            StubTrigger trigger = CreateStubTrigger();
            // EffectiveValuesInitialSize is an internal property on Button, and should be inaccessible
            ChangePropertyAction action = CreateChangePropertyAction("EffectiveValuesInitialSize", 10);

            AttachAction(button, trigger, action);

            trigger.FireStubTrigger();
        }