public void ProcessRequest_CurrentNodeKeyDoesExistInSessionAttributes_SetsNextNodeName() { Story story = new Story(); SpeechNode speechNode = story.CreateNode("Test"); SpeechNode speechNode2 = story.CreateNode("Test2"); speechNode.CreateTransition(speechNode2); Assert.IsNotNull(speechNode.GetNextNode()); SkillRequest request = new SkillRequest(); request.Request = new IntentRequest(); request.Session = new Session(); request.Session.Attributes = new Dictionary <string, object>() { { StoryRuntime.CurrentNodeKey, "Test" } }; RequestContext requestContext = new RequestContext(request, null, null); StoryRuntime storyRuntime = new StoryRuntime(requestContext, story); storyRuntime.TrySetCurrentNode(0); Assert.IsTrue(request.Session.Attributes.ContainsKey(StoryRuntime.CurrentNodeKey)); Assert.AreEqual("Test", request.Session.Attributes[StoryRuntime.CurrentNodeKey]); SkillResponse response = storyRuntime.ProcessRequest(); Assert.IsNotNull(response.SessionAttributes); Assert.AreSame(request.Session.Attributes, response.SessionAttributes); Assert.IsTrue(response.SessionAttributes.ContainsKey(StoryRuntime.CurrentNodeKey)); Assert.AreEqual("Test2", response.SessionAttributes[StoryRuntime.CurrentNodeKey]); }
public void Save_Overwrite_FileExists_OverwritesFileCorrectly_ReturnsTrue() { Story story = new Story(); SpeechNode speechNode = story.CreateNode("Test"); SpeechNode speechNode2 = story.CreateNode("Test2"); speechNode.CreateTransition(speechNode2); string filePath = Path.Combine(Resources.TempDir, "Test.data"); File.WriteAllText(filePath, "Test"); FileAssert.FileExists(filePath); Assert.IsTrue(story.Save(filePath, true)); FileAssert.FileExists(filePath); Story loadedStory = Story.Load(filePath); Assert.IsNotNull(loadedStory); Assert.AreEqual(2, loadedStory.NodeCount); Assert.IsNotNull(loadedStory.FindNode("Test")); Assert.IsNotNull(loadedStory.FindNode("Test2")); Assert.AreEqual(1, loadedStory.FindNode("Test").TransitionCount); Assert.AreSame(loadedStory.FindNode("Test"), loadedStory.FindNode("Test").GetTransitionAt(0).Source); Assert.AreSame(loadedStory.FindNode("Test2"), loadedStory.FindNode("Test").GetTransitionAt(0).Destination); }
public void ConditionPasses_WithCurrentRuntimeSetToSameIntent_ReturnsTrue() { SkillRequest request = new SkillRequest(); request.Request = new IntentRequest() { Intent = new Intent() { Name = "Test" } }; RequestContext requestContext = new RequestContext(request, null, null); StoryRuntime runtime = new StoryRuntime(requestContext); Story story = new Story(); story.Runtime = runtime; SpeechNode speechNode = story.CreateNode("TestNode"); Transition transition = speechNode.CreateTransition(new SpeechNode()); IntentCondition intentCondition = transition.CreateCondition <IntentCondition>(); intentCondition.IntentName = "Test"; Assert.IsTrue(intentCondition.ConditionPasses()); }
public void GetTransitionAt_InputtingInBoundsIndex_ReturnsCorrectTransition() { SpeechNode speechNode = new SpeechNode(); SpeechNode destinationNode = new SpeechNode(); Transition transition = speechNode.CreateTransition(destinationNode); Assert.AreSame(transition, speechNode.GetTransitionAt(0)); }
public void CreateTransition_ReturnsCreatedTransition() { SpeechNode speechNode = new SpeechNode(); SpeechNode destinationNode = new SpeechNode(); Transition transition = speechNode.CreateTransition(destinationNode); Assert.AreSame(transition, speechNode.GetTransitionAt(0)); }
public void CreateTransition_InputtingNullDestinationNode_ReturnsNull() { SpeechNode speechNode = new SpeechNode(); Assert.AreEqual(0, speechNode.TransitionCount); Assert.IsNull(speechNode.CreateTransition(null)); Assert.AreEqual(0, speechNode.TransitionCount); }
public void IEnumerable_WithTransitions_IteratesOverTransitions() { SpeechNode speechNode = new SpeechNode(); speechNode.CreateTransition(new SpeechNode()); speechNode.CreateTransition(new SpeechNode()); Assert.AreEqual(2, speechNode.TransitionCount); int counter = 0; foreach (Transition transition in speechNode) { ++counter; } Assert.AreEqual(2, counter); }
public void GetNextNode_MultipleValidTransition_ReturnsFirstValidDestinationNode() { SpeechNode speechNode = new SpeechNode(); SpeechNode destinationNode = new SpeechNode(); Transition transition = speechNode.CreateTransition(destinationNode); MockTransitionCondition condition = transition.CreateCondition <MockTransitionCondition>(); condition.ConditionPasses_Result = true; SpeechNode secondDestinationNode = new SpeechNode(); Transition secondTransition = speechNode.CreateTransition(secondDestinationNode); MockTransitionCondition secondCondition = secondTransition.CreateCondition <MockTransitionCondition>(); secondCondition.ConditionPasses_Result = true; Assert.AreEqual(2, speechNode.TransitionCount); Assert.IsTrue(transition.ValidateConditions()); Assert.IsTrue(secondTransition.ValidateConditions()); Assert.AreSame(destinationNode, speechNode.GetNextNode()); }
public void GetNextNode_NoValidTransitions_ReturnsNull() { SpeechNode speechNode = new SpeechNode(); SpeechNode destinationNode = new SpeechNode(); Transition transition = speechNode.CreateTransition(destinationNode); transition.CreateCondition <MockTransitionCondition>(); Assert.AreEqual(1, speechNode.TransitionCount); Assert.IsFalse(transition.ValidateConditions()); Assert.IsNull(speechNode.GetNextNode()); }
public void CreateTransition_CreatesNewTransition_WithCorrectValues() { SpeechNode speechNode = new SpeechNode(); SpeechNode destinationNode = new SpeechNode(); Assert.AreEqual(0, speechNode.TransitionCount); speechNode.CreateTransition(destinationNode); Assert.AreEqual(1, speechNode.TransitionCount); Assert.AreSame(speechNode, speechNode.GetTransitionAt(0).Source); Assert.AreSame(destinationNode, speechNode.GetTransitionAt(0).Destination); }
public void Save_DontOverwrite_FileExists_DoesNothing_ReturnsFalse() { Story story = new Story(); SpeechNode speechNode = story.CreateNode("Test"); SpeechNode speechNode2 = story.CreateNode("Test2"); speechNode.CreateTransition(speechNode2); string filePath = Path.Combine(Resources.TempDir, "Test.data"); File.WriteAllText(filePath, "Test"); FileAssert.FileExists(filePath); Assert.IsFalse(story.Save(filePath, false)); FileAssert.FileExists(filePath); Assert.AreEqual("Test", File.ReadAllText(filePath)); }
public void InputtingExistentValidFile_SetsUpTransitionsCorrectly() { Story story = new Story(); SpeechNode speechNode = story.CreateNode("Node1"); SpeechNode destinationNode = story.CreateNode("Node2"); Transition transition = speechNode.CreateTransition(destinationNode); IntentCondition condition = transition.CreateCondition <IntentCondition>(); condition.IntentName = "TestIntent"; string filePath = Path.Combine(Resources.TempDir, "Test.txt"); SaveStoryBinary(story, filePath); FileAssert.FileExists(filePath); Story loadedStory = Story.Load(filePath); Assert.IsNotNull(loadedStory); Assert.AreEqual(2, loadedStory.NodeCount); SpeechNode loadedNode = loadedStory.GetNodeAt(0); SpeechNode loadedDestinationNode = loadedStory.GetNodeAt(1); Assert.IsNotNull(loadedNode); Assert.IsNotNull(loadedDestinationNode); Assert.AreEqual(1, loadedNode.TransitionCount); Transition loadedTransition = loadedNode.GetTransitionAt(0); Assert.AreSame(loadedNode, loadedTransition.Source); Assert.AreSame(loadedDestinationNode, loadedTransition.Destination); Assert.AreEqual(1, loadedTransition.ConditionCount); TransitionCondition loadedCondition = loadedTransition.GetConditionAt(0); Assert.IsInstanceOfType(loadedCondition, typeof(IntentCondition)); Assert.AreEqual("TestIntent", (loadedCondition as IntentCondition).IntentName); Assert.AreSame(loadedTransition, loadedCondition.Transition); }