public void DeserializationOfNullIsBackwardCompatible(string version, string json) { ClassWithUnitValue reconstructed = null; Assert.That( () => reconstructed = JsonConvert.DeserializeObject <ClassWithUnitValue>(json), Throws.Nothing, $"Failing version: {version}"); Assert.That(reconstructed.Name, Is.EqualTo("Test")); Assert.That(reconstructed.Value, Is.Null); }
public void DeserializationIsBackwardCompatible(string version, string json) { // Generate //var json = JsonConvert.SerializeObject(new ClassWithUnitValue("Test", 11.3.To(SIPrefix.Milli, Units.Meter))); //File.WriteAllText($@"C:\Temp\{nameof(ClassWithUnitValue)}.json", json); ClassWithUnitValue reconstructed = null; Assert.That( () => reconstructed = JsonConvert.DeserializeObject <ClassWithUnitValue>(json), Throws.Nothing, $"Failing version: {version}"); Assert.That(reconstructed.Name, Is.EqualTo("Test")); Assert.That(reconstructed.Value.In(SIPrefix.Milli, Unit.Meter), Is.EqualTo(11.3).Within(1e-6)); }