public void BoolTransitionCondition_NotTaken_WhenMissingStartingContextParameter(string key, bool targetValue) { Graph graph = new Graph(); Node nodeA = graph.MakeNode(); Node nodeB = graph.MakeNode(); Transition transition = new Transition(waitForManualExit: false); transition.AddTransitionCondition(new BoolTransitionCondition(key, targetValue)); NodeTransition nodeTransition = new NodeTransition { targets = new NodeId[] { nodeB.Id }, transition = transition }; graph.AddOutgoingTransitionForNode(nodeA, nodeTransition); IGraphContext stubContext = Substitute.For <IGraphContext>(); stubContext.HasBoolParameterKey(Arg.Any <string>()).Returns(false); IGraphContextFactory stubFactory = Substitute.For <IGraphContextFactory>(); stubFactory.MakeContext().Returns(stubContext); GraphContextFactoryLocator.Provide(stubFactory); bool entered = false; nodeB.OnEnter += () => { entered = true; }; graph.Start(); Assert.IsFalse(entered); }
public void BoolTransitionCondition_TakenWhenMatching_NotTakenWhenNotMatching(string key, bool targetValue, bool expectedEntered) { Graph graph = new Graph(); Node nodeA = graph.MakeNode(); Node nodeB = graph.MakeNode(); Transition transition = new Transition(waitForManualExit: false); transition.AddTransitionCondition(new BoolTransitionCondition(key, targetValue)); NodeTransition nodeTransition = new NodeTransition { targets = new NodeId[] { nodeB.Id }, transition = transition }; graph.AddOutgoingTransitionForNode(nodeA, nodeTransition); IGraphContext stubContext = Substitute.For <IGraphContext>(); stubContext.HasBoolParameterKey(Arg.Is("Key")).Returns(true); stubContext.GetBool(Arg.Is("Key")).Returns(true); IGraphContextFactory stubFactory = Substitute.For <IGraphContextFactory>(); stubFactory.MakeContext().Returns(stubContext); GraphContextFactoryLocator.Provide(stubFactory); bool entered = false; nodeB.OnEnter += () => { entered = true; }; graph.Start(); Assert.AreEqual(expectedEntered, entered); }
public void BoolTransitionCondition_MatchesOtherTests_AfterSerializingAndDeserializing(string key, bool targetValue, bool expectedEntered) { Graph graph = new Graph(); Node nodeA = graph.MakeNode(); Node nodeB = graph.MakeNode(); Transition transition = new Transition(waitForManualExit: false); BoolTransitionCondition condition = new BoolTransitionCondition(key, targetValue); // NEW CODE string serialized = TransitionConditionSerializer.Serialize(condition); ITransitionCondition deserialized = TransitionConditionSerializer.Deserialize(serialized); transition.AddTransitionCondition(deserialized); // END NEW CODE NodeTransition nodeTransition = new NodeTransition { targets = new NodeId[] { nodeB.Id }, transition = transition }; graph.AddOutgoingTransitionForNode(nodeA, nodeTransition); IGraphContext stubContext = Substitute.For <IGraphContext>(); stubContext.HasBoolParameterKey(Arg.Is("Key")).Returns(true); stubContext.GetBool(Arg.Is("Key")).Returns(true); IGraphContextFactory stubFactory = Substitute.For <IGraphContextFactory>(); stubFactory.MakeContext().Returns(stubContext); GraphContextFactoryLocator.Provide(stubFactory); bool entered = false; nodeB.OnEnter += () => { entered = true; }; graph.Start(); Assert.AreEqual(expectedEntered, entered); }