Beispiel #1
0
        public async Task EmitTaskWithListener_NotNeedToSave_TheMethodWasCalled()
        {
            var mgr      = new RecyclableMemoryStreamManager();
            var req      = CreateRequest(1);
            var listener = new NullDownloadListener();

            req.Listener = listener;
            var saver = (NullSaver)req.Saver;

            saver.IsNeedToSave = false;
            var   downloader = new ComicDownloader(mgr);
            var   res        = downloader.EmitTasks(req);
            await res[0]();

            Assert.IsTrue(listener.IsNotNeedToSaveAsync);
        }
Beispiel #2
0
        public async Task EmitTaskWithListener_ListenerMethodWasCalled()
        {
            var mgr      = new RecyclableMemoryStreamManager();
            var req      = CreateRequest(1);
            var listener = new NullDownloadListener();

            req.Listener = listener;
            var   downloader = new ComicDownloader(mgr);
            var   res        = downloader.EmitTasks(req);
            await res[0]();

            Assert.IsTrue(listener.IsReadyFetchAsync);
            Assert.IsTrue(listener.IsBeginFetchPageAsync);
            Assert.IsTrue(listener.IsReadySaveAsync);
            Assert.IsTrue(listener.IsEndFetchPageAsync);
            Assert.IsTrue(listener.IsComplatedSaveAsync);
        }
Beispiel #3
0
        public async Task EmitTaskWithListener_Cancel_CancelListenerWasCalled()
        {
            var mgr      = new RecyclableMemoryStreamManager();
            var req      = CreateRequest(1);
            var listener = new NullDownloadListener();

            req.Listener = listener;
            var downloader = new ComicDownloader(mgr);
            var tks        = new CancellationTokenSource();
            var res        = downloader.EmitTasks(req, tks.Token);

            tks.Cancel();
            try
            {
                await res[0]();
            }
            catch (Exception) { }
            Assert.IsTrue(listener.IsCanceledAsync);
        }
Beispiel #4
0
        public async Task EmitTaskWithListener_ThrowException_TheMethodWasCalled()
        {
            var sourceProvider = new ExceptionComicProvider();
            var saver          = new NullSaver();
            var reqs           = Enumerable.Range(0, 1)
                                 .Select(x => new DownloadItemRequest(new ComicPage {
                TargetUrl = "-no-"
            }))
                                 .ToArray();
            var mgr        = new RecyclableMemoryStreamManager();
            var req        = new ComicDownloadRequest(saver, null, null, reqs, sourceProvider);
            var downloader = new ComicDownloader(mgr);
            var listener   = new NullDownloadListener();

            req.Listener = listener;
            var   res = downloader.EmitTasks(req);
            await res[0]();

            Assert.IsTrue(listener.IsFetchPageExceptionAsync);
        }