public async Task ShouldSupportCancellation() { var stubContainerProvider = new StubContainerProvider( mockContainerItems, (item1, c) => { Thread.Sleep(30); return(mockItemContent); }); var cancellationTokenSource = new CancellationTokenSource(); ContainerFetchEngine fetchEngine = GetFetchEngine(stubContainerProvider, CancellationToken.None); cancellationTokenSource.Cancel(); Task fetchAsync = fetchEngine.FetchAsync(cancellationTokenSource.Token); await fetchAsync; Assert.Equal(0, stubContainerProvider.GetFileTaskArguments.Count); }
public async void ShouldNotDoParallelDownloadIfSpecified() { int concurrentAccessCount = 0; var stubContainerProvider = new StubContainerProvider(mockContainerItems, item => { concurrentAccessCount++; Thread.Sleep(10); if (concurrentAccessCount == 1) { concurrentAccessCount = 0; } return(mockItemContent); }); containerFetchEngineTestOptions.ParallelDownloadLimit = 1; ContainerFetchEngine fetchEngine = GetFetchEngine(stubContainerProvider); Task fetchAsync = fetchEngine.FetchAsync(); await fetchAsync; Assert.Equal(0, concurrentAccessCount); }