Request for creating a single task for single user on a single file
Exemplo n.º 1
0
        /// <summary>
        /// Updates a specific task.
        /// </summary>
        /// <param name="taskUpdateRequest">BoxTaskUpdateRequest object.</param>
        /// <returns>The updated task object will be returned upon success.</returns>
        public async Task<BoxTask> UpdateTaskAsync(BoxTaskUpdateRequest taskUpdateRequest)
        {
            taskUpdateRequest.ThrowIfNull("taskUpdateRequest");

            BoxRequest request = new BoxRequest(_config.TasksEndpointUri, taskUpdateRequest.Id)
                .Method(RequestMethod.Put)
                .Payload(_converter.Serialize(taskUpdateRequest));

            IBoxResponse<BoxTask> response = await ToResponseAsync<BoxTask>(request).ConfigureAwait(false);

            return response.ResponseObject;
        }
Exemplo n.º 2
0
        public async Task UpdateTask_ValidResponse()
        {
            /*** Arrange ***/
            string responseString = @"{
                                        ""type"": ""task"",
                                        ""id"": ""1839355"",
                                        ""item"": {
                                            ""type"": ""file"",
                                            ""id"": ""7287087200"",
                                            ""sequence_id"": ""0"",
                                            ""etag"": ""0"",
                                            ""sha1"": ""0bbd79a105c504f99573e3799756debba4c760cd"",
                                            ""name"": ""box-logo.png""
                                        },
                                        ""due_at"": ""2014-04-03T11:09:43-07:00"",
                                        ""action"": ""review"",
                                        ""message"": ""REVIEW PLZ K THX"",
                                        ""task_assignment_collection"": {
                                            ""total_count"": 0,
                                            ""entries"": []
                                        },
                                        ""is_completed"": false,
                                        ""created_by"": {
                                            ""type"": ""user"",
                                            ""id"": ""11993747"",
                                            ""name"": ""sean"",
                                            ""login"": ""*****@*****.**""
                                        },
                                        ""created_at"": ""2013-04-03T11:12:54-07:00""
                                    }";
            IBoxRequest boxRequest = null;
            Uri tasksUri = new Uri(Constants.TasksEndpointString);
            _config.SetupGet(x => x.TasksEndpointUri).Returns(tasksUri);
            _handler.Setup(h => h.ExecuteAsync<BoxTask>(It.IsAny<IBoxRequest>()))
                .Returns(Task.FromResult<IBoxResponse<BoxTask>>(new BoxResponse<BoxTask>()
                {
                    Status = ResponseStatus.Success,
                    ContentString = responseString
                }))
                .Callback<IBoxRequest>(r => boxRequest = r);

            /*** Act ***/
            BoxTaskUpdateRequest taskUpdateRequest = new BoxTaskUpdateRequest()
            {
                Id = "1839355",
                Message = "REVIEW PLZ K THX"
            };
            BoxTask result = await _tasksManager.UpdateTaskAsync(taskUpdateRequest);

            /*** Assert ***/
            //Request check
            Assert.IsNotNull(boxRequest);
            Assert.AreEqual(RequestMethod.Put, boxRequest.Method);
            Assert.AreEqual(tasksUri + "1839355", boxRequest.AbsoluteUri.AbsoluteUri);
            BoxTaskUpdateRequest payload = JsonConvert.DeserializeObject<BoxTaskUpdateRequest>(boxRequest.Payload);
            Assert.AreEqual(taskUpdateRequest.Message, payload.Message);

            //Response check
            Assert.AreEqual("1839355", result.Id);
            Assert.AreEqual("task", result.Type);
            Assert.AreEqual("7287087200", result.Item.Id);
            Assert.AreEqual("file", result.Item.Type);
            Assert.AreEqual("0", result.Item.ETag);
            Assert.AreEqual("REVIEW PLZ K THX", result.Message);
            Assert.AreEqual(false, result.IsCompleted);
            Assert.AreEqual("11993747", result.CreatedBy.Id);
            Assert.AreEqual("*****@*****.**", result.CreatedBy.Login);
            Assert.AreEqual(0, result.TaskAssignments.TotalCount);

        }