Esempio n. 1
0
        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);
        }
Esempio n. 2
0
        public void InputtingExistentValidFile_SetsUpNodesCorrectly()
        {
            Story      story      = new Story();
            SpeechNode speechNode = story.CreateNode("TestNode");

            speechNode.Text = "Test Text";
            speechNode.Tags.Add("Tag1");

            string filePath = Path.Combine(Resources.TempDir, "Test.txt");

            SaveStoryBinary(story, filePath);

            FileAssert.FileExists(filePath);
            Story loadedStory = Story.Load(filePath);

            Assert.IsNotNull(loadedStory);
            Assert.AreEqual(1, loadedStory.NodeCount);

            SpeechNode loadedNode = loadedStory.GetNodeAt(0);

            Assert.IsNotNull(loadedNode);
            Assert.AreEqual("TestNode", loadedNode.Name);
            Assert.AreEqual("Test Text", loadedNode.Text);
            Assert.AreEqual(1, loadedNode.Tags.Count);
            Assert.AreEqual("Tag1", loadedNode.Tags[0]);
            Assert.AreEqual(0, loadedNode.TransitionCount);
            Assert.AreSame(loadedStory, loadedNode.ParentStory);
        }
Esempio n. 3
0
        public void InputtingExistentInvalidFile_ReturnsNull()
        {
            string filePath = Path.Combine(Resources.TempDir, "Test.txt");

            File.WriteAllText(filePath, "WubbaLubba");

            FileAssert.FileExists(filePath);
            Assert.IsNull(Story.Load(filePath));
        }
Esempio n. 4
0
        public void Constructor_InputtingFilePath_LoadsStoryFromInputtedFilePath()
        {
            string path  = Path.Combine(Resources.TempDir, "Test.data");
            Story  story = new Story();

            story.Save(path);

            FileAssert.FileExists(path);

            RequestContext requestContext = new RequestContext(null, null, null);
            StoryRuntime   storyRuntime   = new StoryRuntime(requestContext, path);

            Assert.IsNotNull(storyRuntime.Story);
        }
Esempio n. 5
0
        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));
        }
Esempio n. 6
0
        public void InputtingExistentValidFile_ReturnsStory()
        {
            Story story = new Story();

            story.Name = "Test";

            string filePath = Path.Combine(Resources.TempDir, "Test.txt");

            SaveStoryBinary(story, filePath);

            FileAssert.FileExists(filePath);
            Story loadedStory = Story.Load(filePath);

            Assert.IsNotNull(story);
            Assert.AreEqual("Test", loadedStory.Name);
            Assert.AreEqual(0, loadedStory.NodeCount);
        }
Esempio n. 7
0
        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);
        }