public void ElmahXmlParser_UnflatFile_FlattenFile() { // arrange var fileName = "unflattenendFile.xml"; var fileContents = _guid1.ToString() + ",<error\r\n<item name=\"SomeItem\">\r\n<value=\"abc123\"></item>\r\n" + _guid2 + ",<error\r\n<item name=\"SomethingElse\">\r\n<value=\"def456\"></item>\r\n"; var expectedFlattenedFileContents = string.Join("\r\n", (fileContents.Split("\r\n".ToCharArray()))).Replace("\r\n", " ").Replace("</item>" + _guid2, "</item>\r\n" + _guid2); var helper = new Mock<IFileHelper>(); helper.Setup(x => x.ReadAllLines(fileName)).Returns(fileContents.Split("\r\n".ToCharArray())); var parser = new ElmahXmlParser(helper.Object); // act var actualFlattenedFileContents = parser.FlattenFileContents(fileName); // assert Assert.That(actualFlattenedFileContents, Is.EqualTo(expectedFlattenedFileContents), "Wrong Flattened File Contents"); }
public static void Main(string[] args) { Console.WriteLine("Starting parser engine ..."); var parser = new ElmahXmlParser(new FileHelper()); parser.FlattenFileContents("errors.xml"); var scriptNameList = parser.GetScriptNameList("flatErrors.xml"); var stackTraceList = parser.GetStackTraceList("flatErrors.xml"); var userAgentList = parser.GetUserAgentList("flatErrors.xml"); var outputLines = new StringBuilder("ID\tPage\tStackTrace\tUserAgent\r\n"); var count = scriptNameList.Count; Console.WriteLine("Page Count: {0}\r\nStack Trace Count: {1}\r\nUser Agent Count: {2}", count, stackTraceList.Count, userAgentList.Count); foreach (var item in scriptNameList) { if (stackTraceList.ContainsKey(item.Key) && userAgentList.ContainsKey(item.Key)) outputLines.AppendFormat("{0}\t{1}\t{2}\t{3}\r\n", item.Key, item.Value, stackTraceList[item.Key], userAgentList[item.Key]); else Console.WriteLine("Missing key: " + item.Key); } File.WriteAllText("formattedErrors.txt", outputLines.ToString()); Console.WriteLine("Parsing Complete."); }