public void SinksScopeCreatedEvent() { // arrange var logger = new FakeLogger <LoggerSink>(); var options = Options.Create(new LoggerSinkOptions { }); var sink = new LoggerSink(logger, options); var evt = new FakeScopeCreatedEvent { ScopeId = Guid.NewGuid(), Name = Guid.NewGuid().ToString(), ParentScopeId = Guid.NewGuid(), Timestamp = DateTimeOffset.Now }; // act sink.Sink(evt); // assert Assert.Collection(logger.Items, x => { Assert.Equal(1, x.EventId.Id); Assert.Equal("ScopeCreated", x.EventId.Name); Assert.Equal(LogLevel.Information, x.LogLevel); Assert.Null(x.Exception); }); }
public void SinksTrackerCancelledEvent() { // arrange var logger = new FakeLogger <LoggerSink>(); var options = Options.Create(new LoggerSinkOptions { }); var sink = new LoggerSink(logger, options); var evt = new FakeTrackerCancelledEvent { ScopeId = Guid.NewGuid(), Timestamp = DateTimeOffset.Now, TrackerId = Guid.NewGuid(), Elapsed = TimeSpan.FromSeconds(123) }; // act sink.Sink(evt); // assert Assert.Collection(logger.Items, x => { Assert.Equal(7, x.EventId.Id); Assert.Equal("TrackerCancelled", x.EventId.Name); Assert.Equal(LogLevel.Error, x.LogLevel); Assert.Null(x.Exception); }); }
public void SinkThrowsOnNullTrackingEvent() { // arrange var logger = new FakeLogger <LoggerSink>(); var options = Options.Create(new LoggerSinkOptions()); var sink = new LoggerSink(logger, options); ITrackingEvent trackingEvent = null; // act var ex = Assert.Throws <ArgumentNullException>(() => sink.Sink(trackingEvent)); // assert Assert.Equal(nameof(trackingEvent), ex.ParamName); }
public void SinkThrowsOnUnknownEvent() { // arrange var logger = new FakeLogger <LoggerSink>(); var options = Options.Create(new LoggerSinkOptions { }); var sink = new LoggerSink(logger, options); var evt = Mock.Of <ITrackingEvent>(); // act var ex = Assert.Throws <InvalidOperationException>(() => sink.Sink(evt)); // assert Assert.Contains(evt.GetType().Name, ex.Message, StringComparison.Ordinal); }