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 PushIncreasesCount() { using (RichQueue <int> richQueue = new RichQueue <int>()) { richQueue.Push(5); richQueue.Push(7); Assert.AreEqual(2, richQueue.Count); } }
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 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 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 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); } }