public void TestStartScrape() { FileScraper fileScraper = new FileScraper(); fileScraper.OnErrorScrapingEventHandler += FileScraper_OnErrorScrapingEventHandler; fileScraper.OnSourceParsedEventHandler += FileScraper_OnSourceParsedEventHandler; fileScraper.OnStartScrapingEventHandler += FileScraper_OnStartScrapingEventHandler; fileScraper.OnStopScrapingEventHandler += FileScraper_OnStopScrapingEventHandler; Directory.CreateDirectory(@"C:\Temp"); File.WriteAllText(@"C:\Temp\TestFileScrape.txt", "192.168.15.1:2222"); File.WriteAllText(@"C:\Temp\EmptyTestFileScrape.txt", ""); List <string> source = new List <string>() { @"C:\Temp\TestFileScrape.txt", @"C:\Temp\NotFoundTestFileScrape.txt", @"C:\Temp\EmptyTestFileScrape.txt" }; HashSet <string> proxy = fileScraper.StartScrape(source); Assert.Single(proxy); Assert.Equal("192.168.15.1:2222", proxy.ToList()[0]); List <string> source2 = new List <string>() { @"C:\Temp\TestFileScrape.txt", @"C:\Temp\NotFoundTestFileScrape.txt", @"C:\Temp\EmptyTestFileScrape.txt" }; Task task = new Task(() => fileScraper.StartScrape(source2)); task.Start(); fileScraper.StopScrape(); HashSet <string> proxy2 = null; Task task2 = new Task(() => proxy2 = fileScraper.StartScrape(source2)); task2.Start(); Thread.Sleep(100); fileScraper.StopScrape(); if (!(proxy2 is null)) { Assert.True(proxy2.Count >= 0); } Directory.Delete(@"C:\Temp", true); }
protected void Page_Load(object sender, EventArgs e) { if (Request.QueryString.Count == 0) { //Response.Redirect(HttpContext.Current.Request.Url.AbsoluteUri + "?ClientName=None&ModelType=OILSPILL&Location=Wuhan&Time=true"); Response.Redirect(HttpContext.Current.Request.Url.AbsoluteUri + "?ModelType=OILSPILL&Location=World&TIME=true"); } //TO BE REPLACED WITH SOMTHING MORE SECURE _ModelType = "OILSPILL"; if (Request.QueryString["ModelType"] != null) { _ModelType = Request.QueryString["ModelType"]; } _sLocation = "World"; if (Request.QueryString["Location"] != null) { _sLocation = Request.QueryString["Location"]; } _WebPath = Path.GetDirectoryName(Server.MapPath("ModelRunMapPath.txt")) + "\\ModelData\\" + _sLocation; FileScraper scraper = new FileScraper(_ModelType, _WebPath); bool bWithTime = false; if (Request.QueryString["Time"] != null) { bWithTime = bool.Parse(Request.QueryString["Time"]); } if (bWithTime) { Response.Write(scraper.getModelFileNamesWithTime(_WebPath)); } else { Response.Write(scraper.getModelFileNames(_WebPath)); } }
public void TestStartScrapeThrowsArgumentOutOfRangeException() { FileScraper fileScraper = new FileScraper(); Assert.Throws <ArgumentOutOfRangeException>(() => fileScraper.StartScrape(new List <string>())); }
public void TestStartScrapeThrowsArgumentNullException(ICollection <string> source) { FileScraper fileScraper = new FileScraper(); Assert.Throws <ArgumentNullException>(() => fileScraper.StartScrape(source)); }