public async Task SendEventsAsync_WithNonEmptyEvents_CallsHttpEventCollectorApi() { // Arrange var splunkOutputConfiguration = new SplunkOutputConfiguration() { ServiceBaseAddress = "https://hec.mysplunkserver.com:8088", AuthenticationToken = "B5A79AAD-D822-46CC-80D1-819F80D7BFB0", Host = "MY-COMPUTER" }; var uriExpected = new Uri("https://hec.mysplunkserver.com:8088/services/collector/event/1.0"); var fakeResponseHandler = new FakeResponseHandler(); fakeResponseHandler.AddFakeResponse( uriExpected, new HttpResponseMessage(HttpStatusCode.OK)); var httpClient = new HttpClient(fakeResponseHandler); var events = new ReadOnlyCollection <EventData>(new List <EventData>() { new EventData() { Level = LogLevel.Error, ProviderName = "MyNamespace.MyClass", Payload = { new KeyValuePair <string, object>("MyKey", "MyValue") } } }); var cancellationToken = new CancellationToken(); // Act var splunkHttpEventCollectorClient = new SplunkHttpEventCollectorClient(httpClient, splunkOutputConfiguration); await splunkHttpEventCollectorClient.SendEventsAsync(events, cancellationToken); // Assert Assert.Equal(1, fakeResponseHandler.GetResponseCallCount(uriExpected)); }
public SplunkHttpEventCollectorClient( HttpClient httpClient, SplunkOutputConfiguration configuration) { this.httpClient = httpClient; this.configuration = configuration; httpClient.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue(AuthorizationHeaderScheme, configuration.AuthenticationToken); httpClient.BaseAddress = new Uri(configuration.ServiceBaseAddress, UriKind.Absolute); }
public async Task SendEventsAsync_WhenApiReturnsErrorResponse_Throws() { // Arrange var splunkOutputConfiguration = new SplunkOutputConfiguration() { ServiceBaseAddress = "https://hec.mysplunkserver.com:8088", AuthenticationToken = "B5A79AAD-D822-46CC-80D1-819F80D7BFB0", Host = "MY-COMPUTER" }; var uriExpected = new Uri("https://hec.mysplunkserver.com:8088/services/collector/event/1.0"); var fakeResponseHandler = new FakeResponseHandler(); fakeResponseHandler.AddFakeResponse( uriExpected, new HttpResponseMessage(HttpStatusCode.ServiceUnavailable) { ReasonPhrase = "Service Unavailable", Content = new StringContent( "Something bad happened", Encoding.UTF8, "application/json") }); var httpClient = new HttpClient(fakeResponseHandler); var events = new ReadOnlyCollection <EventData>(new List <EventData>() { new EventData() { Level = LogLevel.Error, ProviderName = "MyNamespace.MyClass", Payload = { new KeyValuePair <string, object>("MyKey", "MyValue") } } }); var cancellationToken = new CancellationToken(); // Act var splunkHttpEventCollectorClient = new SplunkHttpEventCollectorClient(httpClient, splunkOutputConfiguration); await Assert.ThrowsAnyAsync <Exception>(() => splunkHttpEventCollectorClient.SendEventsAsync(events, cancellationToken)); // Assert Assert.Equal(1, fakeResponseHandler.GetResponseCallCount(uriExpected)); }
public SplunkHttpMessageHandlerFactory(SplunkOutputConfiguration configuration) { maxRetryAttempts = configuration.MaxRetryAttempts; ignoreSslCertificateErrors = configuration.IgnoreSslCertificateErrors; }