Ejemplo n.º 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
            );
        }
Ejemplo n.º 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);
        }
Ejemplo n.º 3
0
        public void NotNullTest()
        {
            var obj = new object();

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

            Assert.IsNotNull(notNullObj);
            Assert.IsNotNull(notNullObj.Value);
        }
Ejemplo n.º 4
0
        public void NotNullFailsOnNullValueArgumentTest()
        {
            var exception = Assert.Throws <ArgumentNullException>
                            (
                () => { NotNull <object> .Create(null); }
                            );

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

            Assert.That(nn.Value.Length, Is.EqualTo(4));
        }
Ejemplo n.º 7
0
        public static void TestImplicitConversionWithNotNullExpectSuccess()
        {
            NotNull <string> nn = NotNull <string> .Create("test");

            Assert.That(((string)nn).Length, Is.EqualTo(4));
        }
Ejemplo n.º 8
0
 public static void TestCreateWithNotNullExpectSuccess()
 {
     Assert.That(() => NotNull <object> .Create(new object()), Throws.Nothing);
 }