public void ReturnsOldestEnquedTransmission() { var buffer = new TransmissionBuffer(); Transmission transmission1 = new StubTransmission(); buffer.Enqueue(() => transmission1); Transmission transmission2 = new StubTransmission(); buffer.Enqueue(() => transmission2); Assert.Same(transmission1, buffer.Dequeue()); Assert.Same(transmission2, buffer.Dequeue()); }
public void DoesNotMakesSpaceForNewTransmissionWhenBufferIsEmpty() { var buffer = new TransmissionBuffer { Capacity = 0 }; buffer.Dequeue(); Assert.False(buffer.Enqueue(() => new StubTransmission())); }
public void ReflectsContentLengthOfTransmissionsRemovedByDequeueAsync() { var buffer = new TransmissionBuffer(); buffer.Enqueue(() => new StubTransmission(new byte[10])); buffer.Dequeue(); Assert.Equal(0, buffer.Size); }
public void MakesSpaceForOneNewTransmissionWhenOldTransmissionDequeuedSuccessfully() { var buffer = new TransmissionBuffer { Capacity = 1 }; buffer.Enqueue(() => new StubTransmission()); buffer.Dequeue(); Assert.True(buffer.Enqueue(() => new StubTransmission())); }
public void RaisedWhenDequeueFromEmptyBufferWasAttempted() { object eventSender = null; TransmissionProcessedEventArgs eventArgs = null; var buffer = new TransmissionBuffer(); buffer.TransmissionDequeued += (sender, args) => { eventSender = sender; eventArgs = args; }; buffer.Dequeue(); Assert.Same(buffer, eventSender); Assert.Same(null, eventArgs.Transmission); }
public void IsRaisedWhenTransmissionWasDequeuedSuccessfully() { object eventSender = null; TransmissionProcessedEventArgs eventArgs = null; var buffer = new TransmissionBuffer(); buffer.TransmissionDequeued += (sender, args) => { eventSender = sender; eventArgs = args; }; buffer.Enqueue(() => new StubTransmission()); Transmission dequeuedTransmission = buffer.Dequeue(); Assert.Same(buffer, eventSender); Assert.Same(dequeuedTransmission, eventArgs.Transmission); }
public void EnqueueAndDequeueMethodsAreThreadSafe() { var buffer = new TransmissionBuffer(); const int NumberOfThreads = 16; const int NumberOfIterations = 1000; var tasks = new Task[NumberOfThreads]; for (int t = 0; t < NumberOfThreads; t++) { tasks[t] = TaskEx.Run(() => { for (int i = 0; i < NumberOfIterations; i++) { buffer.Enqueue(() => new StubTransmission()); buffer.Dequeue(); } }); } TaskEx.WhenAll(tasks).GetAwaiter().GetResult(); }
public void EnqueueAndDequeueMethodsAreThreadSafe() { var buffer = new TransmissionBuffer(); const int NumberOfThreads = 16; const int NumberOfIterations = 1000; var tasks = new Task[NumberOfThreads]; for (int t = 0; t < NumberOfThreads; t++) { tasks[t] = TaskEx.Run(() => { for (int i = 0; i < NumberOfIterations; i++) { buffer.Enqueue(() => new StubTransmission()); buffer.Dequeue(); } }); } TaskEx.WhenAll(tasks).GetAwaiter().GetResult(); }
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 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 ReturnsNullWhenBufferIsEmpty() { var buffer = new TransmissionBuffer(); Assert.Null(buffer.Dequeue()); }
public void IsRaisedWhenTransmissionWasDequeuedSuccessfully() { object eventSender = null; TransmissionProcessedEventArgs eventArgs = null; var buffer = new TransmissionBuffer(); buffer.TransmissionDequeued += (sender, args) => { eventSender = sender; eventArgs = args; }; buffer.Enqueue(() => new StubTransmission()); Transmission dequeuedTransmission = buffer.Dequeue(); Assert.Same(buffer, eventSender); Assert.Same(dequeuedTransmission, eventArgs.Transmission); }
public void ReflectsContentLengthOfTransmissionsRemovedByDequeueAsync() { var buffer = new TransmissionBuffer(); buffer.Enqueue(() => new StubTransmission(new byte[10])); buffer.Dequeue(); Assert.Equal(0, buffer.Size); }
public void RaisedWhenDequeueFromEmptyBufferWasAttempted() { object eventSender = null; TransmissionProcessedEventArgs eventArgs = null; var buffer = new TransmissionBuffer(); buffer.TransmissionDequeued += (sender, args) => { eventSender = sender; eventArgs = args; }; buffer.Dequeue(); Assert.Same(buffer, eventSender); Assert.Same(null, eventArgs.Transmission); }
public void DoesNotMakesSpaceForNewTransmissionWhenBufferIsEmpty() { var buffer = new TransmissionBuffer { Capacity = 0 }; buffer.Dequeue(); Assert.False(buffer.Enqueue(() => new StubTransmission())); }
public void MakesSpaceForOneNewTransmissionWhenOldTransmissionDequeuedSuccessfully() { var buffer = new TransmissionBuffer { Capacity = 1 }; buffer.Enqueue(() => new StubTransmission()); buffer.Dequeue(); Assert.True(buffer.Enqueue(() => new StubTransmission())); }
public void ReturnsNullWhenBufferIsEmpty() { var buffer = new TransmissionBuffer(); Assert.Null(buffer.Dequeue()); }
public void ReturnsOldestEnquedTransmission() { var buffer = new TransmissionBuffer(); Transmission transmission1 = new StubTransmission(); buffer.Enqueue(() => transmission1); Transmission transmission2 = new StubTransmission(); buffer.Enqueue(() => transmission2); Assert.Same(transmission1, buffer.Dequeue()); Assert.Same(transmission2, buffer.Dequeue()); }