public async Task SendAsync_SentryTraceHeaderAlreadySet_NotOverwritten() { // Arrange var hub = Substitute.For <IHub>(); hub.GetTraceHeader().ReturnsForAnyArgs( SentryTraceHeader.Parse("75302ac48a024bde9a3b3734a82e36c8-1000000000000000-0") ); using var innerHandler = new FakeHttpClientHandler(); using var sentryHandler = new SentryHttpMessageHandler(innerHandler, hub); using var client = new HttpClient(sentryHandler); client.DefaultRequestHeaders.Add("sentry-trace", "foobar"); // Act await client.GetAsync("https://example.com"); using var request = innerHandler.GetRequests().Single(); // Assert request.Headers.Should().Contain(h => h.Key == "sentry-trace" && string.Concat(h.Value) == "foobar" ); }
public async Task SendEnvelopeAsync_AttachmentTooLarge_DropsItem() { // Arrange using var httpHandler = new FakeHttpClientHandler( _ => SentryResponses.GetOkResponse() ); var logger = new AccumulativeDiagnosticLogger(); var httpTransport = new HttpTransport( new SentryOptions { Dsn = DsnSamples.ValidDsnWithSecret, MaxAttachmentSize = 1, DiagnosticLogger = logger, Debug = true }, new HttpClient(httpHandler) ); var attachmentNormal = new Attachment( AttachmentType.Default, new StreamAttachmentContent(new MemoryStream(new byte[] { 1 })), "test1.txt", null ); var attachmentTooBig = new Attachment( AttachmentType.Default, new StreamAttachmentContent(new MemoryStream(new byte[] { 1, 2, 3, 4, 5 })), "test2.txt", null ); using var envelope = Envelope.FromEvent( new SentryEvent(), new[] { attachmentNormal, attachmentTooBig } ); // Act await httpTransport.SendEnvelopeAsync(envelope); var lastRequest = httpHandler.GetRequests().Last(); var actualEnvelopeSerialized = await lastRequest.Content.ReadAsStringAsync(); // Assert // (the envelope should have only one item) logger.Entries.Should().Contain(e => e.Message == "Attachment '{0}' dropped because it's too large ({1} bytes)." && e.Args[0].ToString() == "test2.txt" && e.Args[1].ToString() == "5" ); actualEnvelopeSerialized.Should().NotContain("test2.txt"); }
private HttpClient CreateClient <T>(HttpStatusCode statusCode, T content, string baseUri = null) where T : class { var handler = new FakeHttpClientHandler <T>(statusCode, content); var client = new HttpClient(handler); if (baseUri != null) { client.BaseAddress = new Uri(baseUri); } return(client); }
public void GetWorkspacesIndividualScope_Throttled() { // Arrange var clientHandler = new FakeHttpClientHandler(new System.Net.Http.HttpResponseMessage((System.Net.HttpStatusCode) 429)); var initFactory = new TestPowerBICmdletInitFactory(clientHandler); var cmdlet = new GetPowerBIWorkspace(initFactory); // Act cmdlet.InvokePowerBICmdlet(); // Assert Assert.Fail("Should not have reached this point"); }
public async Task SendEnvelopeAsync_ItemRateLimit_DropsItem() { // Arrange using var httpHandler = new FakeHttpClientHandler( _ => SentryResponses.GetRateLimitResponse("1234:event, 897:transaction") ); var httpTransport = new HttpTransport( new SentryOptions { Dsn = DsnSamples.ValidDsnWithSecret }, new HttpClient(httpHandler) ); // First request always goes through await httpTransport.SendEnvelopeAsync(Envelope.FromEvent(new SentryEvent())); var envelope = new Envelope( new Dictionary <string, object>(), new[] { // Should be dropped new EnvelopeItem( new Dictionary <string, object> { ["type"] = "event" }, new EmptySerializable()), new EnvelopeItem( new Dictionary <string, object> { ["type"] = "event" }, new EmptySerializable()), new EnvelopeItem( new Dictionary <string, object> { ["type"] = "transaction" }, new EmptySerializable()), // Should stay new EnvelopeItem( new Dictionary <string, object> { ["type"] = "other" }, new EmptySerializable()) } ); var expectedEnvelope = new Envelope( new Dictionary <string, object>(), new[] { new EnvelopeItem( new Dictionary <string, object> { ["type"] = "other" }, new EmptySerializable()) } ); var expectedEnvelopeSerialized = await expectedEnvelope.SerializeToStringAsync(); // Act await httpTransport.SendEnvelopeAsync(envelope); var lastRequest = httpHandler.GetRequests().Last(); var actualEnvelopeSerialized = await lastRequest.Content.ReadAsStringAsync(); // Assert actualEnvelopeSerialized.Should().BeEquivalentTo(expectedEnvelopeSerialized); }