コード例 #1
0
        public async Task BackgroundUriRequester_StopAsync_Stops_Current_Active_Request()
        {
            var cancelled = false;
            Func<Uri, CancellationToken, bool> processor = (u, c) => DoProcessing(c, out cancelled);

            var requester = new BackgroundUriRequester(processor);
            requester.Add(TestHelpers.CreateRequestList(1)[0]);
            requester.Start(TimeSpan.FromMilliseconds(10));

            await Task.Delay(TimeSpan.FromSeconds(1), CancellationToken.None);

            Assert.IsFalse(cancelled);
            await requester.StopAsync();
            Assert.IsTrue(cancelled);
        }
コード例 #2
0
        public void BackgroundUriRequester_StopAsync_Stops_Requesting()
        {
            var actualList = new List<Uri>();
            Func<Uri, CancellationToken, bool> processor = (u, c) => { actualList.Add(u); return true; };

            var requester = new BackgroundUriRequester(processor);
            requester.Start(TimeSpan.FromMilliseconds(10));

            Task.Delay(1000, CancellationToken.None).GetAwaiter().GetResult();

            requester.StopAsync().Wait(CancellationToken.None);
            foreach (var uri in TestHelpers.CreateRequestList(3))
                requester.Add(uri);

            Assert.AreEqual(0, actualList.Count);
            Assert.AreEqual(3, requester.QueueCount);
        }