Exemplo n.º 1
0
        public async Task Start_OnDropout_Fails()
        {
            string mockId = Guid.NewGuid().ToString();

            using MockServer.MockServer mockServer = new MockServer.MockServer();
            mockServer.AddMockHandler(mockId);
            mockServer.StartAsync();

            string id = Guid.NewGuid().ToString();

            string outDir = Path.Combine(Path.GetTempPath(), id);

            Directory.CreateDirectory(outDir);

            var success = true;

            var cs = new CancellationTokenSource();

            var hc = new SingleSourceHTTPDownloader(new SingleSourceHTTPDownloadInfo {
                Uri = $"http://127.0.0.1:39000/{mockId}"
            });

            hc.Finished += (a, b) =>
            {
                success = true;
                cs.Cancel();
            };
            hc.Failed += (a, b) =>
            {
                Console.WriteLine("Test: download failed");
                success = false;
                cs.Cancel();
            };
            hc.TargetDir = outDir;
            hc.Start();
            try
            {
                await Task.Delay(3000, cs.Token);
            }
            catch { }
            mockServer.Stop();

            try
            {
                await Task.Delay(Int32.MaxValue, cs.Token);
            }
            catch { }

            Assert.IsFalse(success);
            Assert.IsFalse(hc.IsCancelled);
            var path = Path.Combine(Config.DataDir, hc.Id);

            Assert.DoesNotThrow(() => Directory.Delete(path, true));
        }
Exemplo n.º 2
0
 public void TearDown()
 {
     mockServer?.Stop();
 }