예제 #1
0
        public void ReducePatch__Given_ArrayPropertyNotEqual__Then_PatchEntireArray(TestJsonObject obj)
        {
            // Assemble
            var original = JObject.FromObject(obj);

            obj.OtherChildren.First().String = "Updated Value";
            var update  = JObject.FromObject(obj);
            var subject = new JsonDiff();

            // Act
            var result = (JObject)subject.ReducePatch(original, update);

            // Assert
            Assert.NotNull(result);

            // All values should be included in array patch
            Assert.Equal(obj.OtherChildren.Count, result[nameof(obj.OtherChildren)].Count());
            var otherChildObj  = obj.OtherChildren.First();
            var otherChildJson = result[nameof(obj.OtherChildren)][0];

            Assert.Equal(otherChildObj.String, otherChildJson["String"].Value <string>());
            Assert.Equal(otherChildObj.Guid, otherChildJson["Guid"].Value <Guid>());
            Assert.Equal(otherChildObj.Int, otherChildJson["Int"].Value <int>());
            Assert.Equal(otherChildObj.Decimal, otherChildJson["Decimal"].Value <decimal>());
            Assert.Equal(otherChildObj.Double, otherChildJson["Double"].Value <double>());
            Assert.Equal(otherChildObj.DateTime, otherChildJson["DateTime"].Value <DateTime>());
            // Other properties should not need patching
            Assert.Single(result);
        }
예제 #2
0
        public void ReducePatch__Given_AllEqual__Then_Null(TestJsonObject obj)
        {
            // Assemble
            var original = JObject.FromObject(obj);
            var update   = JObject.FromObject(obj);
            var subject  = new JsonDiff();

            // Act
            var result = subject.ReducePatch(original, update);

            // Assert
            Assert.Null(result);
        }
예제 #3
0
        public void Equals__Given_IsEqual__Then_True(TestJsonObject obj)
        {
            // Assemble
            var token1 = JObject.FromObject(obj);
            var token2 = JObject.Parse(JsonConvert.SerializeObject(obj));

            var subject = new LooseJsonEqualityComparer();

            // Act
            var result = subject.Equals(token1, token2);

            // Assert
            Assert.True(result);
            Assert.False(JToken.DeepEquals(token1, token2));
        }
예제 #4
0
        public void Equals__Given_NotEqual_String__Then_False(TestJsonObject obj)
        {
            // Assemble
            var token1 = JObject.FromObject(obj);

            obj.String = Guid.NewGuid().ToString();
            var token2 = JObject.Parse(JsonConvert.SerializeObject(obj));

            var subject = new LooseJsonEqualityComparer();

            // Act
            var result = subject.Equals(token1, token2);

            // Assert
            Assert.False(result);
            Assert.False(JToken.DeepEquals(token1, token2));
        }
예제 #5
0
        public void Equals__Given_NotEqual_AddedChildren__Then_False(TestJsonObject obj)
        {
            // Assemble
            var token1 = JObject.FromObject(obj);

            obj.OtherChildren.Add(new TestJsonObjectChild());
            var token2 = JObject.Parse(JsonConvert.SerializeObject(obj));

            var subject = new LooseJsonEqualityComparer();

            // Act
            var result = subject.Equals(token1, token2);

            // Assert
            Assert.False(result);
            Assert.False(JToken.DeepEquals(token1, token2));
        }
예제 #6
0
        public void ReducePatch__Given_SinglePropertyNotEqual__Then_PatchProperty(TestJsonObject obj)
        {
            // Assemble
            var original = JObject.FromObject(obj);

            obj.String = "Updated Value";
            var update  = JObject.FromObject(obj);
            var subject = new JsonDiff();

            // Act
            var result = (JObject)subject.ReducePatch(original, update);

            // Assert
            Assert.NotNull(result);
            Assert.Equal(obj.String, result["String"].Value <string>());
            // Other properties should not need patching
            Assert.Single(result);
        }