Exemple #1
0
 public void TestBatchInvalidArgumentValidation()
 {
     Assert.Throws <ArgumentOutOfRangeException>(() => new BatchBlock <int>(-1));
     Assert.Throws <ArgumentNullException>(() => new BatchBlock <int>(2, null));
     Assert.True(ITargetBlockTestHelper.TestArgumentsExceptions <int>(new BatchBlock <int>(1)));
     Assert.True(ISourceBlockTestHelper.TestArgumentsExceptions <int[]>(new BatchBlock <int>(1)));
 }
Exemple #2
0
 public void TestTransformBlockInvalidArgumentValidation()
 {
     Assert.Throws <ArgumentNullException>(() => new TransformBlock <int, string>((Func <int, string>)null));
     Assert.Throws <ArgumentNullException>(() => new TransformBlock <int, string>((Func <int, Task <string> >)null));
     Assert.Throws <ArgumentNullException>(() => new TransformBlock <int, string>(i => i.ToString(), null));
     Assert.Throws <ArgumentNullException>(() => new TransformBlock <int, string>(i => Task.Run(() => i.ToString()), null));
     Assert.True(ITargetBlockTestHelper.TestArgumentsExceptions <int>(new TransformBlock <int, string>(i => i.ToString())));
     Assert.True(ISourceBlockTestHelper.TestArgumentsExceptions <string>(new TransformBlock <int, string>(i => i.ToString())));
 }
Exemple #3
0
        public void TestWriteOnceInvalidArgumentValidation()
        {
            bool passed = true;

            Assert.Throws <ArgumentNullException>(() => new WriteOnceBlock <int>(i => i, null));
            passed &= ITargetBlockTestHelper.TestArgumentsExceptions <int>(new WriteOnceBlock <int>(i => i));
            passed &= ISourceBlockTestHelper.TestArgumentsExceptions <int>(new WriteOnceBlock <int>(i => i));

            Assert.True(passed, "Argument Validation failed.");
        }
Exemple #4
0
        public void TestTransformManyBlockInvalidArgumentValidation()
        {
            bool passed = true;

            Assert.Throws <ArgumentNullException>(() => new TransformManyBlock <int, string>((Func <int, IEnumerable <string> >)null));
            Assert.Throws <ArgumentNullException>(() => new TransformManyBlock <int, string>((Func <int, Task <IEnumerable <string> > >)null));
            Assert.Throws <ArgumentNullException>(() => new TransformManyBlock <int, string>(i => new[] { i.ToString() }, null));
            Assert.Throws <ArgumentNullException>(() => new TransformManyBlock <int, string>(i => Task.Run(() => (IEnumerable <string>) new[] { i.ToString() }), null));

            passed &= ITargetBlockTestHelper.TestArgumentsExceptions <int>(new TransformManyBlock <int, int>(i => new int[] { i }));
            passed &= ISourceBlockTestHelper.TestArgumentsExceptions <int>(new TransformManyBlock <int, int>(i => new int[] { i }));

            Assert.True(passed, "Test failed.");
        }
Exemple #5
0
        public void RunActionBlockTests()
        {
            Assert.True(IDataflowBlockTestHelper.TestToString(nameFormat => nameFormat != null ? new ActionBlock <int>(x => { }, new ExecutionDataflowBlockOptions()
            {
                NameFormat = nameFormat
            }) : new ActionBlock <int>(x => { })));
            Assert.True(IDataflowBlockTestHelper.TestToString(nameFormat =>
                                                              nameFormat != null ?
                                                              new ActionBlock <int>(x => { }, new ExecutionDataflowBlockOptions()
            {
                NameFormat = nameFormat, SingleProducerConstrained = true
            }) :
                                                              new ActionBlock <int>(x => { }, new ExecutionDataflowBlockOptions()
            {
                SingleProducerConstrained = true
            })));

            Assert.True(ITargetBlockTestHelper.TestArgumentsExceptions <int>(new ActionBlock <int>(i => { })));
            Assert.True(ITargetBlockTestHelper.TestOfferMessage <int>(new ActionBlock <int>(i => { }, new ExecutionDataflowBlockOptions {
                SingleProducerConstrained = true
            })));

            Assert.True(ITargetBlockTestHelper.TestPost <int>(new ActionBlock <int>(i => { }, new ExecutionDataflowBlockOptions {
                SingleProducerConstrained = true
            })));
            Assert.True(ITargetBlockTestHelper.TestComplete <int>(new ActionBlock <int>(i => { }, new ExecutionDataflowBlockOptions {
                SingleProducerConstrained = true
            })));
            Assert.True(ITargetBlockTestHelper.TestCompletionTask <int>(new ActionBlock <int>(i => { }, new ExecutionDataflowBlockOptions {
                SingleProducerConstrained = true
            })));

            Assert.True(ITargetBlockTestHelper.TestNonGreedyPost(new ActionBlock <int>(x => { Task.Delay(1); }, new ExecutionDataflowBlockOptions()
            {
                BoundedCapacity = 1
            })));
        }
Exemple #6
0
 public void TestBroadcastBlockInvalidArgumentValidation()
 {
     Assert.Throws <ArgumentNullException>(() => new BroadcastBlock <int>(i => i, null));
     Assert.True(ITargetBlockTestHelper.TestArgumentsExceptions <int>(new BroadcastBlock <int>(i => i)));
     Assert.True(ISourceBlockTestHelper.TestArgumentsExceptions <int>(new BroadcastBlock <int>(i => i)));
 }