public void TryTake() { //**************************************** var MyCollection = new AsyncCollection <int>(); //**************************************** Assert.IsFalse(MyCollection.TryTake(out _), "Take succeeded unexpectedly"); }
public void TryTakeShouldReturnFalseOnEmpty() { var aq = new AsyncCollection<bool>(); Assert.That(aq.OnDataAvailable(CancellationToken.None).IsCompleted, Is.False, "Task should indicate no data available."); bool data; Assert.That(aq.TryTake(out data), Is.False, "TryTake should report false on empty collection."); Assert.That(aq.OnDataAvailable(CancellationToken.None).IsCompleted, Is.False, "Task should indicate no data available."); }
public void TryTakeShouldReturnFalseOnEmpty() { var aq = new AsyncCollection <bool>(); Assert.That(aq.OnDataAvailable(CancellationToken.None).IsCompleted, Is.False, "Task should indicate no data available."); bool data; Assert.That(aq.TryTake(out data), Is.False, "TryTake should report false on empty collection."); Assert.That(aq.OnDataAvailable(CancellationToken.None).IsCompleted, Is.False, "Task should indicate no data available."); }
public static AsyncCollection <T> .TakeResult TryTakeImmediatlyOrReturnNull <T>(this AsyncCollection <T> collectionForReentrantItems) { try { return(collectionForReentrantItems.TryTake(canceledCancellationTokenSource.Token)); } catch (OperationCanceledException) { return(null); } }
public void OnDataAvailableShouldBlockWhenDataRemoved() { var aq = new AsyncCollection<bool>(); aq.Add(true); Assert.That(aq.OnDataAvailable(CancellationToken.None).IsCompleted, Is.True, "Task should indicate data available."); bool data; aq.TryTake(out data); Assert.That(aq.OnDataAvailable(CancellationToken.None).IsCompleted, Is.False, "Task should indicate no data available."); }
public void OnDataAvailableShouldBlockWhenDataRemoved() { var aq = new AsyncCollection <bool>(); aq.Add(true); Assert.That(aq.OnDataAvailable(CancellationToken.None).IsCompleted, Is.True, "Task should indicate data available."); bool data; aq.TryTake(out data); Assert.That(aq.OnDataAvailable(CancellationToken.None).IsCompleted, Is.False, "Task should indicate no data available."); }