public void Attach_NoStateNamesSet_DoesNothing() { Grid stateGrid = VisualStateHelper.CreateObjectWithStates <Grid>(); DataStateBehavior dataStateBehavior = CreateEmptyDataStateBehavior(); AttachBehavior(dataStateBehavior, stateGrid); // Attaching an empty DataStateBehavior should not cause any problems. }
public void TrueStateChangesToInvalidValue_ThrowsArgumentException() { Grid stateGrid = VisualStateHelper.CreateObjectWithStates <Grid>(); DataStateBehavior dataStateBehavior = CreateEmptyDataStateBehavior(); AttachBehavior(dataStateBehavior, stateGrid); dataStateBehavior.TrueState = "TrueState"; dataStateBehavior.TrueState = "NonExistantState"; }
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"); }
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"); }
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 Attach_FalseStateDoesNotExist_ThrowsArgumentException() { Grid stateGrid = VisualStateHelper.CreateObjectWithStates <Grid>(); DataStateBehavior dataStateBehavior = CreateEmptyDataStateBehavior(); dataStateBehavior.FalseState = "NonExistantState"; using (new StubWindow(stateGrid)) { AttachBehavior(dataStateBehavior, stateGrid); } }
public void GetVisualStateGroups_UserControlControlWithChildStates_ReturnsChildStates() { Grid stateGrid = VisualStateHelper.CreateObjectWithStates <Grid>(); UserControl userControl = CreateUserControlWithContent(stateGrid); using (new StubWindow(userControl)) { IList vsgs = VisualStateUtilities.GetVisualStateGroups(userControl); Assert.AreEqual(vsgs.Count, 1, "Should find 1 VisualStateGroup on the UserControl"); } }
public void GoToState_OnUserControl_WorksProperly() { Grid stateGrid = VisualStateHelper.CreateObjectWithStates <Grid>(); UserControl userControl = CreateUserControlWithContent(stateGrid); userControl.Content = stateGrid; bool success = VisualStateUtilities.GoToState(userControl, VisualStateHelper.ArbitraryThirdStateName, true); Assert.IsTrue(success, "GoToState on a valid UserControl state should navigate to the state correctly."); }
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 FindNearestStatefulControl_ContextNestedSeveralLevelsDeep_FindsAppropriateParent() { Button button = CreateButton(); Grid grid = VisualStateHelper.CreateObjectWithStates <Grid>(); UserControl userControl = CreateUserControlWithContent(grid); grid.Children.Add(button); FrameworkElement nearestControl; VisualStateUtilities.TryFindNearestStatefulControl(button, out nearestControl); Assert.AreEqual(nearestControl, userControl, "Using child Grid of UserControl as context, closest stateful control should be UserControl."); }
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"); }