public void PBScrape_SetsAndRetrievesKeyword_IsTrue() { //Arrange PBScrape newScrape = new PBScrape(); //Assert newScrape.SetKeyword("Seattle Flowers"); Assert.AreEqual("Seattle Flowers", newScrape.GetKeyword()); }
public void PBScrape_SetsAndRetrievesEmail_IsTrue() { //Arrange PBScrape newScrape = new PBScrape("Email test"); //Act newScrape.SetEmail("*****@*****.**"); //Assert Assert.AreEqual("*****@*****.**", newScrape.GetEmail()); }
public void PBScrape_SetsAndRetrievesPhone_IsTrue() { //Arrange PBScrape newScrape = new PBScrape("Phone test"); //Act newScrape.SetPhone("1-800-453-9999"); //Assert Assert.AreEqual("1-800-453-9999", newScrape.GetPhone()); }
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_RetrievedURLSInList_NotEqualToZero() { //Arrange string Keyword = "Sandwhich"; PBScrape newScrape = new PBScrape(Keyword); //Act newScrape.GetGoogleResults(newScrape.GetKeyword()); List <string> urlList = newScrape.GetUrls(); //Assert Assert.AreNotEqual(0, urlList); }
public void PBScrape_SavesStaticVariables_IsTrue() { PBScrape newScrape = new PBScrape(); string Keyword = newScrape.GetKeyword(); bool TestBool = false; if (Keyword == "Bongos") { TestBool = true; } Assert.AreEqual(TestBool, true); }
public List <string> Get(int id) { List <PBScrape> allScrapes = PBScrape.GetAll(); PBScrape currentScrape = allScrapes[id - 1]; List <string> allProperties = new List <string>(); allProperties.Add(currentScrape.GetId().ToString()); allProperties.Add(currentScrape.GetKeyword()); allProperties.Add(currentScrape.GetUrl()); allProperties.Add(currentScrape.GetPhone()); allProperties.Add(currentScrape.GetEmail()); return(allProperties); }
public void PBScrape_GetsURLTitle_IsTrue() { //Arrange string Keyword = "Wikipedia test"; string Url = "https://www.wikipedia.org"; PBScrape newScrape = new PBScrape(Keyword); newScrape.SetUrl(Url); //Act object ParseObject = newScrape.GetTitleHtml(newScrape.GetUrl()); //Assert Assert.AreEqual("Wikipedia", ParseObject); }
public List <string> Get() { List <PBScrape> allScrapes = PBScrape.GetAll(); List <string> allProperties = new List <string>(); for (int i = 0; i < allScrapes.Count; i++) { allProperties.Add(allScrapes[i].GetId().ToString()); allProperties.Add(allScrapes[i].GetKeyword()); allProperties.Add(allScrapes[i].GetUrl()); allProperties.Add(allScrapes[i].GetPhone()); allProperties.Add(allScrapes[i].GetEmail()); } return(allProperties); }
public string Get() { List <PBScrape> allScrapes = PBScrape.GetAll(); Dictionary <string, string> allKeys = new Dictionary <string, string>(); for (int i = 0; i < allScrapes.Count; i++) { allKeys.Add("id", allScrapes[i].GetId().ToString()); allKeys.Add("keyword", allScrapes[i].GetKeyword()); allKeys.Add("url", allScrapes[i].GetUrl()); allKeys.Add("email", allScrapes[i].GetEmail()); allKeys.Add("phone", allScrapes[i].GetPhone()); } string json = JsonConvert.SerializeObject(allKeys); return(json); }
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(); } }