public async Task SendEventsAsync_WhenSplunkHttpEventCollectorClientThrows_ReportsProblem() { // Arrange var splunkHttpEventCollectorClient = new Mock <ISplunkHttpEventCollectorClient>(); var healthReporter = new Mock <IHealthReporter>(); var events = new ReadOnlyCollection <EventData>(new List <EventData>()); var cancellationToken = new CancellationToken(); splunkHttpEventCollectorClient .Setup(c => c.SendEventsAsync(events, cancellationToken)) .Throws <Exception>(); healthReporter .Setup(r => r.ReportProblem(It.IsAny <string>(), It.IsAny <string>())) .Verifiable(); // Act var splunkOutput = new SplunkOutput(splunkHttpEventCollectorClient.Object, healthReporter.Object); await splunkOutput.SendEventsAsync(events, 0, cancellationToken); // Assert splunkHttpEventCollectorClient.Verify(); healthReporter.Verify(); }
public async Task SendEventsAsync_WhenSplunkHttpEventCollectorClientIsSuccessful_ReportsHealthy() { // Arrange var splunkHttpEventCollectorClient = new Mock <ISplunkHttpEventCollectorClient>(); var healthReporter = new Mock <IHealthReporter>(); var events = new ReadOnlyCollection <EventData>(new List <EventData>()); var cancellationToken = new CancellationToken(); splunkHttpEventCollectorClient .Setup(c => c.SendEventsAsync(events, cancellationToken)) .Returns(Task.CompletedTask) .Verifiable(); healthReporter .Setup(r => r.ReportHealthy(It.IsAny <string>(), It.IsAny <string>())) .Verifiable(); // Act var splunkOutput = new SplunkOutput(splunkHttpEventCollectorClient.Object, healthReporter.Object); await splunkOutput.SendEventsAsync(events, 0, cancellationToken); // Assert splunkHttpEventCollectorClient.Verify(); healthReporter.Verify(); }