public void AllItemsPresentAsync() { var input = CreateMultipleBags(); List <int[]> expected = input.expected; Func <int, int> op = (x) => x + 1; var consumer = new MultiConcurrentConsumer <int, int>() { Collections = input.bags, ResultCollection = new ConcurrentQueue <int>(), Operation = op }; Task.WaitAll(consumer.ConsumeAsync()); List <int> expectedNumbers = new List <int>(); foreach (var item in expected) { foreach (var item1 in item) { expectedNumbers.Add(op(item1)); } } var actual = Helpers.VerifyAllValuesPresent(consumer.ResultCollection, expectedNumbers); _ = ""; Assert.True(actual.result, actual.message); }
public void ThrowsWhenNoOperationProvided() { var input = CreateMultipleBags(); List <int[]> expected = input.expected; var consumer = new MultiConcurrentConsumer <int, int>() { Collections = input.bags, ResultCollection = new ConcurrentQueue <int>(), }; Assert.Throws <NotImplementedException>(() => consumer.Consume()); }
public void CancelThrowsWhenAttemptingToCancelWhenCancelTokenIsManagedByOtherObject() { var input = CreateMultipleBags(); List <int[]> expected = input.expected; var consumer = new MultiConcurrentConsumer <int, int>() { Collections = input.bags, ResultCollection = new ConcurrentQueue <int>() }; CancellationTokenSource TokenSource = new CancellationTokenSource(); Task consumerTask = consumer.ConsumeAsync(TokenSource.Token); TaskStatus status = consumerTask.Status; Assert.Throws <NotSupportedException>(() => consumer.Cancel()); }