public void ParseTypesJObject() { var schemaParser = new SchemaParser() .Add(typeof(DataAnonymous)) .Add("DataType1", 1, typeof(DataType1Version1)) .Add("DataType2", 1, typeof(DataType2Version1)) .Add("DataType2", 2, typeof(DataType2Version2)); var dataOfDifferentVersions = new List <object>() { new DataAnonymous { Zero = Guid.NewGuid().ToString() }, new DataType1Version1 { First = Guid.NewGuid().ToString() }, new DataType2Version1 { Second = Guid.NewGuid().ToString() }, new DataType2Version2 { Third = Guid.NewGuid().ToString() } }; foreach (var dataBefore in dataOfDifferentVersions) { var jObject = JObject.FromObject(dataBefore); var success = schemaParser.TryParse(jObject, out _, out _, out var dataAfter); UT.Assert.IsTrue(success); UT.Assert.AreEqual(dataBefore, dataAfter); } }
public void ParseAnonymous() { var schemaParser = new SchemaParser() .Add(typeof(DataAnonymous)); var dataBefore = new DataAnonymous { Zero = Guid.NewGuid().ToString() }; var json = JsonConvert.SerializeObject(dataBefore); var success = schemaParser.TryParse(json, out var dataAfter); UT.Assert.IsTrue(success); UT.Assert.AreEqual(dataBefore, dataAfter); }
public void UnknownVersion() { var schemaParser = new SchemaParser() .Add("DataType2", 1, typeof(DataType2Version1)); var dataBefore = new DataType2Version2 { Third = Guid.NewGuid().ToString() }; var json = JsonConvert.SerializeObject(dataBefore); var success = schemaParser.TryParse(json, out var schemaName, out var schemaVersion, out _); UT.Assert.IsFalse(success); UT.Assert.AreEqual("DataType2", schemaName); UT.Assert.AreEqual(2, schemaVersion); }