public void xmlParse( string infile, List <string> ExpectedOut ) { Contract.Requires(infile != null); var x = new XmlParser(); var dictionary = new Dictionary <string, string>(); x.Add( new String[] { "test-file", "users", "user", "name" }, dictionary, (dict, str) => { dict["name"] = str; return(null); }, (dict, str) => { return(null); }, (dict, str) => { return(null); } ); x.Add( new String[] { "test-file", "users", "user", "$name" }, dictionary, (dict, str) => { dict["name"] = str; return(null); }, (dict, str) => { return(null); }, (dict, str) => { return(null); } ); x.Add( new String[] { "test-file", "users", "user", "phone" }, dictionary, (dict, str) => { dict["phone"] = str; return(null); }, (dict, str) => { return(null); }, (dict, str) => { return(null); } ); x.Add( new String[] { "test-file", "users", "user" }, dictionary, (dict, str) => { return(null); }, (dict, str) => { dict.Clear(); return(null); }, (dict, str) => { return ((dict.ContainsKey("name") ? "name= " + dict["name"] : "") + (dict.ContainsKey("phone") ? ", phone= " + dict["phone"] : "")); }); x.Process(infile); if (ExpectedOut != null) { Assert.That(x.Error, Is.EqualTo(XmlParser <string> .Errors.None)); Assert.That(x.Output, Is.EqualTo(ExpectedOut)); } else { Assert.That(x.Error, Is.EqualTo(XmlParser <string> .Errors.InvalidXml)); } }
public void xmlParse( string infile, List<string> ExpectedOut ) { Contract.Requires(infile != null); var x = new XmlParser(); var dictionary = new Dictionary<string, string>(); x.Add( new String[] { "test-file", "users", "user", "name" }, dictionary, (dict, str) => { dict["name"] = str; return null; }, (dict, str) => { return null; }, (dict, str) => { return null; } ); x.Add( new String[] { "test-file", "users", "user", "$name" }, dictionary, (dict, str) => { dict["name"] = str; return null; }, (dict, str) => { return null; }, (dict, str) => { return null; } ); x.Add( new String[] { "test-file", "users", "user", "phone" }, dictionary, (dict, str) => { dict["phone"] = str; return null; }, (dict, str) => { return null; }, (dict, str) => { return null; } ); x.Add( new String[] { "test-file", "users", "user" }, dictionary, (dict, str) => { return null; }, (dict, str) => { dict.Clear(); return null; }, (dict, str) => { return (dict.ContainsKey("name") ? "name= " + dict["name"] : "") + (dict.ContainsKey("phone") ? ", phone= " + dict["phone"] : ""); }); x.Process(infile); if (ExpectedOut != null) { Assert.That(x.Error, Is.EqualTo(XmlParser<string>.Errors.None)); Assert.That(x.Output, Is.EqualTo(ExpectedOut)); } else { Assert.That(x.Error, Is.EqualTo(XmlParser<string>.Errors.InvalidXml)); } }