Пример #1
0
        public void RenameAllItemsInArray()
        {
            var patchedDoc = new JsonPatcher(doc).Apply(
                new[]
            {
                new PatchRequest
                {
                    Type         = PatchCommandType.Modify,
                    Name         = "comments",
                    AllPositions = true,
                    Nested       = new[]
                    {
                        new PatchRequest {
                            Type = PatchCommandType.Rename, Name = "author", Value = "authorname"
                        },
                    }
                },
            });

            Assert.Equal(@"{""title"":""A Blog Post"",""body"":""html markup"",""comments"":[{""text"":""good post 1"",""authorname"":""ayende""},{""text"":""good post 2"",""authorname"":""ayende""}],""user"":{""name"":""ayende"",""id"":13}}",
                         patchedDoc.ToString(Formatting.None));
        }
Пример #2
0
        public void SetValueNestedInArray()
        {
            var patchedDoc = new JsonPatcher(doc).Apply(
                new[]
            {
                new PatchRequest
                {
                    Type     = PatchCommandType.Modify,
                    Name     = "comments",
                    Position = 1,
                    Nested   = new[]
                    {
                        new PatchRequest {
                            Type = PatchCommandType.Set, Name = "author", Value = new RavenJValue("oren")
                        },
                    }
                },
            });

            Assert.Equal(@"{""title"":""A Blog Post"",""body"":""html markup"",""comments"":[{""author"":""ayende"",""text"":""good post 1""},{""author"":""oren"",""text"":""good post 2""}],""user"":{""name"":""ayende"",""id"":13}}",
                         patchedDoc.ToString(Formatting.None));
        }
Пример #3
0
        public void RemoveValueInNestedElement()
        {
            var patchedDoc = new JsonPatcher(doc).Apply(
                new[]
            {
                new PatchRequest
                {
                    Type    = PatchCommandType.Modify,
                    Name    = "user",
                    PrevVal = RavenJObject.Parse(@"{ ""name"": ""ayende"", ""id"": 13}"),
                    Nested  = new[]
                    {
                        new PatchRequest {
                            Type = PatchCommandType.Unset, Name = "name"
                        },
                    }
                },
            });

            Assert.Equal(@"{""title"":""A Blog Post"",""body"":""html markup"",""comments"":[{""author"":""ayende"",""text"":""good post 1""},{""author"":""ayende"",""text"":""good post 2""}],""user"":{""id"":13}}",
                         patchedDoc.ToString(Formatting.None));
        }
Пример #4
0
        public void SetValueInNestedElement_WithConcurrency_Ok()
        {
            var patchedDoc = new JsonPatcher(doc).Apply(
                new[]
            {
                new PatchRequest
                {
                    Type    = "modify",
                    Name    = "user",
                    PrevVal = JObject.Parse(@"{ ""name"": ""ayende"", ""id"": 13}"),
                    Nested  = new[]
                    {
                        new PatchRequest {
                            Type = "set", Name = "name", Value = new JValue("rahien")
                        },
                    }
                },
            });

            Assert.Equal(@"{""title"":""A Blog Post"",""body"":""html markup"",""comments"":[{""author"":""ayende"",""text"":""good post 1""},{""author"":""ayende"",""text"":""good post 2""}],""user"":{""name"":""rahien"",""id"":13}}",
                         patchedDoc.ToString(Formatting.None));
        }
Пример #5
0
        public void PropertyRemovalPropertyDoesNotExists()
        {
            var patchedDoc = new JsonPatcher(doc).Apply(
                new[]
            {
                new PatchRequest
                {
                    Type = PatchCommandType.Unset,
                    Name = "ip",
                },
            });

            Assert.Equal(@"{""title"":""A Blog Post"",""body"":""html markup"",""comments"":[{""author"":""ayende"",""text"":""good post""}]}", patchedDoc.ToString(Formatting.None));
        }
Пример #6
0
        public void PropertyRemoval_WithConcurrency_Ok()
        {
            var patchedDoc = new JsonPatcher(doc).Apply(
                new[]
            {
                new PatchRequest
                {
                    Type    = PatchCommandType.Unset,
                    Name    = "body",
                    PrevVal = new RavenJValue("html markup")
                },
            });

            Assert.Equal(@"{""title"":""A Blog Post"",""comments"":[{""author"":""ayende"",""text"":""good post""}]}", patchedDoc.ToString(Formatting.None));
        }
Пример #7
0
        public void PropertySetToNull()
        {
            var patchedDoc = new JsonPatcher(doc).Apply(
                new[]
            {
                new PatchRequest
                {
                    Type  = PatchCommandType.Set,
                    Name  = "title",
                    Value = new RavenJValue((object)null)
                },
            });

            Assert.Equal(@"{""title"":null,""body"":""html markup"",""comments"":[{""author"":""ayende"",""text"":""good post""}]}", patchedDoc.ToString(Formatting.None));
        }
Пример #8
0
        public void PropertyAddition_WithConcurrently_ExistingValueOn_Ok()
        {
            RavenJObject apply = new JsonPatcher(doc).Apply(
                new[]
            {
                new PatchRequest
                {
                    Type    = PatchCommandType.Set,
                    Name    = "body",
                    Value   = new RavenJValue("different markup"),
                    PrevVal = new RavenJValue("html markup")
                },
            });

            Assert.Equal(@"{""title"":""A Blog Post"",""body"":""different markup"",""comments"":[{""author"":""ayende"",""text"":""good post""}]}", apply.ToString(Formatting.None));
        }
Пример #9
0
        public void PropertyRemoval()
        {
            var patchedDoc = new JsonPatcher(doc).Apply(
                new[]
            {
                new PatchRequest
                {
                    Type = "unset",
                    Name = "body",
                },
            });

            Assert.Equal(@"{""title"":""A Blog Post"",""comments"":[{""author"":""ayende"",""text"":""good post""}]}", patchedDoc.ToString(Formatting.None));
        }
Пример #10
0
        public void PropertySet()
        {
            var patchedDoc = new JsonPatcher(doc).Apply(
                new[]
            {
                new PatchRequest
                {
                    Type  = "set",
                    Name  = "title",
                    Value = new JValue("another")
                },
            });

            Assert.Equal(@"{""title"":""another"",""body"":""html markup"",""comments"":[{""author"":""ayende"",""text"":""good post""}]}", patchedDoc.ToString(Formatting.None));
        }