public void SerializedJsonPacket_WithValidData_IsValid() { var exception = TestHelper.GetException(); // TODO: This packet should preferably be "complete", i.e. contain as much information as possible. --asbjornu JsonPacket packet = new JsonPacket("https://*****:*****@app.getsentry.com/1337", exception) { Level = ErrorLevel.Fatal, Tags = new Dictionary <string, string> { { "key1", "value1" }, { "key2", "value2" }, }, Request = new SentryRequest { QueryString = "?a=b&c=d", Data = new { A = true, B = 1, C = "Hello" } } }; JObject jPacket = JObject.Parse(packet.ToString()); JsonSchema schema = SchemaHelper.GetSchema(); jPacket.Validate(schema, (s, e) => Console.WriteLine(e.Message)); Console.WriteLine(jPacket); var valid = jPacket.IsValid(schema); Assert.That(valid, Is.True); }
public void Validate_JsonPacketWithMissingLevel_IsNotValid() { const string json = @"{ ""tags"": { ""key1"": ""value1"", ""key2"": ""value2"" }, ""event_id"": ""8ee5d717693b402d93c04aea0107ea60"", ""project"": ""https://*****:*****@app.getsentry.com/1337"", ""culprit"": ""SharpRaven.UnitTests.TestHelper in PerformDivideByZero"", ""timestamp"": ""2013-12-04T09:28:34.7802734Z"", ""logger"": ""root"", ""platform"": ""csharp"", ""message"": ""Attempted to divide by zero."", ""server_name"": ""AUL-PC"", ""exception"": [ { ""type"": ""DivideByZeroException"", ""value"": ""Attempted to divide by zero."", ""module"": ""SharpRaven.UnitTests"", ""stacktrace"": { ""frames"": [ { ""abs_path"": null, ""filename"": ""c:\\Users\\aul\\Dev\\Misc\\raven-csharp\\SharpRaven.UnitTests\\TestHelper.cs"", ""module"": ""SharpRaven.UnitTests.TestHelper"", ""function"": ""GetException"", ""vars"": null, ""pre_context"": null, ""context_line"": ""System.Exception GetException()"", ""lineno"": 18, ""colno"": 17, ""in_app"": false, ""post_context"": null }, { ""abs_path"": null, ""filename"": ""c:\\Users\\aul\\Dev\\Misc\\raven-csharp\\SharpRaven.UnitTests\\TestHelper.cs"", ""module"": ""SharpRaven.UnitTests.TestHelper"", ""function"": ""PerformDivideByZero"", ""vars"": null, ""pre_context"": null, ""context_line"": ""Void PerformDivideByZero()"", ""lineno"": 10, ""colno"": 13, ""in_app"": false, ""post_context"": null } ] } } ] }"; JObject jPacket = JObject.Parse(json); JsonSchema schema = SchemaHelper.GetSchema(); // This should output something like "Required properties are missing from object: level." jPacket.Validate(schema, (s, e) => Console.WriteLine(e.Message)); Console.WriteLine(jPacket); var valid = jPacket.IsValid(schema); Assert.That(valid, Is.False); }