Exemple #1
0
        public JsonResult AddPosts(string data, HttpPostedFileBase file)
        {
            PostEntity post = new System.Web.Script.Serialization.JavaScriptSerializer().Deserialize <PostEntity>(data);

            post.Ip = Request.UserHostAddress;
            var dt = _postService.AddPost(post, file);

            return(Json(dt, JsonRequestBehavior.AllowGet));
        }
        public async void AddPost_AddInvalidPost_ReturnsThrowArgumentException()
        {
            string postText       = string.Empty;
            var    mockRepository = new Mock <IPostsRepository>();
            var    postsService   = new PostsService(mockRepository.Object);
            Guid   guid           = Guid.NewGuid();

            var result = postsService.AddPost(guid, postText);

            await Assert.ThrowsAsync <ArgumentException>(async() => await result);
        }
Exemple #3
0
        public void Post([FromBody] Post post)
        {
            PostsService postsService = new PostsService();

            // If the post exists, submit the post
            if (post != null)
            {
                // If the Post is longer than 140 characters, truncate to the first 140
                if (post.Text.Length > 140)
                {
                    post.Text = post.Text.Substring(0, 140);
                }

                postsService.AddPost(post);
            }
        }