public void TwoPopsWaitWhenItemsWillBeAvailable() { using (RichQueue <int> richQueue = new RichQueue <int>()) { AutoResetEvent resetEvent = new AutoResetEvent(false); var task1 = Task.Run(() => { resetEvent.Set(); return(richQueue.Pop()); }); // Wait when Pop task begin resetEvent.WaitOne(); var task2 = Task.Run(() => { resetEvent.Set(); return(richQueue.Pop()); }); // Wait when Pop task begin resetEvent.WaitOne(); richQueue.Push(5); richQueue.Push(7); Assert.AreEqual(5, task1.Result); Assert.AreEqual(7, task2.Result); } }
public void SeveralDisposeCallsNotThrowsException() { RichQueue <int> richQueue = new RichQueue <int>(); richQueue.Dispose(); richQueue.Dispose(); }
public void PushThrowsOnDisposedObject() { RichQueue <int> richQueue = new RichQueue <int>(); richQueue.Dispose(); Assert.Catch <ObjectDisposedException>(() => richQueue.Push(5)); }
public void PopReturnsPushedItem() { using (RichQueue <int> richQueue = new RichQueue <int>()) { richQueue.Push(5); var actualValue = richQueue.Pop(); Assert.AreEqual(5, actualValue); } }
public void PushIncreasesCount() { using (RichQueue <int> richQueue = new RichQueue <int>()) { richQueue.Push(5); richQueue.Push(7); Assert.AreEqual(2, richQueue.Count); } }
public void PopDecreasesCount() { using (RichQueue <int> richQueue = new RichQueue <int>()) { richQueue.Push(5); var countBeforePop = richQueue.Count; richQueue.Pop(); Assert.AreEqual(countBeforePop - 1, richQueue.Count); } }
public void CountThrowsOnDisposedObject() { RichQueue <int> richQueue = new RichQueue <int>(); richQueue.Push(5); richQueue.Dispose(); Assert.Catch <ObjectDisposedException>(() => { var count = richQueue.Count; }); }
public void EmptyQueue_ZeroCountDefaultFirstValue() { // Arrange var queue = new RichQueue <int>(); // Act var count = queue.Count; var first = queue.First; // Assert Assert.Equal(0, count); Assert.Equal(0, first); }
public void DequeueEvenValues_ReturnsEmptyCollection() { // Arrange var queue = new RichQueue <int>(); var sourceCollection = new[] { 1, 3, 5, 7 }; // Act queue.Enqueue(sourceCollection); var result = queue.Remove(x => x % 2 == 0).ToList(); // Assert Assert.Empty(result); }
public void EnqueueCollection_ValidCountAndFirst() { // Arrange var queue = new RichQueue <int>(); var collection = new [] { 1, 2, 3 }; // Act queue.Enqueue(collection); // Assert Assert.Equal(collection.Length, queue.Count); Assert.Equal(collection[0], queue.First); }
public void PopTwiseReturnsTwoPushedItem() { using (RichQueue <int> richQueue = new RichQueue <int>()) { richQueue.Push(5); richQueue.Push(7); var actualValue1 = richQueue.Pop(); var actualValue2 = richQueue.Pop(); Assert.AreEqual(5, actualValue1); Assert.AreEqual(7, actualValue2); } }
public void DequeueEvenValues_ReturnsExpectedCollection() { // Arrange var queue = new RichQueue <int>(); var sourceCollection = new[] { 1, 2, 3, 4, 5, 6, 7 }; var expectedCollection = new[] { 2, 4, 6 }; // Act queue.Enqueue(sourceCollection); var result = queue.Remove(x => x % 2 == 0).ToList(); // Assert Assert.True(CollectionExtensions.IsCollectionsEqual(expectedCollection, result)); }
public void DequeueCollection_ValidCountAndFirst() { // Arrange var queue = new RichQueue <int>(); var collection = new[] { 1, 2, 3 }; // Act queue.Enqueue(collection); var first = queue.Dequeue(); var second = queue.Dequeue(); // Assert Assert.Equal(collection[0], first); Assert.Equal(collection[1], second); Assert.Equal(collection[2], queue.First); }
public void PopWaitsWhenItemWillBeAvailable() { using (RichQueue <int> richQueue = new RichQueue <int>()) { ManualResetEvent resetEvent = new ManualResetEvent(false); var task = Task.Run(() => { resetEvent.Set(); return(richQueue.Pop()); }); // Wait when Pop task begin resetEvent.WaitOne(); richQueue.Push(5); Assert.AreEqual(5, task.Result); } }