/// <inheritdoc />
        public override async Task <ResourceResponse> ExecuteAsync(PatchResourceRequest request)
        {
            try
            {
                var resource = await this.Repository.ReadResourceAsync(request.ResourceId);

                resource = this.PatchApplier.ApplyTo(resource, PatchOperation.Parse(request.Payload));
                resource = await this.Repository.UpdateResourceAsync(resource);

                return(new ResourceResponse {
                    Code = ResponseCode.Success, Resource = resource
                });
            }
            catch (ResourceNotFoundException exception)
            {
                return(new ResourceResponse {
                    Code = ResponseCode.ResourceNotFound, Exception = exception
                });
            }
            catch (Exception exception)
            {
                return(new ResourceResponse {
                    Code = ResponseCode.Failure, Exception = exception
                });
            }
        }
Ejemplo n.º 2
0
        public void TestJsonArrayCanBeParsed()
        {
            var result = PatchOperation.Parse(
                "[{ \"op\": \"test\", \"path\": \"/a/b/c\", \"value\": \"foo\" }, { \"op\": \"remove\", \"path\": \"/a/b/c\" }]");

            Assert.AreEqual(2, result.Count);

            Assert.AreEqual("test", result[0].Operation);
            Assert.AreEqual("/a/b/c", result[0].Path);
            Assert.AreEqual("foo", result[0].Value);
        }
Ejemplo n.º 3
0
 public void TestMalformedJsonInputShouldThrowException()
 {
     PatchOperation.Parse("[{ \"opsss\": \"test\", \"path\": \"/a/b/c\", \"value\": \"foo\" }]");
 }