public void ComparesEachItemInArrayProperty()
        {
            var obj1 = new TestObject5 {
                PropX = new[] { new TestObject2 {
                                    Prop1 = 123
                                }, new TestObject2 {
                                    Prop1 = 456
                                }, }
            };
            var obj2 = new TestObject5 {
                PropX = new[] { new TestObject2 {
                                    Prop1 = 789
                                }, new TestObject2 {
                                    Prop1 = 456
                                }, }
            };
            var sut = new ObjectComparer();

            var result = sut.Compare(obj1, obj2).ToList();

            Assert.AreEqual(3, result.Count);
            CheckComparison(result[0], ComparisonResult.Equal, ".PropX.Length", 2, 2);
            CheckComparison(result[1], ComparisonResult.NotEqual, ".PropX[0].Prop1", 123, 789);
            CheckComparison(result[2], ComparisonResult.Equal, ".PropX[1].Prop1", 456, 456);
        }
Example #2
0
    void Test5()
    {
        string      jsonString     = "{\"nesteds\":[{\"name\":\"vic\",\"id\":32},{\"name\":\"yuan\",\"id\":97}]}";
        TestObject5 expectedResult = new TestObject5(new NestedObject[] { new NestedObject("vic", 32), new NestedObject("yuan", 97) });

        TestObject5 obj = JsonParser.FromJson <TestObject5>(jsonString);

        if (expectedResult.Equals(obj))
        {
            Debug.Log("Reader Test 5 : Success");
        }
        else
        {
            Debug.LogWarning("Reader Test 5 : Failure");
        }

        string json = JsonParser.ToJson <TestObject5>(obj);

        if (jsonString == json)
        {
            Debug.Log("Writer Test 5 : Success");
        }
        else
        {
            Debug.LogWarning(String.Format("Writer Test 5 : Failure : {0}", json));
        }
    }
Example #3
0
        public void StructCreateInstanceTest()
        {
            TestStruct1 s = (TestStruct1)TypeAccessor.CreateInstance(typeof(TestStruct1));

            Assert.IsNotNull(s);

            TestObject5 o = (TestObject5)TypeAccessor.CreateInstance(typeof(TestObject5));

            Assert.IsNotNull(o);
        }
Example #4
0
        public void IfOneObjectIsNullTheOtherIsStillExploredRecursively()
        {
            var obj1 = new TestObject5 { PropX = new[] { new TestObject2 { Prop1 = 123 }, new TestObject2 { Prop1 = 456 }, } };
              var sut = new ObjectComparer();

              var result = sut.Compare(obj1, null).ToList();

              Assert.AreEqual(3, result.Count);
              CheckComparison(result[0], ComparisonResult.NotEqual, ".PropX.Length", 2, 0);
              CheckComparison(result[1], ComparisonResult.NotEqual, ".PropX[0].Prop1", 123, null);
              CheckComparison(result[2], ComparisonResult.NotEqual, ".PropX[1].Prop1", 456, null);
        }
Example #5
0
        public void IndicesPastArrayEndAreTreatedAsNull()
        {
            var obj1 = new TestObject5 { PropX = new[] { new TestObject2 { Prop1 = 123 }, } };
              var obj2 = new TestObject5 { PropX = new[] { new TestObject2 { Prop1 = 789 }, new TestObject2 { Prop1 = 456 }, } };
              var sut = new ObjectComparer();

              var result = sut.Compare(obj1, obj2).ToList();

              Assert.AreEqual(3, result.Count);
              CheckComparison(result[0], ComparisonResult.NotEqual, ".PropX.Length", 1, 2);
              CheckComparison(result[1], ComparisonResult.NotEqual, ".PropX[0].Prop1", 123, 789);
              CheckComparison(result[2], ComparisonResult.NotEqual, ".PropX[1].Prop1", null, 456);
        }
Example #6
0
        public void ComparesEachItemInArrayProperty()
        {
            var obj1 = new TestObject5 { PropX = new[] { new TestObject2 { Prop1 = 123 }, new TestObject2 { Prop1 = 456 }, } };
              var obj2 = new TestObject5 { PropX = new[] { new TestObject2 { Prop1 = 789 }, new TestObject2 { Prop1 = 456 }, } };
              var sut = new ObjectComparer();

              var result = sut.Compare(obj1, obj2).ToList();

              Assert.AreEqual(3, result.Count);
              CheckComparison(result[0], ComparisonResult.Equal, ".PropX.Length", 2, 2);
              CheckComparison(result[1], ComparisonResult.NotEqual, ".PropX[0].Prop1", 123, 789);
              CheckComparison(result[2], ComparisonResult.Equal, ".PropX[1].Prop1", 456, 456);
        }
        public void LazyInstancesTypeTest()
        {
            TestObject5 o = (TestObject5)TypeAccessor.CreateInstance(typeof(TestObject5));

            Assert.IsNotNull(o.Str);
            Assert.IsNotNull(o.List);

            o.Str  = null;
            o.List = null;

            Assert.IsNotNull(o.Str);
            Assert.AreEqual(null, o.List);
        }
Example #8
0
 public bool Equals(TestObject5 other)
 {
     if (this.nesteds.Length != other.nesteds.Length)
     {
         Debug.LogWarning("TestObject5 : Lengths of nesteds does not match. Type NestedObject[]");
         return(false);
     }
     for (int i = 0; i < this.nesteds.Length; i++)
     {
         if (!this.nesteds[i].Equals(other.nesteds[i]))
         {
             Debug.LogWarning(String.Format("TestObject5 : Field nesteds[{0}] does not match. Type NestedObject[]", i));
             return(false);
         }
     }
     return(true);
 }
        public void IfOneObjectIsNullTheOtherIsStillExploredRecursively()
        {
            var obj1 = new TestObject5 {
                PropX = new[] { new TestObject2 {
                                    Prop1 = 123
                                }, new TestObject2 {
                                    Prop1 = 456
                                }, }
            };
            var sut = new ObjectComparer();

            var result = sut.Compare(obj1, null).ToList();

            Assert.AreEqual(3, result.Count);
            CheckComparison(result[0], ComparisonResult.NotEqual, ".PropX.Length", 2, 0);
            CheckComparison(result[1], ComparisonResult.NotEqual, ".PropX[0].Prop1", 123, null);
            CheckComparison(result[2], ComparisonResult.NotEqual, ".PropX[1].Prop1", 456, null);
        }
        public void IndicesPastArrayEndAreTreatedAsNull()
        {
            var obj1 = new TestObject5 {
                PropX = new[] { new TestObject2 {
                                    Prop1 = 123
                                }, }
            };
            var obj2 = new TestObject5 {
                PropX = new[] { new TestObject2 {
                                    Prop1 = 789
                                }, new TestObject2 {
                                    Prop1 = 456
                                }, }
            };
            var sut = new ObjectComparer();

            var result = sut.Compare(obj1, obj2).ToList();

            Assert.AreEqual(3, result.Count);
            CheckComparison(result[0], ComparisonResult.NotEqual, ".PropX.Length", 1, 2);
            CheckComparison(result[1], ComparisonResult.NotEqual, ".PropX[0].Prop1", 123, 789);
            CheckComparison(result[2], ComparisonResult.NotEqual, ".PropX[1].Prop1", null, 456);
        }
Example #11
0
 public NestedObject2(NestedObject[] nested_arr, TestObject5 nested_test)
 {
     this.nested_arr  = nested_arr;
     this.nested_test = nested_test;
 }