diff --git a/test/Sentry.Tests/Internals/Http/HttpTransportTests.ProcessEnvelope_ShouldAttachClientReport.verified.txt b/test/Sentry.Tests/Internals/Http/HttpTransportTests.ProcessEnvelope_ShouldAttachClientReport.verified.txt new file mode 100644 index 0000000000..6d79f37bd9 --- /dev/null +++ b/test/Sentry.Tests/Internals/Http/HttpTransportTests.ProcessEnvelope_ShouldAttachClientReport.verified.txt @@ -0,0 +1,34 @@ +{ + clientReportJson: { + discarded_events: [ + { + category: internal, + quantity: 1, + reason: network_error + }, + { + category: security, + quantity: 1, + reason: network_error + }, + { + category: error, + quantity: 2, + reason: queue_overflow + }, + { + category: transaction, + quantity: 3, + reason: ratelimit_backoff + } + ], + timestamp: Date_MaxValue + }, + eventItemJson: { + event_id: Guid_1, + platform: csharp, + sdk: {}, + sent_at: DateTime_1, + timestamp: DateTime_2 + } +} \ No newline at end of file diff --git a/test/Sentry.Tests/Internals/Http/HttpTransportTests.cs b/test/Sentry.Tests/Internals/Http/HttpTransportTests.cs index c5393c2ab2..2053ec52c4 100644 --- a/test/Sentry.Tests/Internals/Http/HttpTransportTests.cs +++ b/test/Sentry.Tests/Internals/Http/HttpTransportTests.cs @@ -8,6 +8,7 @@ namespace Sentry.Tests.Internals.Http; +[UsesVerify] public class HttpTransportTests { [Fact] @@ -769,7 +770,7 @@ public async Task CreateRequest_Content_IncludesEvent() } [Fact] - public void ProcessEnvelope_ShouldAttachClientReport() + public Task ProcessEnvelope_ShouldAttachClientReport() { var options = new SentryOptions(); @@ -794,7 +795,6 @@ public void ProcessEnvelope_ShouldAttachClientReport() recorder.RecordDiscardedEvent(DiscardReason.RateLimitBackoff, DataCategory.Transaction); var sentryEvent = new SentryEvent(); - var expectedEventJson = EnvelopeItem.FromEvent(sentryEvent).Payload.SerializeToString(logger); var envelope = Envelope.FromEvent(sentryEvent); var processedEnvelope = httpTransport.ProcessEnvelope(envelope); @@ -808,21 +808,9 @@ public void ProcessEnvelope_ShouldAttachClientReport() Assert.Equal("event", eventItem.TryGetType()); Assert.Equal("client_report", clientReportItem.TryGetType()); - // The event should be unmodified - Assert.Equal(expectedEventJson, eventItem.Payload.SerializeToString(logger)); - - // The client report should contain the counts of the fake discards - const string expectedClientReportJson = - "{\"timestamp\":\"9999-12-31T23:59:59.9999999+00:00\"," + - "\"discarded_events\":[" + - "{\"reason\":\"network_error\",\"category\":\"internal\",\"quantity\":1}," + - "{\"reason\":\"network_error\",\"category\":\"security\",\"quantity\":1}," + - "{\"reason\":\"queue_overflow\",\"category\":\"error\",\"quantity\":2}," + - "{\"reason\":\"ratelimit_backoff\",\"category\":\"transaction\",\"quantity\":3}" + - "]}"; - + var eventItemJson = eventItem.Payload.SerializeToString(logger); var clientReportJson = clientReportItem.Payload.SerializeToString(logger); - Assert.Equal(expectedClientReportJson, clientReportJson); + return VerifyJson($"{{eventItemJson:{eventItemJson},clientReportJson:{clientReportJson}}}"); } [Fact]