Example #1
0
        public void WebsiteRepository_DoesWebsiteExist()
        {
            //Arrange
            var repository = new WebsiteRepository(new DatabaseFactory(Database));

            Database.Websites.Add(new Websites()
            {
                Id = 1, LastScan = DateTime.Today.AddDays(-10), Hostname = "uSa.gov"
            });
            Database.SaveChanges();

            //Act
            var doWebsitesExist = repository.DoWebsitesExist(new[] { "usa.gov", "epa.gov" });

            //Assert
            Assert.IsTrue(doWebsitesExist["usa.gov"]);
            Assert.IsFalse(doWebsitesExist["epa.gov"]);
        }
        public void AddWebsitesFromCsv(string rawCsv)
        {
            var websiteEntries  = CsvService.ParseWebsiteCsvList(rawCsv);
            var hostnames       = websiteEntries.Select(x => x.Hostname.ToLower()).ToList();
            var doWebsitesExist = WebsiteRepository.DoWebsitesExist(hostnames);

            foreach (var websiteEntry in websiteEntries)
            {
                if (!doWebsitesExist[websiteEntry.Hostname.ToLower()])
                {
                    var websiteCategory = WebsiteCategoryService.GetOrCreateWebsiteCategory(websiteEntry);

                    WebsiteRepository.Add(new WebsiteDto()
                    {
                        Id         = WebsiteService.GetNextId(),
                        Hostname   = websiteEntry.Hostname.ToLower(),
                        LastScan   = DateTime.MinValue,
                        Status     = StatusType.NEW,
                        CategoryId = websiteCategory.Id
                    });
                }
            }
        }