public async Task UpdateMetadata_LiveSession_ValidResponse() { /*** Arrange ***/ var mdReq = new BoxMetadataRequest[] { new BoxMetadataRequest() { Op = BoxMetadataOperations.Test, Path="assigned_attorney", Value="Francis Burke"}, new BoxMetadataRequest() { Op = BoxMetadataOperations.Replace, Path="assigned_attorney", Value="Eugene Huang"}, new BoxMetadataRequest() { Op = BoxMetadataOperations.Test, Path="case_status", Value="in-progress"}, new BoxMetadataRequest() { Op = BoxMetadataOperations.Remove, Path="case_status", Value="Francis Burke"}, new BoxMetadataRequest() { Op = BoxMetadataOperations.Add, Path="retention_length", Value="7_years"} }; /*** Act ***/ BoxMetadata md = await _client.ResourcePlugins.Get<BoxMetadataManager>().UpdateMetadata(TestFileId, mdReq); /*** Assert ***/ Assert.IsNotNull(md.Id); Assert.AreEqual("properties", md.Type); Assert.AreEqual(string.Format("file_{0}", TestFileId), md.Parent); Assert.AreEqual("820183", md["client_number"]); Assert.AreEqual("Biomedical Corp", md["client_name"]); Assert.AreEqual("A83JAA", md["case_reference"]); Assert.AreEqual("Employment Litigation", md["case_type"]); Assert.AreEqual("Eugene Huang", md["assigned_attorney"]); Assert.AreEqual("7_years", md["retention_length"]); }
/// <summary> /// Used to update the type instance. Updates can be either add, replace, remove , or test. /// The type instance can only be updated if the type instance already exists. /// To use reserved characters like “/” and “~” defined by RFC 6092, please refer to section 4 of the API docs. /// It demonstrates escaping “/” as “~1″ and “~” as “~0″. /// </summary> /// <param name="id"></param> /// <param name="metadata"></param> /// <param name="typeInstance"></param> /// <returns></returns> public async Task<BoxMetadata> UpdateMetadata(string id, BoxMetadataRequest[] metadataRequests, string typeInstance = DefaultTypeInstance) { id.ThrowIfNullOrWhiteSpace("id"); metadataRequests.ThrowIfNull("metadataRequest"); BoxRequest request = new BoxRequest(new Uri(Constants.BoxApiUriString + string.Format(CultureInfo.InvariantCulture, MetadataEndpointPath, id, typeInstance))) .Method(RequestMethod.Put); request.Payload = _converter.Serialize(metadataRequests); request.ContentType = JsonPatchContentType; IBoxResponse<BoxMetadata> response = await ToResponseAsync<BoxMetadata>(request).ConfigureAwait(false); return response.ResponseObject; }
public async Task UpdateMetadata_ValidResponse_ValidMetadata() { /*** Arrange ***/ var responseString = "{\"$id\":\"c79896a0-a33f-11e3-a5e2-0800200c9a66\",\"$type\": \"properties\",\"$parent\": \"file_552345101\",\"client_number\": \"820183\",\"client_name\": \"Biomedical Corp\",\"case_reference\": \"A83JAA\",\"case_type\": \"Employment Litigation\",\"assigned_attorney\": \"Eugene Huang\",\"retention_length\": \"7_years\"}"; _handler.Setup(h => h.ExecuteAsync<BoxMetadata>(It.IsAny<IBoxRequest>())) .Returns(Task.FromResult<IBoxResponse<BoxMetadata>>(new BoxResponse<BoxMetadata>() { Status = ResponseStatus.Success, ContentString = responseString })); var mdReq = new BoxMetadataRequest[] { new BoxMetadataRequest() { Op = BoxMetadataOperations.Test, Path="/assigned_attorney", Value="Francis Burke"}, new BoxMetadataRequest() { Op = BoxMetadataOperations.Replace, Path="/assigned_attorney", Value="Eugene Huang"}, new BoxMetadataRequest() { Op = BoxMetadataOperations.Test, Path="/case_status", Value="in-progress"}, new BoxMetadataRequest() { Op = BoxMetadataOperations.Remove, Path="/case_status", Value="Francis Burke"}, new BoxMetadataRequest() { Op = BoxMetadataOperations.Add, Path="/retention_length", Value="7_years"} }; /*** Act ***/ BoxMetadata md = await _metadataManager.UpdateMetadata("fakeId", mdReq); /*** Assert ***/ Assert.AreEqual("c79896a0-a33f-11e3-a5e2-0800200c9a66", md.Id); Assert.AreEqual("properties", md.Type); Assert.AreEqual("file_552345101", md.Parent); Assert.AreEqual("820183", md["client_number"]); Assert.AreEqual("Biomedical Corp", md["client_name"]); Assert.AreEqual("A83JAA", md["case_reference"]); Assert.AreEqual("Employment Litigation", md["case_type"]); Assert.AreEqual("Eugene Huang", md["assigned_attorney"]); Assert.AreEqual("7_years", md["retention_length"]); }