public void CanRemoveFromCollectionByValue() { var doc = RavenJObject.FromObject(test); var resultJson = new ScriptedJsonPatcher().Apply(doc, new ScriptedPatchRequest { Script = @" this.Comments.Remove('two'); " }); var result = JsonConvert.DeserializeObject <CustomType>(resultJson.ToString()); Assert.Equal(new[] { "one", "seven" }.ToList(), result.Comments); }
public void CanApplyBasicScriptAsPatch() { var doc = RavenJObject.FromObject(test); var resultJson = new ScriptedJsonPatcher().Apply(doc, new ScriptedPatchRequest { Script = sampleScript }); var result = JsonConvert.DeserializeObject <CustomType>(resultJson.ToString()); Assert.Equal("Something new", result.Id); Assert.Equal(2, result.Comments.Count); Assert.Equal("one test", result.Comments[0]); Assert.Equal("two", result.Comments[1]); Assert.Equal(12144, result.Value); Assert.Equal("err!!", resultJson["newValue"]); }
public void CanPatchUsingRavenJObjectVars() { var doc = RavenJObject.FromObject(test); var variableSource = new { NewComment = "New Comment" }; var variable = RavenJObject.FromObject(variableSource); var script = "this.Comments[0] = variable.NewComment;"; var patch = new ScriptedPatchRequest() { Script = script, Values = { { "variable", variable } } }; var resultJson = new ScriptedJsonPatcher().Apply(doc, patch); var result = JsonConvert.DeserializeObject <CustomType>(resultJson.ToString()); Assert.Equal(variableSource.NewComment, result.Comments[0]); }