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 ShouldMoveObjectBetweenTwoArray()
        {
            dynamic _Object = JObject.Parse(@"
                                {'baz': [{'name': 'foo'},{'name': 'bar'}],
                                 'boo': [{'name': 'zoo'},{'name': 'ear'}]}"
                );

            Operation operation = new CopyOperation() { Target = _Object, From = "$.baz[0]", Path = "$.boo[1]" };
            operation.Execute();
            string result = SerializeObject(_Object);
            result.ShouldBe(@"{'baz':[{'name':'foo'},{'name':'bar'}],'boo':[{'name':'zoo'},{'name':'foo'},{'name':'ear'}]}");
        }
        public void ShouldCopyValueForSimpleProperty()
        {
            dynamic _Object = JObject.Parse(@"
                                {
                                 'baz': 'qux',
                                 'foo': 'bar'
                                 }"
                );

            Operation operation = new CopyOperation() { Target = _Object, From= "$.baz", Path = "$.boo"};
            operation.Execute();
            string result = SerializeObject(_Object);
            result.ShouldBe(@"{'baz':'qux','foo':'bar','boo':'qux'}");
        }
        public void ShouldCopyValueForComplexProperty()
        {
            dynamic _Object = JObject.Parse(@"
                            {
                             'foo': {
                               'bar': 'baz',
                               'waldo': 'fred'
                             },
                             'qux': {
                               'corge': 'grault'
                             }
                           }"
                );

            Operation operation = new CopyOperation() { Target = _Object, From="$.foo.waldo", Path="$.qux.thud"};
            operation.Execute();
            string result = SerializeObject(_Object);
            result.ShouldBe(@"{'foo':{'bar':'baz','waldo':'fred'},'qux':{'corge':'grault','thud':'fred'}}");
        }