protected void btnGetArticles_Click(object sender, EventArgs e) { btnGetArticles.Enabled = false; Stopwatch stopwatch = new Stopwatch(); stopwatch.Start(); //try accessing the web api, if there is an issue, show an error message to the user try { originalArticles = HackerNewsService.GetNewArticles(); } catch (Exception ex) { lblError.Text = ex.Message; lblError.Visible = true; } finally { //if we were not able to get articles, we still want the button to be enabled so the user can try again btnGetArticles.Enabled = true; } grdArticles.DataSource = originalArticles; grdArticles.DataBind(); stopwatch.Stop(); lblTime.Text = "Article Retrive Took: " + stopwatch.Elapsed.ToString(); lblTime.Visible = true; //now that we have content, enable searching btnSearch.Enabled = true; btnReset.Enabled = true; }
public void TestArticleToString() { List <Article> allNewArticles = HackerNewsService.GetNewArticles(); //check that we are not getting any completely null articles (specific code to prevent that from happening) foreach (Article art in allNewArticles) { Assert.IsTrue(art != null); } }