public void ReplaceGuidTest()
        {
            var doc = new SimpleObject()
            {
                GuidValue = Guid.NewGuid()
            };

            var newGuid = Guid.NewGuid();
            // create patch
            var patchDoc = new JsonPatchDocument();

            patchDoc.Replace("GuidValue", newGuid);

            // serialize & deserialize
            var serialized    = JsonConvert.SerializeObject(patchDoc);
            var deserizalized = JsonConvert.DeserializeObject <JsonPatchDocument>(serialized);

            deserizalized.ApplyTo(doc);

            Assert.Equal(newGuid, doc.GuidValue);
        }
        public void Move()
        {
            var doc = new SimpleObject()
            {
                StringProperty        = "A",
                AnotherStringProperty = "B"
            };

            // create patch
            var patchDoc = new JsonPatchDocument();

            patchDoc.Move("StringProperty", "AnotherStringProperty");

            var serialized   = JsonConvert.SerializeObject(patchDoc);
            var deserialized = JsonConvert.DeserializeObject <JsonPatchDocument>(serialized);

            deserialized.ApplyTo(doc);

            Assert.Equal("A", doc.AnotherStringProperty);
            Assert.Null(doc.StringProperty);
        }
        public void CopyFromListToNonList()
        {
            var doc = new SimpleObject()
            {
                IntegerList = new List <int>()
                {
                    1, 2, 3
                }
            };

            // create patch
            var patchDoc = new JsonPatchDocument();

            patchDoc.Copy("IntegerList/0", "IntegerValue");

            var serialized   = JsonConvert.SerializeObject(patchDoc);
            var deserialized = JsonConvert.DeserializeObject <JsonPatchDocument>(serialized);

            deserialized.ApplyTo(doc);

            Assert.Equal(1, doc.IntegerValue);
        }
Ejemplo n.º 4
0
        public void Add_CompatibleTypeWorks()
        {
            // Arrange
            var sDto         = new SimpleObject();
            var iDto         = new InheritedObject();
            var resolver     = new DefaultContractResolver();
            var targetObject = new List <SimpleObject>()
            {
                sDto
            };
            var listAdapter = new ListAdapter();

            // Act
            var addStatus = listAdapter.TryAdd(targetObject, "-", resolver, iDto, out var message);

            // Assert
            Assert.True(addStatus);
            Assert.True(string.IsNullOrEmpty(message), "Expected no error message");
            Assert.Equal(2, targetObject.Count);
            Assert.Equal(new List <SimpleObject>()
            {
                sDto, iDto
            }, targetObject);
        }
Ejemplo n.º 5
0
        public void GenericPatchDocToNonGenericMustSerialize()
        {
            var doc = new SimpleObject()
            {
                StringProperty        = "A",
                AnotherStringProperty = "B"
            };

            var patchDocTyped = new JsonPatchDocument <SimpleObject>();

            patchDocTyped.Copy(o => o.StringProperty, o => o.AnotherStringProperty);

            var patchDocUntyped = new JsonPatchDocument();

            patchDocUntyped.Copy("StringProperty", "AnotherStringProperty");

            var serializedTyped   = JsonConvert.SerializeObject(patchDocTyped);
            var serializedUntyped = JsonConvert.SerializeObject(patchDocUntyped);
            var deserialized      = JsonConvert.DeserializeObject <JsonPatchDocument>(serializedTyped);

            deserialized.ApplyTo(doc);

            Assert.Equal("A", doc.AnotherStringProperty);
        }
 public SimpleObjectWithNestedObject()
 {
     NestedObject       = new NestedObject();
     SimpleObject       = new SimpleObject();
     ListOfSimpleObject = new List <SimpleObject>();
 }