Beispiel #1
0
        public static VisualStateManagerStub AttachCustomVSM(FrameworkElement element)
        {
            VisualStateManagerStub vsmStub = CreateVSMStub();

            element.SetValue(VisualStateManager.CustomVisualStateManagerProperty, vsmStub);
            return(vsmStub);
        }
Beispiel #2
0
        public void BindingChangesToNotMatchValue_TransitionsToFalseState()
        {
            Grid stateGrid = VisualStateHelper.CreateObjectWithStates <Grid>();
            DataStateBehavior      dataStateBehavior = CreateDataStateBehaviorInTrueState();
            VisualStateManagerStub vsmStub           = VisualStateHelper.AttachCustomVSM(stateGrid);

            AttachBehavior(dataStateBehavior, stateGrid);

            dataStateBehavior.Binding = CreateObject();
            Assert.AreEqual(vsmStub.LastStateName, VisualStateHelper.DefaultFalseStateName, "Binding change to no longer match Value should have caused a transition to the FalseState");
        }
Beispiel #3
0
        public void ValueChangesToMatchBinding_TransitionsToTrueState()
        {
            Grid stateGrid = VisualStateHelper.CreateObjectWithStates <Grid>();
            DataStateBehavior      dataStateBehavior = CreateDataStateBehaviorInFalseState();
            VisualStateManagerStub vsmStub           = VisualStateHelper.AttachCustomVSM(stateGrid);

            AttachBehavior(dataStateBehavior, stateGrid);

            dataStateBehavior.Value = dataStateBehavior.Binding;
            Assert.AreEqual(vsmStub.LastStateName, VisualStateHelper.DefaultTrueStateName, "Value change to match Binding should have caused a transition to the TrueState");
        }
Beispiel #4
0
        public void FalseStateChanges_TransitionsToNewFalseState()
        {
            Grid stateGrid = VisualStateHelper.CreateObjectWithStates <Grid>();
            DataStateBehavior      dataStateBehavior = CreateDataStateBehaviorInFalseState();
            VisualStateManagerStub vsmStub           = VisualStateHelper.AttachCustomVSM(stateGrid);

            AttachBehavior(dataStateBehavior, stateGrid);

            dataStateBehavior.FalseState = VisualStateHelper.ArbitraryThirdStateName;
            Assert.AreEqual(vsmStub.LastStateName, VisualStateHelper.ArbitraryThirdStateName, "Change in FalseState should have caused a transition to the new state, as Binding does not match Value.");
        }
        public void Invoke_UseTransitionsIsFalse_TransitionsAreNotUsed()
        {
            Grid                   stateGrid       = VisualStateHelper.CreateObjectWithStates <Grid>();
            GoToStateAction        goToStateAction = CreateTestGoToStateAction();
            VisualStateManagerStub vsm             = VisualStateHelper.AttachCustomVSM(stateGrid);
            StubTrigger            trigger         = AttachAction(goToStateAction, stateGrid);

            goToStateAction.StateName      = VisualStateHelper.ArbitraryThirdStateName;
            goToStateAction.UseTransitions = false;
            trigger.FireStubTrigger();

            Assert.IsTrue(vsm.LastUseTransitions.HasValue && !vsm.LastUseTransitions.Value, "UseTransitions should be respected by the GoToState call.");
        }
        public void Invoke_TargetObjectSet_CallsGoToStateOnTarget()
        {
            UserControl            statefulUC      = VisualStateHelper.CreateObjectWithStates <UserControl>();
            Grid                   statefulGrid    = VisualStateHelper.CreateObjectWithStates <Grid>();
            VisualStateManagerStub gridVSM         = VisualStateHelper.AttachCustomVSM(statefulGrid);
            Grid                   childGrid       = CreateEmptyGrid();
            GoToStateAction        goToStateAction = CreateTestGoToStateAction();
            StubTrigger            trigger         = AttachAction(goToStateAction, childGrid);

            // set up the tree structure
            statefulUC.Content = childGrid;

            // target the action and set the StateName
            goToStateAction.TargetObject = statefulGrid;
            goToStateAction.StateName    = VisualStateHelper.ArbitraryThirdStateName;

            trigger.FireStubTrigger();
            Assert.AreEqual(gridVSM.LastStateName, VisualStateHelper.ArbitraryThirdStateName, "test");
        }