public void EqualsFailTest(string postId, EAccessMode access, string content, string image, string postIdExpected, EAccessMode accessExpected, string contentExpected, string imageExpected) { var actual = new UpdatePostRequestModel(postId, access, content, image); var expected = new UpdatePostRequestModel(postIdExpected, accessExpected, contentExpected, imageExpected); Assert.IsFalse(actual.Equals(expected)); }
public void CtorTestExceptions(string postId, EAccessMode access, string content, string file) { Assert.Throws <ArgumentNullException>(() => { var model = new UpdatePostRequestModel(postId, access, content, file); }); }
public async Task <ActionResult> Update(int id, UpdatePostRequestModel model) { var userId = this.currentUser.GetId(); var result = await this.postsService.Update(id, model.Description, userId); if (result.Failure) { return(this.BadRequest(result.Error)); } return(this.Ok()); }
public void PerformQueryTest(EAccessMode access, string content, string image) { var model = new UpdatePostRequestModel("id", access, content, image); var actual = model.PerformQuery(); var expected = new JObject { ["post"] = new JObject { ["access"] = access == EAccessMode.None ? string.Empty : access.ToString(), ["content"] = content, ["image"] = !string.IsNullOrWhiteSpace(image) ? "data:image/gif;base64," + image : string.Empty } }; Assert.IsTrue(JToken.DeepEquals(actual, expected)); }
public IHttpActionResult Put(UpdatePostRequestModel post, int id) { if (!this.ModelState.IsValid) { return(this.BadRequest()); } var currentUser = this.User.Identity.Name; var tagsFromValue = this.tags.TagsFromCommaSeparatedValues(post.Tags); try { this.posts.Update(id, Mapper.Map <Post>(post), currentUser, tagsFromValue); return(this.Ok()); } catch (ArgumentException) { return(this.NotFound()); } catch (InvalidOperationException) { return(this.Unauthorized()); } }