Exemplo n.º 1
0
        public void GetPostByCat(int catId, int postCount, bool expected)
        {
            PostsResponse response = repo.GetByCategory(catId);

            Assert.AreEqual(expected, response.Success);
            if (expected == true)
            {
                Assert.AreEqual(postCount, response.Posts.Count());
            }
        }
Exemplo n.º 2
0
        public PostsResponse GetByCategory(string category)
        {
            var context          = new PersonalBlogEntities();
            var possibleCategory = context.Categories.FirstOrDefault(c => c.CategoryName.ToLower() == category.ToLower());

            if (possibleCategory == null)
            {
                var response = new PostsResponse();
                response.Success = false;
                response.Message = $"{category} is not a valid category.";
                return(response);
            }
            else
            {
                return(repo.GetByCategory(possibleCategory.CategoryId));
            }
        }