public void MovesTransmissionsFromBufferToStorageWhenBufferCapacityIsZero()
            {
                var storage = new StubTransmissionStorage { Capacity = 1 };

                var bufferedTransmission = new StubTransmission();
                var buffer = new TransmissionBuffer();
                storage.Enqueue(() => bufferedTransmission);
                
                var policy = new StubTransmissionPolicy();
                policy.MaxBufferCapacity = 1;

                Transmitter transmitter = CreateTransmitter(buffer: buffer, storage: storage, policies: new[] { policy });

                policy.MaxBufferCapacity = 0;
                policy.Apply();

                Transmission storedTransmission = storage.Dequeue();
                Assert.Same(bufferedTransmission, storedTransmission);
            }
            public void MovesTransmissionsFromStorageToBufferWhenBufferCapacityIsGreaterThanZero()
            {
                var storedTransmission = new StubTransmission();

                var storage = new StubTransmissionStorage();
                storage.Enqueue(() => storedTransmission);

                var buffer = new TransmissionBuffer();

                var policy = new StubTransmissionPolicy();
                policy.MaxBufferCapacity = 0;

                Transmitter transmitter = CreateTransmitter(buffer: buffer, storage: storage, policies: new[] { policy });

                policy.MaxBufferCapacity = 1;
                policy.Apply();

                Transmission bufferedTransmission = buffer.Dequeue();
                Assert.Same(storedTransmission, bufferedTransmission);
            }
            public void DoesNotMoveTransmissionsFromStorageToSenderWhenBufferIsNotEmptyToPreserveQueueOrder()
            {
                var storedTransmission = new StubTransmission();
                var storage = new StubTransmissionStorage();
                storage.Enqueue(() => storedTransmission);
                var buffer = new StubTransmissionBuffer { OnGetSize = () => 1 };

                var sentTransmissions = new List<Transmission>();
                StubTransmissionSender sender = CreateSender(sentTransmissions);
                sender.OnGetCapacity = () => 1;

                Transmitter transmitter = CreateTransmitter(sender, buffer, storage);
                transmitter.ApplyPolicies();

                Assert.DoesNotContain(storedTransmission, sentTransmissions);                
            }
            public void EmptiesBufferIfCapacityIsZero()
            {
                //// We set capacity to 0 and clear the cache when DC responds with 439.

                var buffer = new StubTransmissionBuffer();
                buffer.Enqueue(() => new StubTransmission());
                var storage = new StubTransmissionStorage();
                storage.Enqueue(() => new StubTransmission());
                var sender = new StubTransmissionSender();
                sender.Enqueue(() => new StubTransmission());

                var policy = new StubTransmissionPolicy();
                policy.MaxStorageCapacity = 0;

                Transmitter transmitter = CreateTransmitter(sender, buffer, storage, new[] { policy });

                policy.Apply();

                Assert.Equal(0, storage.Queue.Count);
            }
            public void MovesTransmissionsFromStorageToSenderToAvoidWaitingUntilBufferIsFullBeforeSendingStarts()
            {
                var storedTransmission = new StubTransmission();
                var storage = new StubTransmissionStorage();
                storage.Enqueue(() => storedTransmission);
                var buffer = new StubTransmissionBuffer();

                var sentTransmissions = new List<Transmission>();
                StubTransmissionSender sender = CreateSender(sentTransmissions);
                sender.OnGetCapacity = () => 1;

                Transmitter transmitter = CreateTransmitter(sender, buffer, storage);
                transmitter.ApplyPolicies();

                Assert.Contains(storedTransmission, sentTransmissions);
            }