public async Task CaptureEventAsync_ResponseNotOkNoMessage_CallbackFired() { const HttpStatusCode expectedCode = HttpStatusCode.BadGateway; var expectedEvent = new SentryEvent(); _fixture.SentryOptions.DiagnosticLogger.IsEnabled(SentryLevel.Error).Returns(true); _fixture.HttpMessageHandler.VerifyableSendAsync(Arg.Any <HttpRequestMessage>(), Arg.Any <CancellationToken>()) .Returns(_ => SentryResponses.GetErrorResponse(expectedCode, null)); var sut = _fixture.GetSut(); await sut.CaptureEventAsync(expectedEvent); _fixture.SentryOptions.DiagnosticLogger.Received(1).Log(SentryLevel.Error, "Sentry rejected the event {0}. Status code: {1}. Sentry response: {2}", null, Arg.Is <object[]>(p => p[0].ToString() == expectedEvent.EventId.ToString() && p[1].ToString() == expectedCode.ToString() && p[2].ToString() == HttpTransport.NoMessageFallback)); }
public async Task SendEnvelopeAsync_ResponseNotOkWithMessage_LogsError() { // Arrange const HttpStatusCode expectedCode = HttpStatusCode.BadGateway; const string expectedMessage = "Bad Gateway!"; var httpHandler = Substitute.For <MockableHttpMessageHandler>(); httpHandler.VerifyableSendAsync(Arg.Any <HttpRequestMessage>(), Arg.Any <CancellationToken>()) .Returns(_ => SentryResponses.GetErrorResponse(expectedCode, expectedMessage)); var logger = new AccumulativeDiagnosticLogger(); var httpTransport = new HttpTransport( new SentryOptions { Dsn = DsnSamples.ValidDsnWithSecret, Debug = true, DiagnosticLogger = logger }, new HttpClient(httpHandler), _ => { } ); var envelope = Envelope.FromEvent(new SentryEvent()); // Act await httpTransport.SendEnvelopeAsync(envelope); // Assert logger.Entries.Any(e => e.Level == SentryLevel.Error && e.Message == "Sentry rejected the envelope {0}. Status code: {1}. Sentry response: {2}" && e.Exception == null && e.Args[0].ToString() == envelope.TryGetEventId().ToString() && e.Args[1].ToString() == expectedCode.ToString() && e.Args[2].ToString() == expectedMessage ).Should().BeTrue(); }
public async Task CaptureEventAsync_ResponseNotOkNoMessage_CallbackFired() { const HttpStatusCode expectedCode = HttpStatusCode.BadGateway; var expectedEvent = new SentryEvent(); var callbackInvoked = false; _fixture.HttpOptions.HandleFailedEventSubmission = (e, c, m) => { Assert.Same(e, expectedEvent); Assert.Equal(HttpTransport.NoMessageFallback, m); Assert.Equal(expectedCode, c); callbackInvoked = true; }; _fixture.HttpMessageHandler.VerifyableSendAsync(Arg.Any <HttpRequestMessage>(), Arg.Any <CancellationToken>()) .Returns(_ => SentryResponses.GetErrorResponse(expectedCode, null)); var sut = _fixture.GetSut(); await sut.CaptureEventAsync(expectedEvent); Assert.True(callbackInvoked); }