public void TestDataContractJsonSerializerSettings() { TestTypeForSerializerSettings instance = new TestTypeForSerializerSettings { BaseRef = new DerivedType(), Date = AnyInstance.AnyDateTime, Dict = new Dictionary <string, object> { { "one", 1 }, { "two", 2 }, { "two point five", 2.5 }, } }; JsonObject dict = new JsonObject { { "one", 1 }, { "two", 2 }, { "two point five", 2.5 }, }; JsonObject equivalentJsonObject = new JsonObject { { "BaseRef", new JsonObject { { "__type", "DerivedType:NS" } } }, { "Date", AnyInstance.AnyDateTime }, { "Dict", dict }, }; JsonObject createdFromType = JsonValueExtensions.CreateFrom(instance) as JsonObject; Assert.Equal(equivalentJsonObject.ToString(), createdFromType.ToString()); TestTypeForSerializerSettings newInstance = equivalentJsonObject.ReadAsType <TestTypeForSerializerSettings>(); // DISABLED, 198487 - Assert.Equal(instance.Date, newInstance.Date); Assert.Equal(instance.BaseRef.GetType().FullName, newInstance.BaseRef.GetType().FullName); Assert.Equal(3, newInstance.Dict.Count); Assert.Equal(1, newInstance.Dict["one"]); Assert.Equal(2, newInstance.Dict["two"]); Assert.Equal(2.5, Convert.ToDouble(newInstance.Dict["two point five"], CultureInfo.InvariantCulture)); }
public void ReadAsComplexTypeTest() { JsonObject target = new JsonObject { { "Name", AnyInstance.AnyString }, { "Age", AnyInstance.AnyInt }, { "Address", new JsonObject { { "Street", Address.AnyStreet }, { "City", Address.AnyCity }, { "State", Address.AnyState } } }, }; Person person = target.ReadAsType <Person>(); Assert.Equal(AnyInstance.AnyString, person.Name); Assert.Equal(AnyInstance.AnyInt, person.Age); Assert.NotNull(person.Address); Assert.Equal(Address.AnyStreet, person.Address.Street); Assert.Equal(Address.AnyCity, person.Address.City); Assert.Equal(Address.AnyState, person.Address.State); }
public void ReadAsComplexTypeTest() { JsonObject target = new JsonObject { { "Name", AnyInstance.AnyString }, { "Age", AnyInstance.AnyInt }, { "Address", new JsonObject { { "Street", Address.AnyStreet }, { "City", Address.AnyCity }, { "State", Address.AnyState } } }, }; Person person = target.ReadAsType<Person>(); Assert.AreEqual(AnyInstance.AnyString, person.Name); Assert.AreEqual(AnyInstance.AnyInt, person.Age); Assert.IsNotNull(person.Address); Assert.AreEqual(Address.AnyStreet, person.Address.Street); Assert.AreEqual(Address.AnyCity, person.Address.City); Assert.AreEqual(Address.AnyState, person.Address.State); }