public void RunWalkthrough() { string folder = System.IO.Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().CodeBase).Substring(6).Replace("/", @"\"); string templateFolder = System.IO.Path.Combine(folder, @"..\..\..\WorldModel\WorldModel\Core"); WorldModel worldModel = new WorldModel( System.IO.Path.Combine(folder, @"..\..\walkthrough.aslx"), templateFolder, null); Mock <IPlayer> player = new Mock <IPlayer>(); worldModel.Initialise(player.Object); worldModel.Begin(); foreach (string cmd in worldModel.Walkthroughs.Walkthroughs["debug"].Steps) { if (cmd.StartsWith("assert:")) { string expr = cmd.Substring(7); Assert.AreEqual(true, worldModel.Assert(expr), expr); } else { worldModel.SendCommand(cmd); } } }
static public void ClassInitialize(TestContext tc) { // http://stackoverflow.com/questions/4518544/xmlreader-from-a-string-content WorldModel.BackupReferenceReader = (x) => { const string coreLibFolder = @"..\..\..\WorldModelCompact\Core"; string whereFrom = Path.Combine(coreLibFolder, @"Languages\" + x); if (File.Exists(whereFrom)) { Console.WriteLine(string.Format("Loading {0}", whereFrom)); return(XmlReader.Create(new StringReader(File.ReadAllText(whereFrom)))); } whereFrom = Path.Combine(coreLibFolder, x); if (File.Exists(whereFrom)) { Console.WriteLine(string.Format("Loading {0}", whereFrom)); return(XmlReader.Create(new StringReader(File.ReadAllText(whereFrom)))); } Console.WriteLine(string.Format("Could not find {0}", x)); return(null); }; string folder = System.IO.Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().CodeBase).Substring(6).Replace("/", @"\"); s_worldModel = new WorldModel(System.IO.Path.Combine(folder, @"..\..\simple.aslx"), null); s_defaultController.m_worldModel = s_worldModel; s_worldModel.Initialise(s_defaultController); s_worldModel.Begin(); //while (defaultController.m_continue) //{ // string stdin = System.Console.ReadLine(); // if (stdin == "quit") // { // defaultController.Quit(); // } // else // { // s_worldModel.SendCommand(stdin); // } //} //s_worldModel.Finish(); }
public void RunWalkthrough() { string folder = System.IO.Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().CodeBase).Substring(6).Replace("/", @"\"); string templateFolder = System.IO.Path.Combine(folder, @"..\..\..\WorldModel\WorldModel\Core"); WorldModel worldModel = new WorldModel( System.IO.Path.Combine(folder, @"..\..\savetest.aslx"), templateFolder, null); Mock <IPlayer> player = new Mock <IPlayer>(); bool success = worldModel.Initialise(player.Object); Assert.IsTrue(success, "Initialisation failed"); worldModel.Begin(); worldModel.SendCommand("update"); string tempFilename = System.IO.Path.GetTempFileName(); worldModel.Save(tempFilename, null); WorldModel savedGameWorldModel = new WorldModel(tempFilename, null, null); success = savedGameWorldModel.Initialise(player.Object); Assert.IsTrue(success, "Initialisation failed"); savedGameWorldModel.Begin(); foreach (string cmd in worldModel.Walkthroughs.Walkthroughs["verify"].Steps) { if (cmd.StartsWith("assert:")) { string expr = cmd.Substring(7); Assert.AreEqual(true, worldModel.Assert(expr), expr); } else { worldModel.SendCommand(cmd); } } System.IO.File.Delete(tempFilename); }
static void RunTheShip() { string folder = System.IO.Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().CodeBase).Substring(6).Replace("/", @"\"); WorldModel worldModel = new WorldModel(System.IO.Path.Combine(folder, @"..\..\TheShip.aslx"), null); DefaultController defaultController = new DefaultController(); defaultController.m_worldModel = worldModel; worldModel.Initialise(defaultController); worldModel.Begin(); while (defaultController.m_continue) { string stdin = System.Console.ReadLine(); if (stdin == "quit") { defaultController.Quit(); } else { worldModel.SendCommand(stdin); } } worldModel.Finish(); }