コード例 #1
0
        public static Operation FromTemplate(OperationTemplate template)
        {
            Operation op = null;

            if (template.op == "add")
            {
                op = new AddOperation();
            }
            else if (template.op == "remove")
            {
                op = new RemoveOperation();
            }
            else if (template.op == "test")
            {
                op = new TestOperation();
            }
            else if (template.op == "move")
            {
                op = new MoveOperation();
            }
            else if (template.op == "copy")
            {
                op = new CopyOperation();
            }
            else if (template.op == "replace")
            {
                op = new ReplaceOperation();
            }

            op.CopyPropertiesFrom(template);

            return op;
        }
コード例 #2
0
        public void RemoveAValueFromAValueArrayAtIndex1_ShouldRemoveMember()
        {
            dynamic _Object = JObject.Parse(@"
                                {'baz': ['foo','bar','ooz']}"
                );

            Operation operation = new RemoveOperation() { Target = _Object, Path = "$.baz[1]" };
            operation.Execute();
            string result = SerializeObject(_Object);
            result.ShouldBe(@"{'baz':['foo','ooz']}");
        }
コード例 #3
0
        protected override void DoExecute()
        {
            var existingValue = Target.SelectToken(From);

            if (existingValue != null)
            {
                Operation removeoperation = new RemoveOperation() { Target = Target, Path = From};
                removeoperation.Execute();
                Operation addOperation = new AddOperation() { Target = Target, Path = Path, Value = existingValue };
                addOperation.Execute();
            }
        }
コード例 #4
0
        public void RemoveAComplexObjectMember_ShouldRemoveMember()
        {
            dynamic _Object = JObject.Parse(@"
                                {
                                 'baz': {'age': 1},
                                 'foo': 'bar'
                                 }"
                );

            Operation operation = new RemoveOperation() { Target = _Object, Path = "$.baz.age" };
            operation.Execute();
            string result = SerializeObject(_Object);
            result.ShouldBe(@"{'foo':'bar'}");
        }
コード例 #5
0
        public void RemoveArrayIfEmpty_ShouldRemoveMember()
        {
            dynamic _Object = JObject.Parse(@"
                                {'baz': ['foo']}"
                );

            Operation operation = new RemoveOperation() { Target = _Object, Path = "$.baz[0]" };
            operation.Execute();
            string result = SerializeObject(_Object);
            result.ShouldBe(@"{}");
        }
コード例 #6
0
        public void RemoveArrayWithMultipleEntryIfOneEntryEmpty_ShouldRemoveMember()
        {
            dynamic _Object = JObject.Parse(@"
                                { 'baz' : [{'prop1':'1','prop2':'2'},{'prop1':'1','prop2':'2'}]}"
                );

            Operation operation = new RemoveOperation() { Target = _Object, Path = "$.baz[0].prop1" };
            operation.Execute();
            operation = new RemoveOperation() { Target = _Object, Path = "$.baz[0].prop2" };
            operation.Execute();
            string result = SerializeObject(_Object);
            result.ShouldBe(@"{'baz':[{'prop1':'1','prop2':'2'}]}");

            //second part remove the array if empty
            operation = new RemoveOperation() { Target = _Object, Path = "$.baz[0].prop1" };
            operation.Execute();
            operation = new RemoveOperation() { Target = _Object, Path = "$.baz[0].prop2" };
            operation.Execute();
            result = SerializeObject(_Object);
            result.ShouldBe(@"{}");
        }