public void RaisesTransmissionSentWhenTransmissionFinishesSending()
            {
                var sender = new StubTransmissionSender();
                Transmitter queue = CreateTransmitter(sender: sender);

                object eventSender = null;
                TransmissionProcessedEventArgs eventArgs = null;
                queue.TransmissionSent += (s, e) =>
                {
                    eventSender = s;
                    eventArgs = e;
                };

                var transmission = new StubTransmission();
                var exception = new Exception();
                sender.OnTransmissionSent(new TransmissionProcessedEventArgs(transmission, exception));

                Assert.Same(queue, eventSender);
                Assert.Same(transmission, eventArgs.Transmission);
                Assert.Same(exception, eventArgs.Exception);
            }
            public void LogsUnhandledAsyncExceptionsToPreventThemFromCrashingApplication()
            {
                var exception = new Exception(Guid.NewGuid().ToString());
                var sender = new StubTransmissionSender { OnEnqueue = getTransmissionAsync => { throw exception; } };
                Transmitter transmitter = CreateTransmitter(sender: sender);
                using (var listener = new TestEventListener())
                {
                    const long AllKeywords = -1;
                    listener.EnableEvents(TelemetryChannelEventSource.Log, EventLevel.Warning, (EventKeywords)AllKeywords);

                    sender.OnTransmissionSent(new TransmissionProcessedEventArgs(new StubTransmission()));

                    EventWrittenEventArgs message = listener.Messages.First();
                    Assert.Contains(exception.Message, (string)message.Payload[0], StringComparison.Ordinal);
                }
            }
            public void MovesOldestTransmissionFromBufferToSender()
            {
                Transmission sentTransmission = null;
                var sender = new StubTransmissionSender();
                sender.OnEnqueue = getTransmission =>
                {
                    sentTransmission = getTransmission();
                    return false;
                };

                Transmission bufferedTransmission = new StubTransmission();
                var buffer = new TransmissionBuffer();
                buffer.Enqueue(() => bufferedTransmission);

                Transmitter transmitter = CreateTransmitter(sender: sender, buffer: buffer);

                sender.OnTransmissionSent(new TransmissionProcessedEventArgs(new StubTransmission()));

                Assert.Same(bufferedTransmission, sentTransmission);
            }