public async Task UpdateComment_ValidResponse_ValidComment() { /*** Arrange ***/ string responseString = "{\"type\":\"comment\",\"id\":\"191969\",\"is_reply_comment\":false,\"message\":\"These tigers are cool!\",\"created_by\":{\"type\":\"user\",\"id\":\"17738362\",\"name\":\"sean rose\",\"login\":\"[email protected]\"},\"created_at\":\"2012-12-12T11:25:01-08:00\",\"item\":{\"id\":\"5000948880\",\"type\":\"file\"},\"modified_at\":\"2012-12-12T11:25:01-08:00\"}"; IBoxRequest boxRequest = null; Handler.Setup(h => h.ExecuteAsync <BoxComment>(It.IsAny <IBoxRequest>())) .Returns(Task.FromResult <IBoxResponse <BoxComment> >(new BoxResponse <BoxComment>() { Status = ResponseStatus.Success, ContentString = responseString })).Callback <IBoxRequest>(r => boxRequest = r); /*** Act ***/ BoxCommentRequest request = new BoxCommentRequest() { Message = "fakeMessage" }; BoxComment c = await _commentsManager.UpdateAsync("fakeId", request); /*** Assert ***/ /*** Request ***/ BoxCommentRequest payLoad = JsonConvert.DeserializeObject <BoxCommentRequest>(boxRequest.Payload); Assert.AreEqual(request.Message, payLoad.Message); /** Response ***/ Assert.AreEqual("comment", c.Type); Assert.AreEqual("191969", c.Id); Assert.AreEqual("These tigers are cool!", c.Message); }
public async Task AddComment_ValidResponse_ValidComment() { /*** Arrange ***/ string responseString = "{\"type\":\"comment\",\"id\":\"191969\",\"is_reply_comment\":false,\"message\":\"These tigers are cool!\",\"created_by\":{\"type\":\"user\",\"id\":\"17738362\",\"name\":\"sean rose\",\"login\":\"[email protected]\"},\"created_at\":\"2012-12-12T11:25:01-08:00\",\"item\":{\"id\":\"5000948880\",\"type\":\"file\"},\"modified_at\":\"2012-12-12T11:25:01-08:00\"}"; _handler.Setup(h => h.ExecuteAsync <BoxComment>(It.IsAny <IBoxRequest>())) .Returns(Task.FromResult <IBoxResponse <BoxComment> >(new BoxResponse <BoxComment>() { Status = ResponseStatus.Success, ContentString = responseString })); /*** Act ***/ BoxCommentRequest request = new BoxCommentRequest() { Item = new BoxRequestEntity() { Id = "fakeId", Type = BoxType.file }, Message = "fake message" }; BoxComment c = await _commentsManager.AddCommentAsync(request); /*** Assert ***/ Assert.AreEqual("comment", c.Type); Assert.AreEqual("191969", c.Id); Assert.AreEqual("These tigers are cool!", c.Message); }
public async Task CommentsWorkflow_LiveSession_ValidResponse() { // Test adding a new comment const string message = "this is a test"; BoxCommentRequest addReq = new BoxCommentRequest() { Message = message, Item = new BoxRequestEntity() { Id = fileId, Type = BoxType.file } }; BoxComment c = await _client.CommentsManager.AddCommentAsync(addReq); Assert.AreEqual(fileId, c.Item.Id); Assert.AreEqual(BoxType.file.ToString(), c.Item.Type); Assert.AreEqual(BoxType.comment.ToString(), c.Type); Assert.AreEqual(message, c.Message); // Test getting the comment information BoxComment cInfo = await _client.CommentsManager.GetInformationAsync(c.Id); Assert.AreEqual(c.Id, cInfo.Id); Assert.AreEqual(BoxType.comment.ToString(), cInfo.Type); // Test updating a message const string updateMessage = "this is an updated test comment"; BoxCommentRequest updateReq = new BoxCommentRequest() { Message = updateMessage }; BoxComment cUpdate = await _client.CommentsManager.UpdateAsync(c.Id, updateReq); Assert.AreEqual(c.Id, cUpdate.Id); Assert.AreEqual(BoxType.comment.ToString(), cUpdate.Type); Assert.AreEqual(updateMessage, cUpdate.Message); // Test deleting a comment bool success = await _client.CommentsManager.DeleteAsync(c.Id); Assert.AreEqual(true, success); }
/// <summary> /// Used to update the message of the comment. /// </summary> /// <param name="id">Id of the comment.</param> /// <param name="commentsRequest">BoxCommentsRequest object.</param> /// <param name="fields">Attribute(s) to include in the response.</param> /// <returns>The full updated comment object is returned if the ID is valid and if the user has access to the comment.</returns> public async Task <BoxComment> UpdateAsync(string id, BoxCommentRequest commentsRequest, IEnumerable <string> fields = null) { id.ThrowIfNullOrWhiteSpace("id"); commentsRequest.ThrowIfNull("commentsRequest") .Message.ThrowIfNullOrWhiteSpace("commentsRequest.Message"); BoxRequest request = new BoxRequest(_config.CommentsEndpointUri, id) .Method(RequestMethod.Put) .Param(ParamFields, fields) .Payload(_converter.Serialize(commentsRequest)); IBoxResponse <BoxComment> response = await ToResponseAsync <BoxComment>(request).ConfigureAwait(false); return(response.ResponseObject); }
public async Task CommentsWorkflow_LiveSession_ValidResponse() { const string fileId = "16894947279"; const string message = "this is a test Comment"; BoxCommentRequest addReq = new BoxCommentRequest() { Message = message, Item = new BoxRequestEntity() { Id = fileId, Type = BoxType.file } }; BoxComment c = await _client.CommentsManager.AddCommentAsync(addReq); Assert.AreEqual(fileId, c.Item.Id, "Comment was added to incorrect file"); Assert.AreEqual(BoxType.file.ToString(), c.Item.Type, "Comment was not added to a file"); Assert.AreEqual(BoxType.comment.ToString(), c.Type, "Returned object is not a comment"); Assert.AreEqual(message, c.Message, "Wrong comment added to file"); // Get comment details BoxComment cInfo = await _client.CommentsManager.GetInformationAsync(c.Id); Assert.AreEqual(c.Id, cInfo.Id, "two comment objects have different ids"); Assert.AreEqual(BoxType.comment.ToString(), cInfo.Type, "returned object is not a comment"); // Update the comment const string updateMessage = "this is an updated test comment"; BoxCommentRequest updateReq = new BoxCommentRequest() { Message = updateMessage }; BoxComment cUpdate = await _client.CommentsManager.UpdateAsync(c.Id, updateReq); Assert.AreEqual(c.Id, cUpdate.Id, "Wrong comment was updated"); Assert.AreEqual(BoxType.comment.ToString(), cUpdate.Type, "returned type of update is not a comment"); Assert.AreEqual(updateMessage, cUpdate.Message, "Comment was not updated with correct string"); // Deleting a comment bool success = await _client.CommentsManager.DeleteAsync(c.Id); Assert.AreEqual(true, success, "Unsuccessful comment delete"); }
/// <summary> /// Used to add a comment by the user to a specific file, discussion, or comment (i.e. as a reply comment). /// </summary> /// <param name="commentRequest">BoxCommentRequest object.</param> /// <param name="fields">Attribute(s) to include in the response.</param> /// <returns>The new comment object is returned.</returns> public async Task <BoxComment> AddCommentAsync(BoxCommentRequest commentRequest, IEnumerable <string> fields = null) { commentRequest.ThrowIfNull("commentRequest") .Item.ThrowIfNull("commentRequest.Item") .Id.ThrowIfNullOrWhiteSpace("commentRequest.Item.Id"); if (commentRequest.Item.Type == null) { throw new ArgumentNullException("commentRequest.Item.Type"); } BoxRequest request = new BoxRequest(_config.CommentsEndpointUri) .Method(RequestMethod.Post) .Param(ParamFields, fields) .Payload(_converter.Serialize(commentRequest)); IBoxResponse <BoxComment> response = await ToResponseAsync <BoxComment>(request).ConfigureAwait(false); return(response.ResponseObject); }
private async Task RunCreate() { base.CheckForValue(this._itemId.Value, this._app, "An item ID is required for this command"); base.CheckForValue(this._itemType.Value, this._app, "An item type is required for this command"); var type = this._itemType.Value.ToLower(); if (type != "file" && type != "comment") { throw new Exception("The type must be either file or comment for this command."); } var boxClient = base.ConfigureBoxClient(oneCallAsUserId: base._asUser.Value(), oneCallWithToken: base._oneUseToken.Value()); var commentCreate = new BoxCommentRequest(); commentCreate.Item = new BoxRequestEntity() { Id = this._itemId.Value }; if (type == "file") { commentCreate.Item.Type = BoxType.file; } else if (type == "comment") { commentCreate.Item.Type = BoxType.comment; } if (this._message.HasValue()) { commentCreate.Message = this._message.Value(); } if (this._taggedMessage.HasValue()) { commentCreate.TaggedMessage = this._taggedMessage.Value(); } var newComment = await boxClient.CommentsManager.AddCommentAsync(commentCreate); if (base._json.HasValue() || this._home.GetBoxHomeSettings().GetOutputJsonSetting()) { base.OutputJson(newComment); return; } Reporter.WriteSuccess("Created comment."); base.PrintComment(newComment); }
private async Task RunUpdate() { base.CheckForValue(this._commentId.Value, this._app, "A comment ID is required for this command"); var boxClient = base.ConfigureBoxClient(oneCallAsUserId: base._asUser.Value(), oneCallWithToken: base._oneUseToken.Value()); var commentUpdate = new BoxCommentRequest(); if (this._message.HasValue()) { commentUpdate.Message = this._message.Value(); } var updatedComment = await boxClient.CommentsManager.UpdateAsync(this._commentId.Value, commentUpdate); if (base._json.HasValue() || this._home.GetBoxHomeSettings().GetOutputJsonSetting()) { base.OutputJson(updatedComment); return; } Reporter.WriteSuccess("Updated comment."); base.PrintComment(updatedComment); }