public void Scraper_ReturnsCorrectNumberOfPostsDefault() { //this is bad but I'm out of time var hackerItems = Scraper.Scrape("https://news.ycombinator.com/news"); Assert.AreEqual(hackerItems.Count, 30); }
static void Main(string[] args) { args = new string[] { "--posts", "100" }; int numOfPosts; var hackerNewsItems = new List <HackerNewsItem>(); var hackerNewsBaseUrl = "https://news.ycombinator.com/news?p="; if (!ArgsValidator.Validate(args, out numOfPosts)) { Environment.Exit(0); } int postsLeftToGet = numOfPosts; int postsPerPage = 30; int page = 1; //this assumes 30 posts per page. while (postsLeftToGet > postsPerPage) { hackerNewsItems.AddRange(Scraper.Scrape(hackerNewsBaseUrl + page++.ToString(), postsPerPage)); postsLeftToGet -= postsPerPage; } //get the remaining posts to get hackerNewsItems.AddRange(Scraper.Scrape(hackerNewsBaseUrl + page++.ToString(), postsLeftToGet)); //now we'll use JsonConvert to serialize the object to json System.Console.WriteLine(JsonConvert.SerializeObject( hackerNewsItems, new JsonSerializerSettings //use this serializer settings to output property names in camelCase { ContractResolver = new CamelCasePropertyNamesContractResolver() })); System.Console.WriteLine(); }
public void Scraper_ReturnsCorrectNumberOfPosts12() { var hackerItems = Scraper.Scrape("https://news.ycombinator.com/news", 12); Assert.AreEqual(hackerItems.Count, 12); }