public static bool IsValidStory(this HNItem HNItem) { if (HNItemTypes.Story != HNItem.Type) { return(false); } if (string.IsNullOrEmpty(HNItem.Title) || HNItem.Title.Length > 256) { return(false); } if (!Uri.IsWellFormedUriString(HNItem.Url, UriKind.Absolute)) { return(false); } if (HNItem.Score <= 0) { return(false); } if (HNItem.Kids == null) { return(false); } if (HNItem.Kids.Count() == 0) { return(false); } return(true); }
public void GivenThatTheItemIsNotStory_WhenIsMappedToStories_ThenAExceptionIsLaunch() { var NHItemUT = new HNItem() { Type = "comment" }; var story = NHItemUT.Map(1); }
protected override async void OnNavigatedTo(NavigationEventArgs e) { base.OnNavigatedTo(e); this.id = (int)e.Parameter; this.root = await HNItem.fromID(id); this.ScoreText.Text = root.score.ToString(); this.TitleText.Text = root.title; RefreshThread(id); }
public ThreadItem(int level, HNItem item) { this.margin = new Thickness(level * 30, 0, 0, 0); this.item = item; if (item.dead || item.deleted) { color = new SolidColorBrush(Windows.UI.Colors.Gray); } else { color = new SolidColorBrush(Windows.UI.Colors.White); //change based on theme } }
private async void RefreshMessages(string category) { var client = new HttpClient(); var raw = await client.GetStringAsync(new Uri("https://hacker-news.firebaseio.com/v0/" + category + "stories.json")); List <int> topids = JsonConvert.DeserializeObject <List <int> >(raw); var topitems = new List <HNItem>(); while (topitems.Count < 20) { topitems.Add(await HNItem.fromID(topids[topitems.Count], client)); } MessageList.ItemsSource = topitems; }
private async Task <List <ThreadItem> > buildThread(List <ThreadItem> thread, int level, List <int> nodes, HttpClient client) { if (nodes != null) { foreach (int kidid in nodes) { var kid = await HNItem.fromID(kidid); thread.Add(new ThreadItem(level, kid)); await buildThread(thread, level + 1, kid.kids, client); } } return(thread); }
public void GivenThatTheItemIsStory_WhenIsMappedToStories_ThenANewStoryObjectIsCreated() { var NHItemUT = new HNItem() { Type = HNItemTypes.Story, Title = "Some title", By = "author", Score = 33 }; var rank = 6; var story = NHItemUT.Map(rank); Assert.AreEqual(NHItemUT.Title, story.Title); Assert.AreEqual(NHItemUT.By, story.Author); Assert.AreEqual(rank, story.Rank); Assert.AreEqual(NHItemUT.Score, story.Points); }
public InvalidHNItemToStoryException(HNItem HNItem, string message) : base(message) { this.HNItem = HNItem; }
public InvalidHNItemToStoryException(HNItem HNItem) : base() { this.HNItem = HNItem; }