示例#1
0
        public PostsResponse GetByTitle(string title)
        {
            var context = new PersonalBlogEntities();

            if (string.IsNullOrEmpty(title))
            {
                return(repo.GetByTitle(title));
            }
            if (context.Posts.FirstOrDefault(p => p.PostTitle == title) == null)
            {
                var response = new PostsResponse();

                response.Success = false;
                response.Message = $"There are no posts that have the name of {title}";
                return(response);
            }

            return(repo.GetByTitle(title));
        }
示例#2
0
        public void GetPostByTitle(string title, int postId, bool expected)
        {
            PostsResponse response = repo.GetByTitle(title);

            Assert.AreEqual(expected, response.Success);
            if (expected == true)
            {
                Assert.AreEqual(postId, response.Posts.First().PostId);
            }
        }