예제 #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 AddOperationOnExistingProperties_ShouldReplaceValueForArrayProperty()
 {
     _emptyObject.Address = JArray.Parse("[{'Street':'Hell Lane'}]");
     Operation operation = new AddOperation() { Target = _emptyObject, Path = "Address[0].Street", Value = "Paradise Lane" };
     operation.Execute();
     ((string)_emptyObject.Address[0].Street).ShouldBe("Paradise Lane");
 }
 public void AddOperationOnExistingProperties_Should_ReplaceValueForSimpleProperty()
 {
     _emptyObject.FirstName = "ToBeReplaced";
     Operation operation = new AddOperation() { Target = _emptyObject, Path = "FirstName", Value = "Cedric" };
     operation.Execute();
     ((string)_emptyObject.FirstName).ShouldBe("Cedric");
 }
        public void ShouldInsertValueAtIndexContainedInArray()
        {
            dynamic obj = JObject.Parse(@"{'baz': [{'name': 'foo'},{'name': 'bar'}]}");
            dynamic objToBeInserted = JObject.Parse(@"{'name': 'boo'}");

            Operation operation = new AddOperation() { Target = obj, Path = "$.baz[1]", Value=objToBeInserted };
            operation.Execute();
            string result = SerializeObject(obj);
            result.ShouldBe(@"{'baz':[{'name':'foo'},{'name':'boo'},{'name':'bar'}]}");
        }
        protected override void DoExecute()
        {
            var existingValue = Target.SelectToken(From);

            if (existingValue != null)
            {
                Operation operation = new AddOperation() { Target = Target, Path = Path, Value = existingValue };
                operation.Execute();
            }


        }
        public void ShouldAddPropertyAtObjectInIndexContainedInArray()
        {
            dynamic obj = JObject.Parse(@"{'baz': [{'name': 'foo'},{'name': 'bar'}]}");

            Operation operation = new AddOperation() { Target = obj, Path = "$.baz[1].lastName", Value = "myLastName" };
            operation.Execute();
            string result = SerializeObject(obj);
            result.ShouldBe(@"{'baz':[{'name':'foo'},{'name':'bar','lastName':'myLastName'}]}");
        }
 public void AddOperationOnEmptyObject_ShouldAddArray()
 {
     Operation operation = new AddOperation() { Target = _emptyObject, Path = "Address[0].Street", Value = "Paradise Lane" };
     operation.Execute();
     ((string)_emptyObject.Address[0].Street).ShouldBe("Paradise Lane");
 }
 public void AddOperationOnEmptyObject_ShouldAddComplexProperty()
 {
     Operation operation = new AddOperation() { Target = _emptyObject, Path = "Name.FirstName", Value = "Cedric" };
     operation.Execute();
     ((string)_emptyObject.Name.FirstName).ShouldBe("Cedric");
 }