コード例 #1
0
        public static async Task StartNew <T>
        (
            IEnumerable <T> initialItems,
            Func <T, CancellationToken, IEnumerable <T> > action,
            CancellationToken cancellationToken,
            SearchTaskOptions options = null
        )
        {
            var notNullAction       = Argument.IsNotNull(action, nameof(action));
            var notNullInitialItems = Argument.IsNotNull(initialItems, nameof(initialItems));

            var items = notNullInitialItems.Value.ToArray();

            if (items.Length == 0)
            {
                throw new ArgumentException(@"Initial items collection cannot be empty", nameof(initialItems));
            }

            var queueOptions = NotNull <SearchTaskOptions> .Create(options ?? new SearchTaskOptions());

            var queue = NotNull <IBlockingQueue <HierarchyElement <T> > > .Create
                        (
                new HierarchicalLimitedBlockingQueue <T>(items, queueOptions.Value.MaxQueueLength,
                                                         queueOptions.Value.MaxHierarchyDepth)
                        );

            await Task.Run
            (
                () => { Process(queue, notNullAction, cancellationToken, queueOptions); },
                cancellationToken
            );
        }
コード例 #2
0
        public static async Task StartNew(Action action, int parallelCount)
        {
            Argument.IsNotNull(action, nameof(action));
            Argument.IsInRange(parallelCount, nameof(parallelCount), 2, int.MaxValue);

            var actions = NotNull <IEnumerable <Action> > .Create(Enumerable.Repeat(action, parallelCount));

            await StartCore(actions);
        }
コード例 #3
0
        public void NotNullTest()
        {
            var obj = new object();

            var notNullObj = NotNull <object> .Create(obj);

            Assert.IsNotNull(notNullObj);
            Assert.IsNotNull(notNullObj.Value);
        }
コード例 #4
0
        public void NotNullFailsOnNullValueArgumentTest()
        {
            var exception = Assert.Throws <ArgumentNullException>
                            (
                () => { NotNull <object> .Create(null); }
                            );

            Assert.AreEqual(@"value", exception.ParamName);
        }
コード例 #5
0
 public static void TestCreateWithNullExpectException()
 {
     Assert.That(() => NotNull <object> .Create(null), Throws.Exception);
 }
コード例 #6
0
        public static void TestValueWithNotNullExpectSuccess()
        {
            NotNull <string> nn = NotNull <string> .Create("test");

            Assert.That(nn.Value.Length, Is.EqualTo(4));
        }
コード例 #7
0
        public static void TestImplicitConversionWithNotNullExpectSuccess()
        {
            NotNull <string> nn = NotNull <string> .Create("test");

            Assert.That(((string)nn).Length, Is.EqualTo(4));
        }
コード例 #8
0
 public static void TestCreateWithNotNullExpectSuccess()
 {
     Assert.That(() => NotNull <object> .Create(new object()), Throws.Nothing);
 }