public void UnitInIComparable_ExpectUnitCorrectlyDeserialized() { TestObjWithIComparable testObjWithIComparable = new TestObjWithIComparable() { Value = Power.FromWatts(10) }; JsonSerializerSettings jsonSerializerSettings = CreateJsonSerializerSettings(); string json = JsonConvert.SerializeObject(testObjWithIComparable, jsonSerializerSettings); var deserializedTestObject = JsonConvert.DeserializeObject <TestObjWithIComparable>(json, jsonSerializerSettings); Assert.Equal(typeof(Power), deserializedTestObject.Value.GetType()); Assert.Equal(Power.FromWatts(10), (Power)deserializedTestObject.Value); }
public void DoubleInIComparable_ExpectUnitCorrectlyDeserialized() { TestObjWithIComparable testObjWithIComparable = new TestObjWithIComparable() { Value = 10.0 }; JsonSerializerSettings jsonSerializerSettings = CreateJsonSerializerSettings(); string json = JsonConvert.SerializeObject(testObjWithIComparable, jsonSerializerSettings); var deserializedTestObject = JsonConvert.DeserializeObject <TestObjWithIComparable>(json, jsonSerializerSettings); Assert.Equal(typeof(double), deserializedTestObject.Value.GetType()); Assert.Equal(10d, (double)deserializedTestObject.Value); }
public void ClassInIComparable_ExpectUnitCorrectlyDeserialized() { TestObjWithIComparable testObjWithIComparable = new TestObjWithIComparable() { Value = new ComparableClass() { Value = 10 } }; JsonSerializerSettings jsonSerializerSettings = CreateJsonSerializerSettings(); string json = JsonConvert.SerializeObject(testObjWithIComparable, jsonSerializerSettings); var deserializedTestObject = JsonConvert.DeserializeObject <TestObjWithIComparable>(json, jsonSerializerSettings); Assert.That(deserializedTestObject.Value.GetType(), Is.EqualTo(typeof(ComparableClass))); Assert.That(((ComparableClass)(deserializedTestObject.Value)).Value, Is.EqualTo(10.0)); }