コード例 #1
0
ファイル: GetNewsTests.cs プロジェクト: TheMulti0/Content
        public void TestWithCancellation()
        {
            var cts = new CancellationTokenSource();

            cts.CancelAfter(TimeSpan.FromMilliseconds(25));

            Assert.ThrowsAny <OperationCanceledException>(
                () =>
            {
                try
                {
                    var provider = new CalcalistProvider();
                    var items    = provider
                                   .GetNews(cts.Token)
                                   .Result
                                   .ToList();
                }
                catch (AggregateException e)
                {
                    List <OperationCanceledException> canceledExceptions = e.InnerExceptions
                                                                           .Cast <OperationCanceledException>()
                                                                           .ToList();
                    if (canceledExceptions.Any())
                    {
                        throw canceledExceptions.First();
                    }
                }
            });
        }
コード例 #2
0
        public void TestItemsParsing()
        {
            IEnumerable <INewsItem> items = CalcalistProvider.DeserializeItems(ReadXml("news1.xml"));

            foreach (INewsItem item in items)
            {
                AssertNewsItem(item);
            }
        }