private void FillCategories() { _sortedPublished = new Dictionary <string, List <BlogPostPublished> >(); var posts = blogRepository.GetAllPostsDescending(); var cats = blogRepository.GetAllCategoriesUsed(true); foreach (var cat in cats) { _sortedPublished.Add(cat, posts.Where(p => p.Categories.Contains(cat)).ToList()); } }
public void DictGetter_Works() { IBlogPostRepository repo = Substitute.For <IBlogPostRepository>(); var posts = Generate10Posts(); repo.GetAllPostsDescending().Returns(posts); repo.GetAllCategoriesUsed() .Returns(posts.SelectMany(p => p.Categories).Distinct().ToList()); CategoriesViewModel model = new CategoriesViewModel(repo); var sorted = model.SortedPublished; Assert.AreEqual(sorted.Count, 10); Assert.AreEqual(sorted["OtherCat"].Count, 9); for (int i = 1; i < 10; i++) { Assert.AreEqual(sorted["Cat" + i].Count, 1); } }