public void LogStoresSentryIdInExceptionDataTest() { var expected = Guid.NewGuid().ToString(); var name = Guid.NewGuid().ToString(); var eventId = new EventId(Environment.TickCount); var state = new AddressState { Address = Guid.NewGuid().ToString() }; var exception = new TimeoutException(Guid.NewGuid().ToString()); exception.AddContextData(state.Address); var client = Substitute.For <IRavenClient>(); client.Capture(Arg.Any <SentryEvent>()).Returns(expected); var sut = new SentryLogger(name, client); sut.Log(LogLevel.Critical, eventId, state, exception, (logState, ex) => ex.ToString()); var actual = exception.Data["Sentry_Id"] as string; actual.Should().Be(expected); }
public void LogSendsMessageToSentryTest() { var name = Guid.NewGuid().ToString(); var sentryId = Guid.NewGuid().ToString(); var message = Guid.NewGuid().ToString(); var state = new AddressState { Address = Guid.NewGuid().ToString() }; var exception = new TimeoutException(Guid.NewGuid().ToString()); exception.AddContextData(state.Address); var client = Substitute.For <IRavenClient>(); client.Capture(Arg.Any <SentryEvent>()).Returns(sentryId); var sut = new SentryLogger(name, client); sut.LogError(exception, message); client.Received(1).Capture(Arg.Any <SentryEvent>()); client.Received().Capture(Arg.Is <SentryEvent>(x => x.Level == ErrorLevel.Error)); client.Received().Capture(Arg.Is <SentryEvent>(x => x.Exception == exception)); client.Received().Capture(Arg.Is <SentryEvent>(x => x.Message == exception.Message)); client.Logger.Should().Be(name); client.Received().Capture( Arg.Is <SentryEvent>(x => x.Exception.Data["FormattedMessage"].As <string>() == message)); }
public void LogSendsExceptionWithContextDataToSentryTest() { var name = Guid.NewGuid().ToString(); var sentryId = Guid.NewGuid().ToString(); var eventId = new EventId(Environment.TickCount); var state = new AddressState { Address = Guid.NewGuid().ToString() }; var exception = new TimeoutException(Guid.NewGuid().ToString()); exception.AddContextData(state.Address); var client = Substitute.For <IRavenClient>(); client.Capture(Arg.Any <SentryEvent>()).Returns(sentryId); var sut = new SentryLogger(name, client); sut.Log(LogLevel.Critical, eventId, state, exception, (logState, ex) => ex.ToString()); client.Received(1).Capture(Arg.Any <SentryEvent>()); client.Received().Capture( Arg.Is <SentryEvent>(x => x.Exception.Data["ContextData"].As <string>().Contains(state.Address))); }
public void AddContextDataThrowsExceptionWithNullData() { var sut = new TimeoutException(); Action action = () => sut.AddContextData(null); action.Should().Throw <ArgumentNullException>(); }
public void AddContextDataAppendsSerializedValueToException() { var value = Model.Create <Company>(); var expected = JsonConvert.SerializeObject(value, ExceptionData.SerializerSettings); var sut = new TimeoutException(); sut.AddContextData(value); var actual = sut.Data["ContextData"].As <string>(); _output.WriteLine("Stored context data is: {0}", actual); actual.Should().Be(expected); }
public void LogSendsToSentryWithoutNullFormattedMessageTest() { var name = Guid.NewGuid().ToString(); var sentryId = Guid.NewGuid().ToString(); var state = new AddressState { Address = Guid.NewGuid().ToString() }; var exception = new TimeoutException(Guid.NewGuid().ToString()); exception.AddContextData(state.Address); var client = Substitute.For <IRavenClient>(); client.Capture(Arg.Any <SentryEvent>()).Returns(sentryId); var sut = new SentryLogger(name, client); sut.LogError(exception, null); client.Received(1).Capture(Arg.Any <SentryEvent>()); client.Received().Capture( Arg.Is <SentryEvent>(x => x.Exception.Data.Contains("FormattedMessage") == false)); }