public void Minimal_notice_generates_valid_XML() { var notice = new HoptoadNotice(); notice.ApiKey = "123456"; notice.Error = new HoptoadError { Class = "TestError", Message = "something blew up", Backtrace = new[] { new TraceLine() { File = "unknown.cs", LineNumber = 0, Method = "unknown" } } }; notice.Notifier = new HoptoadNotifier { Name = "hopsharp", Version = "2.0", Url = "http://github.com/krobertson/hopsharp" }; notice.ServerEnvironment = new HoptoadServerEnvironment { ProjectRoot = "/test", EnvironmentName = "staging" }; var serializer = new CleanXmlSerializer<HoptoadNotice>(); var xml = serializer.ToXml(notice); HoptoadValidator.ValidateSchema(xml); }
public void Minimal_notice_generates_valid_XML() { var notice = new AirbrakeNotice(); notice.ApiKey = "123456"; notice.Error = new AirbrakeError { Class = "TestError", Message = "something blew up", Backtrace = new[] { new AirbrakeTraceLine("unknown.cs", 0) { Method = "unknown" } } }; notice.Notifier = new AirbrakeNotifier { Name = "hopsharp", Version = "2.0", Url = "http://github.com/krobertson/hopsharp" }; notice.ServerEnvironment = new AirbrakeServerEnvironment("staging") { ProjectRoot = "/test", }; var serializer = new CleanXmlSerializer <AirbrakeNotice>(); string xml = serializer.ToXml(notice); AirbrakeValidator.ValidateSchema(xml); }
public void Notice_missing_error_fails_validation() { var notice = new AirbrakeNotice { ApiKey = "123456", Request = new AirbrakeRequest(new Uri("http://example.com/"), GetType().FullName) { Action = "Maximal_notice_generates_valid_XML", }, Notifier = new AirbrakeNotifier { Name = "sharpbrake", Version = "2.2", Url = "http://github.com/asbjornu/SharpBrake" }, ServerEnvironment = new AirbrakeServerEnvironment("staging") { ProjectRoot = "/test", }, }; var serializer = new CleanXmlSerializer <AirbrakeNotice>(); string xml = serializer.ToXml(notice); TestDelegate throwing = () => AirbrakeValidator.ValidateSchema(xml); XmlSchemaValidationException exception = Assert.Throws <XmlSchemaValidationException>(throwing); Console.WriteLine(exception); Assert.That(exception.Message, Is.StringContaining("notice")); Assert.That(exception.Message, Is.StringContaining("error")); Assert.That(exception.LineNumber, Is.EqualTo(18)); Assert.That(exception.LinePosition, Is.EqualTo(3)); }
public void Minimal_notice_generates_valid_XML() { var notice = new AirbrakeNotice(); notice.ApiKey = "123456"; notice.Error = new AirbrakeError { Class = "TestError", Message = "something blew up", Backtrace = new[] { new AirbrakeTraceLine ("unknown.cs", 0) { Method = "unknown"} } }; notice.Notifier = new AirbrakeNotifier { Name = "hopsharp", Version = "2.0", Url = "http://github.com/krobertson/hopsharp" }; notice.ServerEnvironment = new AirbrakeServerEnvironment("staging") { ProjectRoot = "/test", }; var serializer = new CleanXmlSerializer<AirbrakeNotice>(); string xml = serializer.ToXml(notice); AirbrakeValidator.ValidateSchema(xml); }
public void Minimal_notice_generates_valid_XML() { var error = Activator.CreateInstance <AirbrakeError>(); error.Class = "TestError"; error.Message = "something blew up"; error.Backtrace = new[] { new AirbrakeTraceLine("unknown.cs", 0) { Method = "unknown" } }; var notice = new AirbrakeNotice { ApiKey = "123456", Error = error, Notifier = new AirbrakeNotifier { Name = "sharpbrake", Version = "2.2", Url = "http://github.com/asbjornu/SharpBrake" }, ServerEnvironment = new AirbrakeServerEnvironment("staging") { ProjectRoot = "/test", }, }; var serializer = new CleanXmlSerializer <AirbrakeNotice>(); string xml = serializer.ToXml(notice); AirbrakeValidator.ValidateSchema(xml); }
public void Notice_contains_Request() { AirbrakeNotice notice = null; const string url = "http://example.com/?Query.Key1=Query.Value1&Query.Key2=Query.Value2"; const string referer = "http://github.com/"; string physicalApplicationPath = Environment.CurrentDirectory + Path.DirectorySeparatorChar; var httpSimulator = new HttpSimulator("/", physicalApplicationPath) .SetFormVariable("Form.Key1", "Form.Value1") .SetFormVariable("Form.Key2", "Form.Value2") .SetHeader("Header.Key1", "Header.Value1") .SetHeader("Header.Key2", "Header.Value2") .SetReferer(new Uri(referer)) .SimulateRequest(new Uri(url)); using (httpSimulator) { try { Thrower.Throw(new Exception("Halp!")); } catch (Exception exception) { AirbrakeError error = this.builder.ErrorFromException(exception); notice = this.builder.Notice(error); } } Console.WriteLine(CleanXmlSerializer.ToXml(notice)); Assert.That(notice, Is.Not.Null); Assert.That(notice.Error, Is.Not.Null); #if !NET35 // We have defined a NET35 constant in the Visual Studio 2008 project so the below code isn't executed, // since it requires HttpSimulator which in turn requires .NET 4.0, which in turn requires Visual Studio 2010. Assert.That(notice.Request, Is.Not.Null); Assert.That(notice.Request.Url, Is.EqualTo(url)); Assert.That(notice.Request.Component, Is.EqualTo(typeof(Thrower).FullName)); Assert.That(notice.Request.Action, Is.EqualTo("Throw")); Assert.That(notice.Request.CgiData, Contains.Item(new AirbrakeVar("Content-Type", "application/x-www-form-urlencoded"))); Assert.That(notice.Request.CgiData, Contains.Item(new AirbrakeVar("Header.Key1", "Header.Value1"))); Assert.That(notice.Request.CgiData, Contains.Item(new AirbrakeVar("Header.Key2", "Header.Value2"))); Assert.That(notice.Request.CgiData, Contains.Item(new AirbrakeVar("Referer", referer))); Assert.That(notice.Request.Params, Contains.Item(new AirbrakeVar("APPL_PHYSICAL_PATH", physicalApplicationPath))); Assert.That(notice.Request.Params, Contains.Item(new AirbrakeVar("QUERY_STRING", "Query.Key1=Query.Value1&Query.Key2=Query.Value2"))); Assert.That(notice.Request.Params, Contains.Item(new AirbrakeVar("Form.Key1", "Form.Value1"))); Assert.That(notice.Request.Params, Contains.Item(new AirbrakeVar("Form.Key2", "Form.Value2"))); Assert.That(notice.Request.Params, Contains.Item(new AirbrakeVar("Query.Key1", "Query.Value1"))); Assert.That(notice.Request.Params, Contains.Item(new AirbrakeVar("Query.Key2", "Query.Value2"))); #endif }
public void Maximal_notice_generates_valid_XML() { var error = Activator.CreateInstance <AirbrakeError>(); error.Class = "TestError"; error.Message = "something blew up"; error.Backtrace = new[] { new AirbrakeTraceLine("unknown.cs", 0) { Method = "unknown" } }; var notice = new AirbrakeNotice { ApiKey = "123456", Error = error, Request = new AirbrakeRequest(new Uri("http://example.com/"), GetType().FullName) { Action = "Maximal_notice_generates_valid_XML", Component = "MyApp.HomeController", CgiData = new[] { new AirbrakeVar("REQUEST_METHOD", "POST"), }, Params = new[] { new AirbrakeVar("Form.Key1", "Form.Value1"), }, Session = new[] { new AirbrakeVar("UserId", "1"), }, Url = "http://example.com/myapp", }, Notifier = new AirbrakeNotifier { Name = "sharpbrake", Version = "2.2", Url = "http://github.com/asbjornu/SharpBrake", }, ServerEnvironment = new AirbrakeServerEnvironment("staging") { ProjectRoot = "/test", }, }; var serializer = new CleanXmlSerializer <AirbrakeNotice>(); string xml = serializer.ToXml(notice); AirbrakeValidator.ValidateSchema(xml); }
public void XmlContainsNoFluff() { var notice = new TestNotice { ApiKey = "123456", Version = "2.0" }; var serializer = new CleanXmlSerializer<TestNotice>(); var xml = serializer.ToXml(notice); Assert.AreEqual(xml, "<notice version=\"2.0\"><api-key>123456</api-key></notice>"); }
public void Xml_contains_no_fluff() { var notice = new TestNotice { ApiKey = "123456", Version = "2.0" }; var serializer = new CleanXmlSerializer<TestNotice>(); string xml = serializer.ToXml(notice); const string expected = @"<notice version=""2.0""><api-key>123456</api-key></notice>"; Assert.AreEqual(expected, xml); }
public void Maximal_notice_generates_valid_XML() { var error = Activator.CreateInstance<AirbrakeError>(); error.Class = "TestError"; error.Message = "something blew up"; error.Backtrace = new[] { new AirbrakeTraceLine("unknown.cs", 0, "unknown") }; var notice = new AirbrakeNotice { ApiKey = "123456", Error = error, Request = new AirbrakeRequest("http://example.com/", GetType().FullName, "Maximal_notice_generates_valid_XML") { Component = "MyApp.HomeController", CgiData = new[] { new AirbrakeVar("REQUEST_METHOD", "POST") }, Params = new[] { new AirbrakeVar("Form.Key1", "Form.Value1") }, Session = new[] { new AirbrakeVar("UserId", "1") }, Url = "http://example.com/myapp", }, Notifier = new AirbrakeNotifier { Name = "sharpbrake", Version = "2.2", Url = "http://github.com/asbjornu/SharpBrake", }, ServerEnvironment = new AirbrakeServerEnvironment("staging") { ProjectRoot = "/test", }, }; var serializer = new CleanXmlSerializer<AirbrakeNotice>(); var xml = serializer.ToXml(notice); Util.ValidateSchema(xml); }
private void SetRequestBody(WebRequest request, AirbrakeNotice notice) { var serializer = new CleanXmlSerializer <AirbrakeNotice>(); string xml = serializer.ToXml(notice); this.log.Debug(f => f("Sending the following to '{0}':\n{1}", request.RequestUri, xml)); byte[] payload = Encoding.UTF8.GetBytes(xml); request.ContentLength = payload.Length; using (Stream stream = request.GetRequestStream()) { stream.Write(payload, 0, payload.Length); } }
public void Xml_contains_no_fluff() { var notice = new TestNotice { ApiKey = "123456", Version = "2.0" }; var serializer = new CleanXmlSerializer <TestNotice>(); string xml = serializer.ToXml(notice); const string expected = @"<notice version=""2.0""> <api-key>123456</api-key> </notice>"; Assert.AreEqual(expected, xml); }
public void Notice_missing_error_fails_validation() { var notice = new AirbrakeNotice { ApiKey = "123456", Request = new AirbrakeRequest(new Uri("http://example.com/"), GetType().FullName) { Action = "Maximal_notice_generates_valid_XML", }, Notifier = new AirbrakeNotifier { Name = "hopsharp", Version = "2.0", Url = "http://github.com/krobertson/hopsharp" }, ServerEnvironment = new AirbrakeServerEnvironment("staging") { ProjectRoot = "/test", }, }; var serializer = new CleanXmlSerializer<AirbrakeNotice>(); string xml = serializer.ToXml(notice); TestDelegate throwing = () => AirbrakeValidator.ValidateSchema(xml); XmlSchemaValidationException exception = Assert.Throws<XmlSchemaValidationException>(throwing); Assert.That(exception.Message, Is.StringContaining("notice")); Assert.That(exception.Message, Is.StringContaining("error")); Assert.That(exception.LineNumber, Is.EqualTo(17)); Assert.That(exception.LinePosition, Is.EqualTo(3)); }
private void SetRequestBody(WebRequest request, AirbrakeNotice notice) { var serializer = new CleanXmlSerializer<AirbrakeNotice>(); string xml = serializer.ToXml(notice); //this.log.Debug(f => f("Sending the following to '{0}':\n{1}", request.RequestUri, xml)); byte[] payload = Encoding.UTF8.GetBytes(xml); request.ContentLength = payload.Length; using (Stream stream = request.GetRequestStream()) { stream.Write(payload, 0, payload.Length); } }
public void Minimal_notice_with_request_generates_valid_XML() { var error = Activator.CreateInstance<AirbrakeError>(); error.Class = "TestError"; error.Message = "something blew up"; error.Backtrace = new[] { new AirbrakeTraceLine("unknown.cs", 0, "unknown") }; var notice = new AirbrakeNotice { ApiKey = "123456", Error = error, Request = new AirbrakeRequest("http://example.com/", GetType().FullName, "") { Session = new AirbrakeVar[0] }, Notifier = new AirbrakeNotifier { Name = "sharpbrake", Version = "2.2", Url = "http://github.com/asbjornu/SharpBrake" }, ServerEnvironment = new AirbrakeServerEnvironment("staging") { ProjectRoot = "/test", }, }; var serializer = new CleanXmlSerializer<AirbrakeNotice>(); var xml = serializer.ToXml(notice); Util.ValidateSchema(xml); }
private void SetRequestBody(WebRequest request, AirbrakeNotice notice) { var serializer = new CleanXmlSerializer<AirbrakeNotice>(); string xml = serializer.ToXml(notice); //string validationErrors; //if(!AirbrakeValidator.IsValidXml(xml,out validationErrors)) // this.log.Debug(f => f("Schema validation errors '{0}':\n{1}\n:{2}", request.RequestUri, xml, validationErrors)); "Sending the following to '{0}':\n{1}".TraceDebug(request.RequestUri, xml); byte[] payload = Encoding.UTF8.GetBytes(xml); request.ContentLength = payload.Length; using (Stream stream = request.GetRequestStream()) { stream.Write(payload, 0, payload.Length); } }
public void Notice_missing_error_fails_validation() { var notice = new AirbrakeNotice { ApiKey = "123456", Request = new AirbrakeRequest("http://example.com/", GetType().FullName, "") { Action = "Maximal_notice_generates_valid_XML", }, Notifier = new AirbrakeNotifier { Name = "sharpbrake", Version = "2.2", Url = "http://github.com/asbjornu/SharpBrake" }, ServerEnvironment = new AirbrakeServerEnvironment("staging") { ProjectRoot = "/test", }, }; var serializer = new CleanXmlSerializer<AirbrakeNotice>(); var xml = serializer.ToXml(notice); TestDelegate throwing = () => Util.ValidateSchema(xml); var exception = Assert.Throws<XmlSchemaValidationException>(throwing); Console.WriteLine(exception); Assert.That(exception.Message, Is.StringContaining("notice")); Assert.That(exception.Message, Is.StringContaining("error")); Assert.That(exception.LineNumber, Is.EqualTo(18)); Assert.That(exception.LinePosition, Is.EqualTo(3)); }
public void NoticeMissingErrorFailsValidation() { var notice = new AirbrakeNotice { ApiKey = "123456", Request = new AirbrakeRequest(new Uri("http://example.com/"), GetType().FullName) { Action = "NoticeMissingErrorFailsValidation", }, Notifier = new AirbrakeNotifier { Name = "sharpbrake", Version = "2.2.2.0", Url = "https://github.com/airbrake/SharpBrake" }, ServerEnvironment = new AirbrakeServerEnvironment("staging") { ProjectRoot = "/test", }, }; var serializer = new CleanXmlSerializer<AirbrakeNotice>(); var xml = serializer.ToXml(notice); TestDelegate throwing = () => AirbrakeValidator.ValidateSchema(xml); var exception = Assert.Throws<XmlSchemaValidationException>(throwing); Console.WriteLine(exception); Assert.That(exception.Message, Is.StringContaining("notice")); Assert.That(exception.Message, Is.StringContaining("error")); }
public void MaximalNoticeGeneratesValidXml() { var error = new AirbrakeError { Class = "TestError", Message = "something blew up", Backtrace = new[] { new AirbrakeTraceLine("unknown.cs", 0) { Method = "unknown" } } }; var notice = new AirbrakeNotice { ApiKey = "123456", Error = error, Request = new AirbrakeRequest(new Uri("http://example.com/"), GetType().FullName) { Action = "MaximalNoticeGeneratesValidXml", Component = "MyApp.HomeController", Url = "http://example.com/myapp", CgiData = new[] { new AirbrakeVar("REQUEST_METHOD", "POST"), }, Params = new[] { new AirbrakeVar("Form.Key1", "Form.Value1"), }, Session = new[] { new AirbrakeVar("UserId", "1"), }, }, Notifier = new AirbrakeNotifier { Name = "sharpbrake", Version = "2.2.2.0", Url = "https://github.com/airbrake/SharpBrake", }, ServerEnvironment = new AirbrakeServerEnvironment("staging") { ProjectRoot = "/test", }, }; var serializer = new CleanXmlSerializer<AirbrakeNotice>(); var xml = serializer.ToXml(notice); AirbrakeValidator.ValidateSchema(xml); }
public void MinimalNoticeGeneratesValidXml() { var error = new AirbrakeError { Class = "TestError", Message = "something blew up", Backtrace = new[] { new AirbrakeTraceLine("unknown.cs", 0) { Method = "unknown" } } }; var notice = new AirbrakeNotice { ApiKey = "123456", Error = error, Notifier = new AirbrakeNotifier { Name = "sharpbrake", Version = "2.2.2.0", Url = "https://github.com/airbrake/SharpBrake" }, ServerEnvironment = new AirbrakeServerEnvironment("staging") { ProjectRoot = "/test", }, }; var serializer = new CleanXmlSerializer<AirbrakeNotice>(); var xml = serializer.ToXml(notice); AirbrakeValidator.ValidateSchema(xml); }
public void Minimal_notice_generates_valid_XML() { var error = Activator.CreateInstance<AirbrakeError>(); error.Class = "TestError"; error.Message = "something blew up"; error.Backtrace = new[] { new AirbrakeTraceLine("unknown.cs", 0) { Method = "unknown" } }; var notice = new AirbrakeNotice { ApiKey = "123456", Error = error, Notifier = new AirbrakeNotifier { Name = "sharpbrake", Version = "2.2", Url = "http://github.com/asbjornu/SharpBrake" }, ServerEnvironment = new AirbrakeServerEnvironment("staging") { ProjectRoot = "/test", }, }; var serializer = new CleanXmlSerializer<AirbrakeNotice>(); string xml = serializer.ToXml(notice); AirbrakeValidator.ValidateSchema(xml); }
private static void SetRequestBody(WebRequest request, HoptoadNotice notice) { var serializer = new CleanXmlSerializer<HoptoadNotice>(); string xml = serializer.ToXml(notice); byte[] payload = Encoding.UTF8.GetBytes(xml); request.ContentLength = payload.Length; using (Stream stream = request.GetRequestStream()) { stream.Write(payload, 0, payload.Length); stream.Close(); } }
private string SetRequestBody(HttpWebRequest request, HoptoadNotice notice) { var serializer = new CleanXmlSerializer<HoptoadNotice>(); var xml = ""; if (this.builder.Configuration.UseRedMine == true) xml = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n" + serializer.ToXml(notice); else xml = serializer.ToXml(notice); var payload = Encoding.UTF8.GetBytes(xml); request.ContentLength = payload.Length; //HttpWebResponse HttpWResp = (HttpWebResponse)request.GetResponse(); // Insert code that uses the response object. // HttpWResp.Close(); using (var stream = request.GetRequestStream()) { stream.Write(payload, 0, payload.Length); stream.Close(); } try { HttpWebResponse response = (HttpWebResponse)request.GetResponse(); StreamReader reader = new StreamReader(response.GetResponseStream()); string contents = reader.ReadToEnd(); reader.Close(); return contents; } catch (Exception e) { return string.Format("RedHopToad Error {0}: Bug not reported", e.Message); } }