Exemplo n.º 1
0
        public void GetPostById(string title, int postId, bool expected)
        {
            PostsResponse response = repo.GetById(postId);

            Assert.AreEqual(expected, response.Success);
            if (expected == true)
            {
                Assert.AreEqual(title, response.Posts.First().PostTitle);
            }
        }
Exemplo n.º 2
0
        public PostsResponse GetById(int id)
        {
            PostsResponse response = new PostsResponse();

            if (id == 0)
            {
                response.Success = false;
                response.Message = "Id value was not passed in.";
                return(response);
            }
            try
            {
                response = repo.GetById(id);
                if (response.Posts.Count == 0 || response.Posts.First() == null)
                {
                    response.Success = false;
                    response.Message = "No posts found";
                }
                response.Success = true;
            }
            catch (Exception ex)
            {
                response.Success = true;
                response.Message = ex.Message;
            }
            return(response);
        }