Пример #1
0
        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);
        }
Пример #2
0
        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());
        }
Пример #3
0
        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());
        }