Beispiel #1
0
        public void WebsiteRepository_Add()
        {
            //Arrange
            var dto = new WebsiteDto()
            {
                Id = 1032, Hostname = "usa.gov", LastScan = DateTime.Today.AddDays(-10)
            };

            var unitOfWork        = new UnitOfWork(Database);
            var unitOfWorkFactory = new Mock <IUnitOfWorkFactory>();

            unitOfWorkFactory.Setup(x => x.GetUnitOfWork()).Returns(unitOfWork);

            var repository = new WebsiteRepository(new DatabaseFactory(Database))
            {
                UnitOfWorkFactory = unitOfWorkFactory.Object
            };

            //Act
            repository.Add(dto);
            var entityToAssert = Database.Websites.Find(1032);

            //Assert
            Assert.IsNotNull(entityToAssert);
            Assert.AreEqual(1032, entityToAssert.Id);
            Assert.AreEqual("usa.gov", entityToAssert.Hostname);
            Assert.AreEqual(DateTime.Today.AddDays(-10), entityToAssert.LastScan);
        }
Beispiel #2
0
        public void WebsiteRepository_GetLargestId()
        {
            //Arrange
            Database.Add(new Websites()
            {
                Id = 25, Hostname = "fcc.gov"
            });
            Database.Add(new Websites()
            {
                Id = 50, Hostname = "usa.gov"
            });
            Database.Add(new Websites()
            {
                Id = 75, Hostname = "epa.gov"
            });
            Database.SaveChanges();

            var repository = new WebsiteRepository(new DatabaseFactory(Database));

            //Act
            var maxId = repository.GetLargestId();

            //Assert
            Assert.AreEqual(75, maxId);
        }
Beispiel #3
0
 public async Task Remove(int id)
 {
     if (!await WebsiteRepository.Remove(id))
     {
         throw new NotFoundError($"Delete Failed. Website with id {id} not found");
     }
 }
Beispiel #4
0
        public static Guid GetAnExistingIdByName(WebsiteRepository repo, string name)
        {
            var website = repo.FindAll()
                          .First(a => a.CompanyName == name);

            return(website.Id);
        }
Beispiel #5
0
        public async Task <int> Create(WebsiteProxy websiteProxy)
        {
            WebsiteValidator.ValidateOnUpdateOrCreate(websiteProxy);

            var id = await WebsiteRepository.Create(websiteProxy);

            return(id);
        }
Beispiel #6
0
        public void WebsiteRepository_GetLargestId_NoWebsites()
        {
            //Arrange
            var repository = new WebsiteRepository(new DatabaseFactory(Database));

            //Act
            var maxId = repository.GetLargestId();

            //Assert
            Assert.AreEqual(0, maxId);
        }
        private async Task <WebsiteController> GetWebsiteController()
        {
            var entityMapper = await InstanceFactory.GetInstance <WebsiteManagementEntityMapper>();

            var websiteRepository = new WebsiteRepository(await GetDbContext(), entityMapper);
            var websiteValidator  = await InstanceFactory.GetInstance <WebsiteValidator>();

            var websiteDataService = new WebsiteDataService(websiteRepository, websiteValidator, new PagingValidator());

            return(new WebsiteController(websiteDataService));
        }
Beispiel #8
0
        public async Task <WebsiteProxy> Get(int id)
        {
            var website = await WebsiteRepository.Get(id);

            if (website is null)
            {
                throw new NotFoundError($"Website with id {id} not found");
            }

            return(website);
        }
Beispiel #9
0
        public MainViewModel()
        {
            _websiteRepository = new WebsiteRepository();

            Products = new ObservableCollection <Product>();
            Website  = new Website();
            PageToCheckCollection = new ObservableCollection <PageToCheck>();

            var websiteFromDb = _websiteRepository.GetAll();

            WebsiteCollection = websiteFromDb != null ? new ObservableCollection <Website>(websiteFromDb) : new ObservableCollection <Website>();
        }
Beispiel #10
0
        public async Task <WebsiteProxy> Patch(WebsiteProxy websiteProxy)
        {
            WebsiteValidator.ValidateOnPatch(websiteProxy);

            var updatedObject = await WebsiteRepository.Patch(websiteProxy);

            if (updatedObject is null)
            {
                throw new NotFoundError($"Update Failed. Website with id {websiteProxy.Id} not found");
            }

            return(updatedObject);
        }
        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);
        }
Beispiel #12
0
        public async Task <WebsiteProxy[]> Get(int?page,
                                               int?pageSize,
                                               WebsiteOrderByEnum?orderBy,
                                               WebsiteOrderByAscDescEnum?orderType)
        {
            var totalRecords = await GetCount();

            if (totalRecords == 0)
            {
                return(Enumerable.Empty <WebsiteProxy>().ToArray());
            }

            PagingValidator.Validate(totalRecords, page, pageSize);

            return(await WebsiteRepository.Get(page, pageSize, orderBy, orderType));
        }
Beispiel #13
0
        static void Main(string[] args)
        {
            var _websiteRepository   = new WebsiteRepository();
            var _websiteCollection   = _websiteRepository.GetAll();
            var _pageToCheckTaskList = new List <Task>();

            foreach (var pageToCheck in _websiteCollection.Select(website => new PageToCheck(website.MainUrl, website.NameXPath, website.PriceXPath)))
            {
                Console.WriteLine($"Sprawdzam {pageToCheck.WebUrl} ...");
                pageToCheck.AllLinkCheck += ((arg1, arg2, arg3, arg4) =>
                                             Console.WriteLine(
                                                 $"{arg4}{Environment.NewLine} Przeszukano: {arg2}{Environment.NewLine} Produktów: {arg1}{Environment.NewLine}"));

                _pageToCheckTaskList.Add(pageToCheck.Check());
            }

            Task.WaitAll(_pageToCheckTaskList.ToArray());
        }
Beispiel #14
0
        public async Task <WebsiteProxy> Update(WebsiteProxy websiteProxy)
        {
            if (websiteProxy.Id == 0)
            {
                throw new NotFoundError($"Update Failed. Website {websiteProxy.Id} not provided");
            }

            WebsiteValidator.ValidateOnUpdateOrCreate(websiteProxy);

            var updatedObject = await WebsiteRepository.Update(websiteProxy);

            if (updatedObject is null)
            {
                throw new NotFoundError($"Update Failed. Website with id {websiteProxy.Id} not found");
            }

            return(updatedObject);
        }
Beispiel #15
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"]);
        }
Beispiel #16
0
        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);
        }
        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
                    });
                }
            }
        }
Beispiel #18
0
 public async Task <int> GetCount()
 {
     return(await WebsiteRepository.GetCount());
 }
 public WebsiteRepositoryTests()
 {
     websiteRepo      = new WebsiteRepository();
     basicWebsiteRepo = new BasicWebsiteRepository();
 }
 public WebsiteController(WebsiteRepository websiteRepository)
 {
     this.websiteRepository = websiteRepository;
 }