public static void SequenceEqual_SharedRight_Cancellation(Labeled <ParallelQuery <int> > left, Labeled <ParallelQuery <int> > right, int count) { IntegerRangeSet seen = new IntegerRangeSet(0, count); CancellationTokenSource cs = new CancellationTokenSource(); Assert.Throws <OperationCanceledException>(() => left.Item.Except(ParallelEnumerable.Range(0, count).Select(x => { cs.Cancel(); seen.Add(x); return(x); })) .SequenceEqual(right.Item.WithCancellation(cs.Token))); // Canceled query means some elements should not be seen. Assert.False(seen.All(x => x.Value)); }