コード例 #1
0
        public async Task Cancellation()
        {
            var cts = new CancellationTokenSource();
            var gatekeeperSource = new TaskCompletionSource <int>();
            var resource         = new PageStreamedResource(
                "check",
                new Page("x", 1, 2, 3),
                new Page("y", 4, 5),
                new Page(null, 6, 7));

            resource.gateKeeper = gatekeeperSource.Task;

            var task = PageStreamedResource.PageStreamer.FetchAllAsync(new Request(resource), cts.Token);

            // Delay the resource fetching until we've cancelled the token
            cts.Cancel();
            gatekeeperSource.SetResult(0);
            // TODO: Move to Assert.ThrowsAsync when we update to an appropriate version of NUnit.
            // Assert.That is available, but the documentation is unclear how this interacts with await.
            try
            {
                await task;
                Assert.Fail("Expected exception");
            }
            catch (OperationCanceledException)
            {
                // Expected
            }
        }
コード例 #2
0
        public async Task FetchAllAsync(PageStreamedResource resource)
        {
            var actual = await PageStreamedResource.PageStreamer.FetchAllAsync(
                new Request(resource),
                CancellationToken.None);

            Assert.AreEqual(resource.AllItems, actual);
        }
コード例 #3
0
        public void Fetch(PageStreamedResource resource)
        {
            var actual = PageStreamedResource.PageStreamer.Fetch(new Request(resource));

            Assert.AreEqual(resource.AllItems, actual);
        }
コード例 #4
0
 internal Request(PageStreamedResource resource)
 {
     this.resource = resource;
 }