Exemplo n.º 1
0
        public async Task ShouldHonorRetryLimit()
        {
            int fetchCount            = 0;
            var stubContainerProvider = new StubContainerProvider(
                new List <ContainerItem>
            {
                DummyConatinerItem1
            },
                item1 =>
            {
                fetchCount++;
                if (fetchCount == 1)
                {
                    throw new FileNotFoundException();
                }
                return(mockItemContent);
            });

            containerFetchEngineTestOptions.RetryLimit = 2;
            var fetchEngine = GetFetchEngine(stubContainerProvider);

            Task  fetchAsync = fetchEngine.FetchAsync();
            await fetchAsync;

            Assert.Equal(containerFetchEngineTestOptions.RetryLimit, fetchCount);
        }
Exemplo n.º 2
0
 private ContainerFetchEngine GetFetchEngine(StubContainerProvider stubContainerProvider)
 {
     return(new ContainerFetchEngine(stubContainerProvider,
                                     string.Empty,
                                     "c:\\")
     {
         FileSystemManager = new Mock <IReleaseFileSystemManager>().Object,
         ContainerFetchEngineOptions = containerFetchEngineTestOptions
     });
 }
Exemplo n.º 3
0
        public async void ShouldDownloadAllTheFiles()
        {
            var stubContainerProvider = new StubContainerProvider(mockContainerItems, item => mockItemContent);
            var fetchEngine           = GetFetchEngine(stubContainerProvider);

            Task  fetchAsync = fetchEngine.FetchAsync();
            await fetchAsync;

            Assert.Equal(1, stubContainerProvider.GetItemsAsynCounter);
            Assert.Equal(mockContainerItems, stubContainerProvider.GetFileTaskArguments);
        }
Exemplo n.º 4
0
        public async void ShouldDownloadAllTheFiles()
        {
            var stubContainerProvider = new StubContainerProvider(mockContainerItems, (item1, c) => mockItemContent);

            using (var fetchEngine = GetFetchEngine(stubContainerProvider, CancellationToken.None))
            {
                Task  fetchAsync = fetchEngine.FetchAsync(CancellationToken.None);
                await fetchAsync;

                Assert.Equal(1, stubContainerProvider.GetItemsAsynCounter);
                Assert.Equal(mockContainerItems, stubContainerProvider.GetFileTaskArguments);
            }
        }
Exemplo n.º 5
0
        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);
        }
Exemplo n.º 6
0
        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);
        }