public void Scan() { var website = WebsiteRepository.GetNextScanTargets(1).FirstOrDefault(); if (website == null) { throw new NoWebsiteException(); } var scan = ScanService.TriggerScan(website.Hostname); scan.Wait(); ScanRepository.AddWebsiteToScan(scan.Result, website.Id); WebsiteRepository.UpdateLastScanDateToNow(website.Id); }
public void WebsiteRepository_GetNextScanTargets() { //Arrange Database.Websites.Add(new Websites() { Id = 1, Hostname = "usa.gov", LastScan = DateTime.Today.AddDays(-234) }); Database.Websites.Add(new Websites() { Id = 2, Hostname = "epa.gov", LastScan = DateTime.Today.AddDays(-3) }); Database.Websites.Add(new Websites() { Id = 3, Hostname = "dhs.gov", LastScan = DateTime.Today }); Database.Websites.Add(new Websites() { Id = 4, Hostname = "fbi.gov", LastScan = DateTime.Today.AddDays(-3243) }); Database.Websites.Add(new Websites() { Id = 5, Hostname = "usda.gov", LastScan = DateTime.Today.AddDays(-3) }); Database.Websites.Add(new Websites() { Id = 6, Hostname = "fda.gov", LastScan = DateTime.Today.AddDays(-193) }); Database.SaveChanges(); var repository = new WebsiteRepository(new DatabaseFactory(Database)); //Act var websiteScanTargets = repository.GetNextScanTargets(); //Assert Assert.AreEqual(6, websiteScanTargets.Count); Assert.AreEqual("fbi.gov", websiteScanTargets[0].Hostname); Assert.AreEqual("usa.gov", websiteScanTargets[1].Hostname); Assert.AreEqual("fda.gov", websiteScanTargets[2].Hostname); Assert.AreEqual("epa.gov", websiteScanTargets[3].Hostname); Assert.AreEqual("usda.gov", websiteScanTargets[4].Hostname); Assert.AreEqual("dhs.gov", websiteScanTargets[5].Hostname); }