public async Task CreateNewAssignment_ValidResponse() { /*** Arrange ***/ string responseString = @"{ ""type"": ""legal_hold_policy_assignment"", ""id"": ""255613"", ""legal_hold_policy"": { ""type"": ""legal_hold_policy"", ""id"": ""166757"", ""policy_name"": ""Bug Bash 5-12 Policy 3 updated"" }, ""assigned_to"": { ""type"": ""file"", ""id"": ""5025127885"" }, ""assigned_by"": { ""type"": ""user"", ""id"": ""2030388321"", ""name"": ""Steve Boxuser"", ""login"": ""*****@*****.**"" }, ""assigned_at"": ""2016-05-18T17:38:03-07:00"", ""deleted_at"": null }"; IBoxRequest boxRequest = null; Uri legalHoldPolicyAssignmentUri = new Uri(Constants.LegalHoldPolicyAssignmentsEndpointString); _config.SetupGet(x => x.LegalHoldPolicyAssignmentsEndpointUri).Returns(legalHoldPolicyAssignmentUri); _handler.Setup(h => h.ExecuteAsync<BoxLegalHoldPolicyAssignment>(It.IsAny<IBoxRequest>())) .Returns(Task.FromResult<IBoxResponse<BoxLegalHoldPolicyAssignment>>(new BoxResponse<BoxLegalHoldPolicyAssignment>() { Status = ResponseStatus.Success, ContentString = responseString })) .Callback<IBoxRequest>(r => boxRequest = r); /*** Act ***/ BoxLegalHoldPolicyAssignmentRequest createRequest = new BoxLegalHoldPolicyAssignmentRequest() { PolicyId = "166757", AssignTo = new BoxRequestEntity() { Id = "5025127885", Type = BoxType.file } }; BoxLegalHoldPolicyAssignment result = await _legalHoldPoliciesManager.CreateAssignmentAsync(createRequest); /*** Assert ***/ //Request check Assert.IsNotNull(boxRequest); Assert.AreEqual(RequestMethod.Post, boxRequest.Method); Assert.AreEqual(legalHoldPolicyAssignmentUri, boxRequest.AbsoluteUri.AbsoluteUri); BoxLegalHoldPolicyAssignmentRequest payLoad = JsonConvert.DeserializeObject<BoxLegalHoldPolicyAssignmentRequest>(boxRequest.Payload); Assert.AreEqual("166757", payLoad.PolicyId); Assert.AreEqual("5025127885", payLoad.AssignTo.Id); Assert.AreEqual(BoxType.file, payLoad.AssignTo.Type); //Response check Assert.AreEqual("legal_hold_policy_assignment", result.Type); Assert.AreEqual("255613", result.Id); Assert.AreEqual("legal_hold_policy", result.LegalHoldPolicy.Type); Assert.AreEqual("166757", result.LegalHoldPolicy.Id); Assert.AreEqual("Bug Bash 5-12 Policy 3 updated", result.LegalHoldPolicy.PolicyName); Assert.AreEqual("file", result.AssignedTo.Type); Assert.AreEqual("5025127885", result.AssignedTo.Id); Assert.AreEqual("user", result.AssignedBy.Type); Assert.AreEqual("2030388321", result.AssignedBy.Id); Assert.AreEqual("Steve Boxuser", result.AssignedBy.Name); Assert.AreEqual("*****@*****.**", result.AssignedBy.Login); Assert.IsNull(result.DeletedAt); Assert.AreEqual(DateTime.Parse("2016-05-18T17:38:03-07:00"), result.AssignedAt); }
/// <summary> /// Create a new Assignment, which will apply the Legal Hold Policy to the target of the Assignment. /// </summary> /// <param name="createRequest">BoxLegalHoldPolicyAssignmentRequest object.</param> /// <returns>For a successful request, returns object with information about the Assignment created. /// If the policy or assign-to target cannot be found, null will be returned. /// </returns> public async Task<BoxLegalHoldPolicyAssignment> CreateAssignmentAsync(BoxLegalHoldPolicyAssignmentRequest createRequest) { createRequest.ThrowIfNull("createRequest") .PolicyId.ThrowIfNullOrWhiteSpace("createRequest.PolicyId"); createRequest.AssignTo.ThrowIfNull("createRequest.AssignTo") .Id.ThrowIfNullOrWhiteSpace("createRequest.AssignTo.Id"); createRequest.AssignTo.Type.ThrowIfNull("createRequest.AssignTo.Type"); BoxRequest request = new BoxRequest(_config.LegalHoldPolicyAssignmentsEndpointUri) .Method(RequestMethod.Post) .Payload(_converter.Serialize(createRequest)); IBoxResponse<BoxLegalHoldPolicyAssignment> response = await ToResponseAsync<BoxLegalHoldPolicyAssignment>(request).ConfigureAwait(false); return response.ResponseObject; }