Exemplo n.º 1
0
        public void ApplyTo_Model_Test1()
        {
            // Arrange
            var model = new ObjectWithJObject {
                CustomData = JObject.FromObject(new { Email = "*****@*****.**", Name = "Bar" })
            };
            var patch = new JsonPatchDocument <ObjectWithJObject>();

            patch.Operations.Add(new Operation <ObjectWithJObject>("test", "/CustomData/Email", null, "*****@*****.**"));
            patch.Operations.Add(new Operation <ObjectWithJObject>("add", "/CustomData/Name", null, "Bar Baz"));

            // Act & Assert
            Assert.Throws <JsonPatchException>(() => patch.ApplyTo(model));
        }
Exemplo n.º 2
0
        public void ApplyTo_Model_Add()
        {
            // Arrange
            var model = new ObjectWithJObject();
            var patch = new JsonPatchDocument <ObjectWithJObject>();

            patch.Operations.Add(new Operation <ObjectWithJObject>("add", "/CustomData/Name", null, "Foo"));

            // Act
            patch.ApplyTo(model);

            // Assert
            Assert.Equal("Foo", model.CustomData["Name"].Value <string>());
        }
Exemplo n.º 3
0
        public void ApplyTo_Model_Add_Null()
        {
            // Arrange
            var model = new ObjectWithJObject();
            var patch = new JsonPatchDocument <ObjectWithJObject>();

            patch.Operations.Add(new Operation <ObjectWithJObject>("add", "/CustomData/Name", null, null));

            // Act
            patch.ApplyTo(model);

            // Assert
            Assert.Equal(JTokenType.Null, model.CustomData["Name"].Type);
        }
Exemplo n.º 4
0
        public void ApplyTo_Model_Remove()
        {
            // Arrange
            var model = new ObjectWithJObject {
                CustomData = JObject.FromObject(new { FirstName = "Foo", LastName = "Bar" })
            };
            var patch = new JsonPatchDocument <ObjectWithJObject>();

            patch.Operations.Add(new Operation <ObjectWithJObject>("remove", "/CustomData/LastName", null));

            // Act
            patch.ApplyTo(model);

            // Assert
            Assert.False(model.CustomData.ContainsKey("LastName"));
        }
Exemplo n.º 5
0
        public void ApplyTo_Model_Copy()
        {
            // Arrange
            var model = new ObjectWithJObject {
                CustomData = JObject.FromObject(new { Email = "*****@*****.**" })
            };
            var patch = new JsonPatchDocument <ObjectWithJObject>();

            patch.Operations.Add(new Operation <ObjectWithJObject>("copy", "/CustomData/UserName", "/CustomData/Email"));

            // Act
            patch.ApplyTo(model);

            // Assert
            Assert.Equal("*****@*****.**", model.CustomData["UserName"].Value <string>());
        }
Exemplo n.º 6
0
        public void ApplyTo_Array_Add()
        {
            // Arrange
            var model = new ObjectWithJObject {
                CustomData = JObject.FromObject(new { Emails = new[] { "*****@*****.**" } })
            };
            var patch = new JsonPatchDocument <ObjectWithJObject>();

            patch.Operations.Add(new Operation <ObjectWithJObject>("add", "/CustomData/Emails/-", null, "*****@*****.**"));

            // Act
            patch.ApplyTo(model);

            // Assert
            Assert.Equal("*****@*****.**", model.CustomData["Emails"][1].Value <string>());
        }
Exemplo n.º 7
0
        public void ApplyTo_Model_Replace()
        {
            // Arrange
            var model = new ObjectWithJObject {
                CustomData = JObject.FromObject(new { Email = "*****@*****.**", Name = "Bar" })
            };
            var patch = new JsonPatchDocument <ObjectWithJObject>();

            patch.Operations.Add(new Operation <ObjectWithJObject>("replace", "/CustomData/Email", null, "*****@*****.**"));

            // Act
            patch.ApplyTo(model);

            // Assert
            Assert.Equal("*****@*****.**", model.CustomData["Email"].Value <string>());
        }
Exemplo n.º 8
0
        public void ApplyTo_Model_Move()
        {
            // Arrange
            var model = new ObjectWithJObject {
                CustomData = JObject.FromObject(new { FirstName = "Bar" })
            };
            var patch = new JsonPatchDocument <ObjectWithJObject>();

            patch.Operations.Add(new Operation <ObjectWithJObject>("move", "/CustomData/LastName", "/CustomData/FirstName"));

            // Act
            patch.ApplyTo(model);

            // Assert
            Assert.False(model.CustomData.ContainsKey("FirstName"));
            Assert.Equal("Bar", model.CustomData["LastName"].Value <string>());
        }