상속: System.Diagnostics.Tracing.EventListener
        public void ShouldRaiseFlushFailedOnFlushAsyncWhenEventHubClientFails()
        {
            var eventHubClient = Substitute.For<IEventHubClient>();
            using (var sink = new EventHubAmqpSink(eventHubClient, Buffering.DefaultBufferingInterval, Buffering.DefaultBufferingCount, Buffering.DefaultMaxBufferSize, TimeSpan.Zero))
            using (var collectErrorsListener = new MockEventListener())
            {
                collectErrorsListener.EnableEvents(SemanticLoggingEventSource.Log, EventLevel.Error, Keywords.All);
                eventHubClient.When(client => client.SendBatchAsync(Arg.Any<IEnumerable<EventData>>()))
                    .Do(action => { throw new Exception(); });

                sink.OnNext(EventEntryTestHelper.Create());

                try
                {
                    sink.FlushAsync().Wait();
                    Assert.Fail("AggregateException should be thrown.");
                }
                catch (AggregateException ex)
                {
                    Assert.IsInstanceOfType(ex.InnerException, typeof(FlushFailedException));
                }
                
                Assert.IsTrue(collectErrorsListener.WrittenEntries.Any(x => x.EventId == 1));
            }
        }
        public void ShouldRaiseFlushFailedOnFlushAsyncWhenHttpClientFails()
        {
            var httpClient = HttpClientTestHelper.Create();
            httpClient.When(client => client.PostAsync(Arg.Any<string>(), Arg.Any<HttpContent>())).Do(action => { throw new Exception(); });

            using (var sink = new EventHubHttpSink(httpClient, "eventHubNameNs", "eventhubName", "pubId", "token", Buffering.DefaultBufferingInterval, Buffering.DefaultBufferingCount, Buffering.DefaultMaxBufferSize, TimeSpan.Zero))
            using (var collectErrorsListener = new MockEventListener())
            {
                collectErrorsListener.EnableEvents(SemanticLoggingEventSource.Log, EventLevel.Error, Keywords.All);
                
                sink.OnNext(EventEntryTestHelper.Create());

                try
                {
                    sink.FlushAsync().Wait();
                    Assert.Fail("AggregateException should be thrown.");
                }
                catch (AggregateException ex)
                {
                    Assert.IsInstanceOfType(ex.InnerException, typeof(FlushFailedException));
                }

                Assert.IsTrue(collectErrorsListener.WrittenEntries.Any(x => x.EventId == 1));
            }
        }
        public void ShouldNotStallOrThrowWhenEventHubClientFails()
        {
            var eventHubClient = Substitute.For<IEventHubClient>();
            using (var sink = new EventHubAmqpSink(eventHubClient, Buffering.DefaultBufferingInterval, Buffering.DefaultBufferingCount, Buffering.DefaultMaxBufferSize, TimeSpan.Zero))
            using (var collectErrorsListener = new MockEventListener())
            {
                collectErrorsListener.EnableEvents(SemanticLoggingEventSource.Log, EventLevel.Error, Keywords.All);
                eventHubClient.When(client => client.SendBatchAsync(Arg.Any<IEnumerable<EventData>>()))
                    .Do(action => { throw new Exception(); });

                sink.OnNext(EventEntryTestHelper.Create());

                Assert.IsTrue(Task.Run(() => sink.OnCompleted()).Wait(TimeSpan.FromSeconds(5)));
                Assert.IsTrue(collectErrorsListener.WrittenEntries.Any(x => x.EventId == 1));
            }
        }
        public void ShouldNotStallOrThrowWhenHttpClientFails()
        {
            var httpClient = HttpClientTestHelper.Create();
            httpClient.PostAsync(Arg.Any<string>(), Arg.Any<HttpContent>()).Returns(Task.FromResult(new HttpResponseMessage(HttpStatusCode.InternalServerError)));

            using (var sink = new EventHubHttpSink(httpClient, "eventHubNameNs", "eventhubName", "pubId", "token", Buffering.DefaultBufferingInterval, Buffering.DefaultBufferingCount, Buffering.DefaultMaxBufferSize, TimeSpan.Zero))
            using (var collectErrorsListener = new MockEventListener())
            {
                collectErrorsListener.EnableEvents(SemanticLoggingEventSource.Log, EventLevel.Error, Keywords.All);
                
                sink.OnNext(EventEntryTestHelper.Create());

                Assert.IsTrue(Task.Run(() => sink.OnCompleted()).Wait(TimeSpan.FromSeconds(5)));
                Assert.IsTrue(collectErrorsListener.WrittenEntries.Any(x => x.EventId == 1));
            }
        }