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)); }
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)); }
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)); }
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)); }
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)); }
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)); }
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)); }
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)); }
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)); }
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)); }