Exemplo n.º 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;
        }
        public void ShouldReplaceValueForArray()
        {
            dynamic _Object = JObject.Parse(@"
                                {'baz': [{'name': 'foo'},{'name': 'bar'}]}"
                );

            Operation operation = new ReplaceOperation() { Target = _Object, Path = "$.baz[0].name", Value="boo" };
            operation.Execute();
            string result = SerializeObject(_Object);
            result.ShouldBe(@"{'baz':[{'name':'boo'},{'name':'bar'}]}");
        }
        public void ShouldReplaceValueForComplexProperty()
        {
            dynamic _Object = JObject.Parse(@"
                                {
                                 'baz': {'age': 1},
                                 'foo': 'bar'
                                 }"
                );

            Operation operation = new ReplaceOperation() { Target = _Object, Path = "$.baz.age", Value=2};
            operation.Execute();
            string result = SerializeObject(_Object);
            result.ShouldBe(@"{'baz':{'age':2},'foo':'bar'}");
        }
        public void ShouldReplaceValueForSimpleProperty()
        {
            dynamic _Object = JObject.Parse(@"
                                {
                                 'baz': 'qux',
                                 'foo': 'bar'
                                 }"
                );

            Operation operation = new ReplaceOperation() { Target = _Object, Path = "$.baz", Value="boo"};
            operation.Execute();
            string result = SerializeObject(_Object);
            result.ShouldBe(@"{'baz':'boo','foo':'bar'}");
        }