Exemplo n.º 1
0
        public void CanPatchUsingVars()
        {
            var doc        = RavenJObject.FromObject(test);
            var resultJson = new ScriptedJsonPatcher().Apply(doc, new ScriptedPatchRequest
            {
                Script = "this.TheName = Name",
                Values = { { "Name", "ayende" } }
            });

            Assert.Equal("ayende", resultJson.Value <string>("TheName"));
        }
Exemplo n.º 2
0
        public void Manual()
        {
            var doc = RavenJObject.FromObject(new Product
            {
                Tags = new string[0],
            });
            var resultJson = new ScriptedJsonPatcher().Apply(doc, new ScriptedPatchRequest
            {
                Script = "this.Tags2 = this.Tags.Map(function(value) { return value; });",
            });

            Assert.Equal(0, resultJson.Value <RavenJArray>("Tags2").Length);
        }
Exemplo n.º 3
0
        public void CanUseLoDash()
        {
            const string email  = "*****@*****.**";
            var          doc    = RavenJObject.Parse("{\"Contact\":null}");
            const string script = "this.Emails = _.times(3, function(i) { return contact.Email + i; });";
            var          patch  = new ScriptedPatchRequest()
            {
                Script = script,
                Values = { { "contact", new { Email = email } } }
            };

            using (var scope = new DefaultScriptedJsonPatcherOperationScope())
            {
                var result = new ScriptedJsonPatcher().Apply(scope, doc, patch);
                Assert.Equal(new[] { "[email protected]", "[email protected]", "[email protected]" }, result.Value <RavenJArray>("Emails").Select(x => x.Value <string>()));
            }
        }