public void ArgsValidator_IsPostCountInvalid(int numOfPosts) { string[] args = new string[] { "--posts", numOfPosts.ToString() }; var result = ArgsValidator.Validate(args, out numOfPosts); Assert.IsFalse(result); }
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 ArgsValidator_IncorrectUsageProducesFalse() { string[] args = new string[] { "somethingwrong", "2" }; int numOfPosts; Assert.IsFalse(ArgsValidator.Validate(args, out numOfPosts)); args = new string[] { "2", "--posts" }; }
public void ArgsValidator_ArgsProducesCorrectNumOfPosts() { string[] args = new string[] { "--posts", "2" }; int numOfPosts; Assert.IsTrue(ArgsValidator.Validate(args, out numOfPosts)); Assert.AreEqual(numOfPosts, 2); }