public void LogsUnhandledAsyncExceptionsToPreventThemFromCrashingApplication()
            {
                var exception = new Exception(Guid.NewGuid().ToString());
                var buffer = new StubTransmissionBuffer 
                { 
                    OnEnqueue = getTransmissionAsync => 
                    { 
                        throw exception; 
                    } 
                };

                Transmitter transmitter = CreateTransmitter(buffer: buffer);

                using (var listener = new TestEventListener())
                {
                    const long AllKeywords = -1;
                    listener.EnableEvents(TelemetryChannelEventSource.Log, EventLevel.Warning, (EventKeywords)AllKeywords);

                    buffer.OnTransmissionDequeued(new TransmissionProcessedEventArgs(new StubTransmission()));

                    EventWrittenEventArgs message = listener.Messages.First();
                    Assert.Contains(exception.Message, (string)message.Payload[0], StringComparison.Ordinal);
                }
            }
            public void MovesOldestTransmissionFromStorageToBuffer()
            {
                var previouslyStoredTransmissions = new List<Transmission> { new StubTransmission(), new StubTransmission() };
                int storageIndex = 0;
                var storage = new StubTransmissionStorage
                {
                    OnDequeue = () =>
                    {
                        if (storageIndex < previouslyStoredTransmissions.Count)
                        {
                            return previouslyStoredTransmissions[storageIndex++];
                        }

                        return null;
                    }
                };

                var newlyBufferedTransmissions = new List<Transmission>();
                var buffer = new StubTransmissionBuffer
                {
                    OnEnqueue = getTransmission =>
                    {
                        var transmission = getTransmission();
                        if (transmission != null)
                        {
                            newlyBufferedTransmissions.Add(transmission);
                            return true;
                        }

                        return false;
                    }
                };

                var sender = new StubTransmissionSender();

                Transmitter queue = CreateTransmitter(sender: sender, buffer: buffer, storage: storage);

                buffer.OnTransmissionDequeued(new TransmissionProcessedEventArgs(null));

                Assert.Equal(previouslyStoredTransmissions, newlyBufferedTransmissions);
            }