Exemple #1
0
        public IHttpActionResult Get(int id)
        {
            var posts = postsrepository.Get(id);

            if (posts == null)
            {
                return(StatusCode(HttpStatusCode.NoContent));
            }
            posts.Links.Add(new Link()
            {
                Url = HttpContext.Current.Request.Url.AbsoluteUri.ToString(), Method = "GET", Relation = "Self"
            });
            posts.Links.Add(new Link()
            {
                Url = "http://localhost:58618/api/posts", Method = "GET", Relation = "Get All"
            });
            posts.Links.Add(new Link()
            {
                Url = "http://localhost:58618/api/posts", Method = "POST", Relation = "Create"
            });
            posts.Links.Add(new Link()
            {
                Url = HttpContext.Current.Request.Url.AbsoluteUri.ToString(), Method = "PUT", Relation = "Update"
            });
            posts.Links.Add(new Link()
            {
                Url = HttpContext.Current.Request.Url.AbsoluteUri.ToString(), Method = "DELETE", Relation = "Delete"
            });
            return(Ok(postsrepository.Get(id)));
        }
Exemple #2
0
 public ActionResult Details(Guid id)
 {
     Models.PostViewModel post = new Models.PostViewModel();
     post.Title       = _repository.Get(id).PostName;
     post.Id          = _repository.Get(id).Id;
     post.Description = _repository.Get(id).PostText;
     post.PublishDate = _repository.Get(id).PublishDate;
     return(View(post));
 }
        public void PostsRepository_Post_Only_By_Valid_Id()
        {
            //  Arrange
            var postsRepository = new PostsRepository(new WebClient(new HttpClient()));

            //  Act
            var result = postsRepository.Get <Post>(-10);

            //  Assert
            Assert.True(result.Result == null);
        }
        public void PostsRepository_Can_Get_Post_By_Id()
        {
            //  Arrange
            var postsRepository = new PostsRepository(new WebClient(new HttpClient()));

            //  Act
            var result = postsRepository.Get <Post>(6);

            //  Assert
            Assert.True(result.Result.Id == 6);
            Assert.True(result.Result.Title.Length > 0);
        }