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 } }
public async Task FetchAllAsync(PageStreamedResource resource) { var actual = await PageStreamedResource.PageStreamer.FetchAllAsync( new Request(resource), CancellationToken.None); Assert.AreEqual(resource.AllItems, actual); }
public void Fetch(PageStreamedResource resource) { var actual = PageStreamedResource.PageStreamer.Fetch(new Request(resource)); Assert.AreEqual(resource.AllItems, actual); }
internal Request(PageStreamedResource resource) { this.resource = resource; }