public async Task UpdateFileMetadata_ValidResponse_ValidEntries()
{
/*** Arrange ***/
string responseString = @"{
""audience1"": ""internal"",
""documentType"": ""Q1 plans"",
""status"": ""inactive"",
""author"": ""Jones"",
""$type"": ""marketingCollateral-d086c908-2498-4d3e-8a1f-01e82bfc2abe"",
""$parent"": ""file_5010739061"",
""$id"": ""2094c584-68e1-475c-a581-534a4609594e"",
""$version"": 1,
""$typeVersion"": 0,
""editor"": ""Jones"",
""previousState"": ""proposal"",
""currentState"": ""reviewed"",
""$template"": ""marketingCollateral"",
""$scope"": ""enterprise_12345""
}";
IBoxRequest boxRequest = null;
_handler.Setup(h => h.ExecuteAsync<Dictionary<string, object>>(It.IsAny<IBoxRequest>()))
.Returns(Task.FromResult<IBoxResponse<Dictionary<string, object>>>(new BoxResponse<Dictionary<string, object>>()
{
Status = ResponseStatus.Success,
ContentString = responseString
})).Callback<IBoxRequest>(r => boxRequest = r);
/*** Act ***/
List<BoxMetadataUpdate> updates = new List<BoxMetadataUpdate>()
{
new BoxMetadataUpdate()
{
Op = MetadataUpdateOp.test,
Path = "/competitiveDocument",
Value = "no"
},
new BoxMetadataUpdate()
{
Op = MetadataUpdateOp.remove,
Path = "/competitiveDocument"
},
new BoxMetadataUpdate()
{
Op = MetadataUpdateOp.test,
Path = "/status",
Value = "active"
},
new BoxMetadataUpdate()
{
Op = MetadataUpdateOp.replace,
Path = "/competitiveDocument",
Value = "inactive"
},
new BoxMetadataUpdate()
{
Op = MetadataUpdateOp.test,
Path = "/author",
Value = "Jones"
},
new BoxMetadataUpdate()
{
Op = MetadataUpdateOp.copy,
From="/author",
Path = "/editor"
},
new BoxMetadataUpdate()
{
Op = MetadataUpdateOp.test,
Path = "/currentState",
Value = "proposal"
},
new BoxMetadataUpdate()
{
Op = MetadataUpdateOp.move,
From = "/currentState",
Path = "/previousState"
},
new BoxMetadataUpdate()
{
Op = MetadataUpdateOp.add,
Path = "/currentState",
Value = "reviewed"
},
};
Dictionary<string, object> result = await _metadataManager.UpdateFileMetadataAsync("5010739061", updates, "enterprise", "marketingCollateral");
/*** Assert ***/
/***request***/
List<BoxMetadataUpdate> payLoad = JsonConvert.DeserializeObject<List<BoxMetadataUpdate>>(boxRequest.Payload);
for (int i = 0; i < payLoad.Count; i++)
{
Assert.AreEqual(updates[i].Op, payLoad[i].Op);
Assert.AreEqual(updates[i].Path, payLoad[i].Path);
}
/***response***/
Assert.AreEqual("internal", result["audience1"]);
Assert.AreEqual("Q1 plans", result["documentType"]);
Assert.AreEqual((long)1, result["$version"]);
Assert.AreEqual("reviewed", result["currentState"]);
}
}