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 void ElmahXmlParser_ParseStackTrace_GetList() { // arrange var expectedList = new Dictionary<Guid, string>() { { _guid1, "System.Web.HttpException (0x80004005): Exception Message.
 at Namespace1.ClassName1.Method(string something1)
 at System.Web.Handlers.ProcessRequest(Params params)" }, { _guid2, "System.Web.HttpException (0x80004005): Exception Message.
 at Namespace2.ClassName2.Method(string something2)
 at System.Web.Handlers.ProcessRequest(Params params)" }, }; var helper = new Mock<IFileHelper>(); var errorsXmlFileName = "errors.xml"; helper.Setup(x => x.ReadAllLines(errorsXmlFileName)).Returns(new[] { string.Format("{{{0}}},detail=\"System.Web.HttpException (0x80004005): Exception Message.
 at Namespace1.ClassName1.Method(string something1)
 at System.Web.Handlers.ProcessRequest(Params params)\" ", _guid1.ToString()), string.Format("{{{0}}},detail=\"System.Web.HttpException (0x80004005): Exception Message.
 at Namespace2.ClassName2.Method(string something2)
 at System.Web.Handlers.ProcessRequest(Params params)\" ", _guid2.ToString()), }); var parser = new ElmahXmlParser(helper.Object); // act var actualList = parser.GetStackTraceList(errorsXmlFileName); // assert Assert.That(actualList, Is.Not.Empty, "Empty List"); Assert.That(actualList, Is.EquivalentTo(expectedList), "Wrong List"); }
public void ElmahXmlParser_ParseScriptName_GetList() { // arrange var expectedList = new Dictionary<Guid, string>() { { _guid1, "/folder1/test1.aspx" }, { _guid2, "/folder2/test2.aspx" }, }; var helper = new Mock<IFileHelper>(); var errorsXmlFileName = "errors.xml"; helper.Setup(x => x.ReadAllLines(errorsXmlFileName)).Returns(new[] { string.Format("{{{0}}},<item\r\n name=\"URL\">\r\n<value\r\nstring=\"/folder1/test1.aspx\" />", _guid1.ToString()), string.Format("{{{0}}},<item\r\n name=\"URL\">\r\n<value\r\nstring=\"/folder2/test2.aspx\" />", _guid2.ToString()), }); var parser = new ElmahXmlParser(helper.Object); // act var actualList = parser.GetScriptNameList(errorsXmlFileName); // assert Assert.That(actualList, Is.Not.Empty, "Empty List"); Assert.That(actualList, Is.EquivalentTo(expectedList), "Wrong List"); Assert.That(_guid1, Is.Not.EqualTo(_guid2), "GUIDs are equal?!?"); }
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."); }