public void ListAddRangeTest() { var factoryPlain = new JsonInterfaceFactory(); var list1 = factoryPlain.CreateList <int?>(); list1.AddRange(new int?[] { 5, 6, 7, 8 }); Assert.AreEqual("[5,6,7,8]", list1.ToString().RemoveWhitespace()); var list2 = factoryPlain.CreateList <IPrimitives>(); list2.AddRange(new[] { factoryPlain.Create <IPrimitives>(v => v.Decimal = 21), factoryPlain.Create <IPrimitives>(v => v.Decimal = 33) }); Assert.AreEqual("[{\"Decimal\":21.0},{\"Decimal\":33.0}]", list2.ToString().RemoveWhitespace()); var list3 = factoryPlain.CreateList <IJsonList <IPrimitives> >(); list3.AddRange(new[] { factoryPlain.CreateList <IPrimitives>(v => v.AddRange(list2)), factoryPlain.CreateList <IPrimitives>(v => v.AddRange(list2)) }); Assert.AreEqual("[[{\"Decimal\":21.0},{\"Decimal\":33.0}],[{\"Decimal\":21.0},{\"Decimal\":33.0}]]", list3.ToString().RemoveWhitespace()); }
public void EqualIfSameJObjectButDifferentProxy() { var j = new JObject(); var factory = new JsonInterfaceFactory(); var left = factory.Create <IEqualityTest>(j); var right = factory.Create <IEqualityTest>(j); Assert.IsTrue(left.Equals(right)); Assert.IsTrue(right.Equals(left)); }
public void EqualIfJObjectComparedToProxy() { var factory = new JsonInterfaceFactory(); var jsonString = "{ \"prop\": 445 }"; var leftJObject = JObject.Parse(jsonString); var rightJObject = JObject.Parse(jsonString); var left = factory.Create <IEqualityTest>(leftJObject); var right = factory.Create <IEqualityTest>(rightJObject); // proxies refer to different JObjects, so they are not equal Assert.IsFalse(right.Equals(left)); Assert.IsFalse(left.Equals(right)); // proxies came from same initial json, so DeepEquals should be true Assert.IsTrue(JToken.DeepEquals(left.JsonObject, right.JsonObject)); }