public void PBScrape_CountsDatabaseEntries_1() { PBScrape newScrape = new PBScrape(); newScrape.Save(); List <PBScrape> allScrapes = PBScrape.GetAll(); int count = allScrapes.Count; Assert.AreEqual(1, count); }
public void PBScrape_SavesStaticVariables_IsTrue() { PBScrape newScrape = new PBScrape(); newScrape.Save(); int Id = newScrape.GetId(); string Keyword = newScrape.GetKeyword(); string Url = newScrape.GetUrl(); string Phone = newScrape.GetPhone(); string Email = newScrape.GetEmail(); bool TestBool = false; if (Id == 0 && Keyword == "Bongos" && Url == "https://Bongos.com" && Phone == "333-333-3333" && Email == "*****@*****.**") { TestBool = true; } Assert.AreEqual(TestBool, true); }
public void Post([FromBody] string keyword) { //New instance PBScrape newScrape = new PBScrape(); //Set Keyword string and scrape keyword string postKeyword = keyword; newScrape.SetKeyword(postKeyword); //Get list of url's off keyword List <object> newList = new List <object> { newScrape.GetGoogleResults(postKeyword) }; //Step through each URL foreach (var url in newList) { string instanceUrl = url.ToString(); bool emailMatchBool = false; bool phoneMatchBool = false; List <string> parsedDiv = new List <string> { newScrape.ParseDiv(instanceUrl).ToString() }; newScrape.SetUrl(instanceUrl); foreach (var div in parsedDiv) { //Email & Phone regex match string emailPattern = _emailRegex; string phonePattern = _phoneRegex; Match emailMatch = Regex.Match(div, emailPattern); Match phoneMatch = Regex.Match(div, phonePattern); //If email regex match if (emailMatchBool == false) { if (emailMatch.Success) { emailMatchBool = true; newScrape.SetEmail(emailMatch.Value); } else { newScrape.SetEmail("No Match Found"); } } //if phone match if (phoneMatchBool == false) { if (phoneMatch.Success) { phoneMatchBool = true; newScrape.SetPhone(phoneMatch.Value); } else { newScrape.SetPhone("No Match Found"); } } } //save instance newScrape.Save(); } }