/// <summary> /// Used to assign a task to a single user. There can be multiple assignments on a given task. /// </summary> /// <param name="taskAssignmentRequest">BoxTaskAssignmentRequest object.</param> /// <returns>A new task assignment object will be returned upon success.</returns> public async Task<BoxTaskAssignment> CreateTaskAssignmentAsync(BoxTaskAssignmentRequest taskAssignmentRequest) { taskAssignmentRequest.ThrowIfNull("taskAssignmentRequest") .Task.ThrowIfNull("taskAssignmentRequest.Task") .Id.ThrowIfNullOrWhiteSpace("taskAssignmentRequest.Task.Id"); taskAssignmentRequest.AssignTo.ThrowIfNull("taskAssignmentRequest.AssignTo"); if (string.IsNullOrEmpty(taskAssignmentRequest.AssignTo.Login) && string.IsNullOrEmpty(taskAssignmentRequest.AssignTo.Id)) { throw new ArgumentException("At least one of Id or Login is required in this object.", "taskAssignmentRequest.AssignTo"); } BoxRequest request = new BoxRequest(_config.TaskAssignmentsEndpointUri) .Method(RequestMethod.Post) .Payload(_converter.Serialize(taskAssignmentRequest)); IBoxResponse<BoxTaskAssignment> response = await ToResponseAsync<BoxTaskAssignment>(request).ConfigureAwait(false); return response.ResponseObject; }
public async Task CreateTaskAssignment_ValidResponse() { /*** Arrange ***/ string responseString = @"{ ""type"": ""task_assignment"", ""id"": ""2698512"", ""item"": { ""type"": ""file"", ""id"": ""8018809384"", ""sequence_id"": ""0"", ""etag"": ""0"", ""sha1"": ""7840095ee096ee8297676a138d4e316eabb3ec96"", ""name"": ""scrumworksToTrello.js"" }, ""assigned_to"": { ""type"": ""user"", ""id"": ""1992432"", ""name"": ""*****@*****.**"", ""login"": ""*****@*****.**"" }, ""message"": null, ""completed_at"": null, ""assigned_at"": ""2013-05-10T11:43:41-07:00"", ""reminded_at"": null, ""resolution_state"": ""incomplete"", ""assigned_by"": { ""type"": ""user"", ""id"": ""11993747"", ""name"": ""sean"", ""login"": ""*****@*****.**"" } }"; IBoxRequest boxRequest = null; Uri taskAssignmentsUri = new Uri(Constants.TaskAssignmentsEndpointString); _config.SetupGet(x => x.TaskAssignmentsEndpointUri).Returns(taskAssignmentsUri); _handler.Setup(h => h.ExecuteAsync<BoxTaskAssignment>(It.IsAny<IBoxRequest>())) .Returns(Task.FromResult<IBoxResponse<BoxTaskAssignment>>(new BoxResponse<BoxTaskAssignment>() { Status = ResponseStatus.Success, ContentString = responseString })) .Callback<IBoxRequest>(r => boxRequest = r); /*** Act ***/ BoxTaskAssignmentRequest taskAssignmentRequest = new BoxTaskAssignmentRequest() { Task = new BoxTaskRequest() { Id = "1992432" }, AssignTo = new BoxAssignmentRequest() { Id = "1992432" } }; BoxTaskAssignment result = await _tasksManager.CreateTaskAssignmentAsync(taskAssignmentRequest); /*** Assert ***/ //Request check Assert.IsNotNull(boxRequest); Assert.AreEqual(RequestMethod.Post, boxRequest.Method); Assert.AreEqual(taskAssignmentsUri, boxRequest.AbsoluteUri.AbsoluteUri); BoxTaskAssignmentRequest payload = JsonConvert.DeserializeObject<BoxTaskAssignmentRequest>(boxRequest.Payload); Assert.AreEqual(taskAssignmentRequest.Task.Id, payload.Task.Id); Assert.AreEqual(taskAssignmentRequest.Task.Type, payload.Task.Type); Assert.AreEqual(taskAssignmentRequest.AssignTo.Id, payload.AssignTo.Id); Assert.AreEqual(taskAssignmentRequest.AssignTo.Login, payload.AssignTo.Login); //Response check Assert.AreEqual("2698512", result.Id); Assert.AreEqual("task_assignment", result.Type); Assert.AreEqual("8018809384", result.Item.Id); Assert.AreEqual("file", result.Item.Type); Assert.AreEqual("0", result.Item.ETag); Assert.AreEqual(ResolutionStateType.incomplete, result.ResolutionState); Assert.AreEqual("*****@*****.**", result.AssignedBy.Login); Assert.AreEqual("11993747", result.AssignedBy.Id); Assert.AreEqual("*****@*****.**", result.AssignedTo.Login); Assert.AreEqual("1992432", result.AssignedTo.Id); }