Ejemplo n.º 1
0
        public void TestValueDiffEquality()
        {
            var diff = new ValueDiff(
                new DiffPoint("$",
                              new JsonString("Hello"),
                              new JsonString("Goodbye")));

            var sameDiff = new ValueDiff(
                new DiffPoint("$",
                              new JsonString("Hello"),
                              new JsonString("Goodbye")));

            var anotherDiff = new ValueDiff(
                new DiffPoint("$.value",
                              new JsonString("Hello"),
                              new JsonString("Goodbye")));

            var yetAnotherDiff = new ValueDiff(
                new DiffPoint("$",
                              new JsonString("Hey"),
                              new JsonString("Goodbye")));

            Assert.Equal(diff, sameDiff);
            Assert.NotEqual(diff, anotherDiff);
            Assert.NotEqual(diff, yetAnotherDiff);
            Assert.NotEqual(anotherDiff, yetAnotherDiff);
        }
Ejemplo n.º 2
0
        public void TestValueDiff()
        {
            var str1 = @"{
    ""title"": ""Thinking Forth"",
    ""author"": ""Leo Brodie""
}";
            var str2 = @"{
    ""title"": ""Thinking Forth"",
    ""author"": ""Chuck Moore""
}";

            var diff1 = JsonStrings.Diff(str1, str2).Single();

            Assert.True(diff1.IsValueDiff);
            Assert.False(diff1.IsTypeDiff);
            Assert.False(diff1.IsArrayDiff);
            Assert.False(diff1.IsObjectDiff);

            var diff2 = new ValueDiff(
                new DiffPoint("$.author",
                              new JsonString("Leo Brodie"),
                              new JsonString("Chuck Moore")));

            Assert.True(diff2.IsValueDiff);
            Assert.False(diff2.IsTypeDiff);
            Assert.False(diff2.IsArrayDiff);
            Assert.False(diff2.IsObjectDiff);

            Assert.Equal(diff1, diff2);

            Assert.Equal("ValueDiff { Path = $.author, Left = Leo Brodie, Right = Chuck Moore }", diff1.ToString());
        }
Ejemplo n.º 3
0
 private static string ToTextDiff(Diff diff)
 {
     return(diff switch
     {
         TypeDiff typeDiff => ToTypeTextDiff(typeDiff),
         ValueDiff valueDiff => ToValueTypeTextDiff(valueDiff),
         ArrayDiff arrayDiff => ToArrayTextDiff(arrayDiff),
         ObjectDiff objectDiff => ToObjectTextDiff(objectDiff),
         _ => throw new Exception("Unknown diff type")
     });
Ejemplo n.º 4
0
        private static bool TryGetValueDiff(object x, object y, MemberSettings settings, out ValueDiff diff)
        {
            bool result;
            if (EqualBy.TryGetValueEquals(x, y, settings, out result))
            {
                diff = result
                           ? null
                           : new ValueDiff(x, y);

                return true;
            }

            diff = null;
            return false;
        }
Ejemplo n.º 5
0
        private static bool TryGetValueDiff(object x, object y, MemberSettings settings, out ValueDiff diff)
        {
            if (EqualBy.TryGetValueEquals(x, y, settings, out var result))
            {
                diff = result
                           ? null
                           : new ValueDiff(x, y);

                return(true);
            }

            diff = null;
            return(false);
        }
Ejemplo n.º 6
0
 /// <summary>Initializes a new instance of the <see cref="SubDiff"/> class.</summary>
 /// <param name="valueDiff">The diff.</param>
 protected SubDiff(ValueDiff valueDiff)
     : base(valueDiff.Diffs)
 {
     this.ValueDiff = valueDiff;
 }