public void AggregateExceptionsAreSerialized() { var converter = new LogEventConverter(null); Exception innerException = null; try { try { ThrowException(); } catch (Exception e) { innerException = e; throw new AggregateException(e, e); } } catch (AggregateException e) { var evt = new LogEvent(DateTimeOffset.UtcNow, LogEventLevel.Error, e, new MessageTemplate("Hello", Enumerable.Empty <MessageTemplateToken>()), Enumerable.Empty <LogEventProperty>()); var logglyEvent = converter.CreateLogglyEvent(evt); var exceptionnDetails = logglyEvent.Data["Exception"] as ExceptionDetails; Assert.Equal(2, exceptionnDetails.InnerExceptions.Length); Assert.Equal(innerException.Message, exceptionnDetails.InnerExceptions[0].Message); Assert.Equal(innerException.Message, exceptionnDetails.InnerExceptions[1].Message); } }
/// <summary> /// Reads the given Journal file from specified position and generates the events /// </summary> /// <param name="textReader">Stream reader for input data</param> /// <returns>Sequence of events read from input</returns> public IEnumerable <LogEvent> ReadEventsFromStream(TextReader textReader) { if (textReader == null) { throw new ArgumentNullException(nameof(textReader)); } using (var jsonReader = new JsonTextReader(textReader) { SupportMultipleContent = true, CloseInput = false }) { while (jsonReader.Read()) { var @object = Converter.Serializer.Deserialize <JObject>(jsonReader); LogEvent @event = null; try { @event = LogEventConverter.Convert(@object); } catch (Exception e) { Log.Error(e, "Error deserializing event from journal"); } if (@event != null) { yield return(@event); } } } }
public void EventsTransformationShouldNotSpoilData(JObject source) { var @event = LogEventConverter.Convert(source); if (@event.GetType() == typeof(LogEvent)) { Assert.Pass("Automatic pass for non-typed events"); } if (@event is FsdJump || @event is Location || @event is Docked) { source.Remove("StationFaction"); source.Remove("SystemFaction"); source.Remove("FactionState"); } // TODO: return those fields to objects var serialized = JObject.FromObject(@event, Converter.Serializer); if (@event is Scan) { source.Remove("Parents"); // TODO: find a way to serialize that structure } Assert.IsEmpty(JsonComparer.Compare(@event.Event, source, serialized)); // This assert should never trigger - if it triggers means there's an error in comparison code Assert.IsTrue(JToken.DeepEquals(source, serialized), "Json objects before/after serialization should be 'DeepEqual'"); }
public void ShouldConvertFsdJumpEvent() { string eventString = @"{""timestamp"":""2018-06-25T18:10:30Z"", ""event"":""FSDJump"", ""StarSystem"":""Shinrarta Dezhra"", ""SystemAddress"":3932277478106, ""StarPos"":[55.71875, 17.59375, 27.15625 ], ""SystemAllegiance"":""PilotsFederation"", ""SystemEconomy"":""$economy_HighTech;"", ""SystemEconomy_Localised"":""High Tech"", ""SystemSecondEconomy"":""$economy_Industrial;"", ""SystemSecondEconomy_Localised"":""Industrial"", ""SystemGovernment"":""$government_Democracy;"", ""SystemGovernment_Localised"":""Democracy"", ""SystemSecurity"":""$SYSTEM_SECURITY_high;"", ""SystemSecurity_Localised"":""High Security"", ""Population"":85206935, ""JumpDist"":11.896, ""FuelUsed"":2.983697, ""FuelLevel"":12.767566, ""Factions"":[{""Name"":""Lori Jameson"", ""FactionState"":""None"", ""Government"":""Engineer"", ""Influence"":0.000000, ""Allegiance"":""Independent""} ], ""SystemFaction"":""Pilots Federation Local Branch""}"; var @event = (FsdJump)LogEventConverter.Convert(JObject.Parse(eventString)); Assert.AreEqual(new DateTime(2018, 06, 25, 18, 10, 30, DateTimeKind.Utc), @event.Timestamp); }
public static void ToolGetUnmappedEvents() { var events = TestEventSource.LocalEvents .Concat(TestEventSource.LocalBetaEvents) .Select(e => { try { return(LogEventConverter.Convert(e)); } catch { return(null); } }) .Where(e => e != null && e.GetType() == typeof(LogEvent)) .Select(e => e.Event) .Distinct() .OrderBy(x => x) .ToList(); Assert.Pass(string.Join(", ", events)); }
public void ShouldConvertLocalEvents() { var events = TestEventSource.LocalBetaEvents.Concat(TestEventSource.LocalEvents).ToList(); events.ForEach(x => LogEventConverter.Convert(x)); }