public void TestWithCancellation() { var cts = new CancellationTokenSource(); cts.CancelAfter(TimeSpan.FromMilliseconds(25)); Assert.ThrowsAny <OperationCanceledException>( () => { try { var provider = new KanNewsProvider(); var items = provider .GetNews(provider.MaximumItemsPerPage, cancellationToken: cts.Token) .Result .ToList(); } catch (AggregateException e) { List <OperationCanceledException> canceledExceptions = e.InnerExceptions .Cast <OperationCanceledException>() .ToList(); if (canceledExceptions.Any()) { throw canceledExceptions.First(); } } }); }
public void TestItemsParsing() { string html = ReadHtmlText("newsitems.html"); IEnumerable <INewsItem> items = KanNewsProvider.ParseItems(html); Assert.NotNull(items); foreach (INewsItem item in items) { AssertNewsItem(item); Assert.NotNull(item.Url); } }