public void SearchTaskFailsWithNullActionTest() { const Func <string, CancellationToken, IEnumerable <string> > nullAction = null; IEnumerable <string> inilialItems = new[] { "http://mail.ru" }; try { SearchTask .StartNew(inilialItems, nullAction, CancellationToken.None) .Wait(CancellationToken.None); } catch (AggregateException ex) { Assert.AreEqual(1, ex.InnerExceptions.Count); Assert.IsTrue(ex.InnerExceptions.First() is ArgumentNullException); } }
private async Task StartUrlTest(ConcurrentBag <string> outputItems, CancellationToken cancellationToken, SearchTaskOptions options = null) { Assert.IsNotNull(outputItems); Assert.IsNotNull(cancellationToken); var searchOptions = options ?? new SearchTaskOptions { MaxDegreeOfParallelism = Environment.ProcessorCount, MaxHierarchyDepth = HierarchyDepth, MaxQueueLength = int.MaxValue, DequeueWaitTimeout = 5 }; var initialUrls = new Collection <string>(); for (var i = 0; i < InitialItemsCount; i++) { initialUrls.Add($"http://{i}"); } await SearchTask.StartNew ( initialUrls, (url, token) => { outputItems.Add(url); Thread.Sleep(10); var subItems = new Collection <string>(); for (var i = 0; i < SubItemsCount; i++) { subItems.Add($"{url}/{i}"); } return(subItems); }, cancellationToken, searchOptions ); }
public void SearchTaskFailsWithNullInitialItemCollectionTest() { Func <string, CancellationToken, IEnumerable <string> > action = (url, token) => Enumerable.Empty <string>(); const IEnumerable <string> nullInilialItems = null; try { SearchTask .StartNew(nullInilialItems, action, CancellationToken.None) .Wait(CancellationToken.None); } catch (AggregateException ex) { Assert.AreEqual(1, ex.InnerExceptions.Count); Assert.IsTrue(ex.InnerExceptions.First() is ArgumentNullException); } }