public void Filling() { NotebookDialog<MultiTest> Filler = new NotebookDialog<MultiTest>("All filled?"); MultiTest Filled = new MultiTest(); Filled.Answer = 42; Filled.Back = Direction.Back; Filled.Black = new ushort [] { 0, 0, 0 }; Filled.Check = true; Filled.Fr = Fruit.Apple | Fruit.Orange; Filled.Hosts = "/etc/hosts"; Filled.Newyear = new DateTime(System.DateTime.Now.Year, 1, 1); Filled.Wuppertahl = "wuppertahl"; Assert.IsTrue(Filler.Run(Filled)); }
public void Saving() { NotebookDialog<MultiTest> Saver = new NotebookDialog<MultiTest>("Do comply"); var Test = new MultiTest(); Assert.IsTrue(Saver.Run(Test)); Assert.AreEqual("wuppertahl", Test.Wuppertahl.ToLower()); Assert.AreEqual(42, Test.Answer); Assert.AreEqual(1, Test.Newyear.DayOfYear); Assert.IsTrue(Test.Check); Assert.AreEqual("/etc/hosts", Test.Hosts); Assert.AreEqual(Direction.Back, Test.Back); Assert.AreEqual(new ushort[] { 0, 0, 0 }, Test.Black); Assert.AreEqual(Fruit.Apple | Fruit.Orange, Test.Fr); }
/// <summary> /// Loads the given XML file and tries to parse it into XML. /// </summary> /// <param name="xmlFileName">The location of the XML file to load and parse.</param> void loadAndParseXML(string xmlFileName) { if (File.Exists(xmlFileName)) { TestGeneration = TestGenerations.ValidateXML(xmlFileName); XmlDocument doc = new XmlDocument(); using (FileStream fs = new FileStream(xmlFileName, FileMode.Open, FileAccess.Read)) { doc.Load(fs); FileInfo fi = new FileInfo(xmlFileName); switch (TestGeneration) { case TestGenerations.XML_FIRST_GENERATION: // Dealing with the first typee, test(s) only XmlNodeList testNodes = doc.SelectNodes("//test"); LoadedFileName = fi.Name.Replace(".xml", ""); foreach (XmlNode node in testNodes) { XmlNode sampleFile = node.SelectSingleNode("sample"); XmlNode command = node.SelectSingleNode("cmd"); XmlNode resultFile = node.SelectSingleNode("result"); Entries.Add( new TestEntry( ConvertFolderDelimiters(sampleFile.InnerText), command.InnerText, ConvertFolderDelimiters(resultFile.InnerText) ) ); } break; case TestGenerations.XML_SECOND_GENERATION: // Dealing with multi file foreach (XmlNode node in doc.SelectNodes("//testfile")) { String testFileLocation = ConvertFolderDelimiters(node.SelectSingleNode("location").InnerText); testFileLocation = Path.Combine(fi.DirectoryName, testFileLocation); MultiTest.Add(testFileLocation); } break; case TestGenerations.XML_THIRD_GENERATION: // Dealing with the newest version of tests LoadedFileName = fi.Name.Replace(".xml", ""); foreach (XmlNode node in doc.SelectNodes("//entry")) { int id = int.Parse(node.Attributes["id"].Value); // Get nodes for entry XmlNode command = node.SelectSingleNode("command"); XmlNode input = node.SelectSingleNode("input"); XmlNode output = node.SelectSingleNode("output"); XmlNodeList compareTo = node.SelectSingleNode("compare").SelectNodes("file"); // Convert to appropriate values string ccx_command = command.InnerText; string inputFile = input.InnerText; InputType inputType = InputTypeParser.parseString(input.Attributes["type"].Value); OutputType outputType = OutputTypeParser.parseString(output.InnerText); List <CompareFile> compareFiles = new List <CompareFile>(); foreach (XmlNode compareEntry in compareTo) { bool ignore = bool.Parse(compareEntry.Attributes["ignore"].Value); int compareId = int.Parse(compareEntry.Attributes["id"].Value); string correct = compareEntry.SelectSingleNode("correct").InnerText; XmlNode expectedNode = compareEntry.SelectSingleNode("expected"); string expected = (expectedNode != null) ? expectedNode.InnerText : correct; compareFiles.Add(new CompareFile(compareId, correct, expected, ignore)); } // Add entry Entries.Add(new TestEntry(id, inputFile, inputType, ccx_command, outputType, compareFiles)); } break; default: break; } } return; } throw new InvalidDataException("File does not exist"); }