Mercurial > pub > ImplabNet
diff Implab.Test/JsonTests.cs @ 264:3a6e18c432be v3
Added XmlToJson xsl transformation.
Added JsonXmlReader.CreateJsonXmlReader(...) methods
Added SerializationHelpers.SerializeJson/DeserializeJson methods
author | cin |
---|---|
date | Mon, 16 Apr 2018 18:43:49 +0300 |
parents | f1696cdc3d7a |
children | 74e048cbaac8 |
line wrap: on
line diff
--- a/Implab.Test/JsonTests.cs Mon Apr 16 02:12:57 2018 +0300 +++ b/Implab.Test/JsonTests.cs Mon Apr 16 18:43:49 2018 +0300 @@ -6,6 +6,7 @@ using Implab.Formats; using Implab.Formats.Json; using System.IO; +using Implab.Test.Model; namespace Implab.Test { public class JsonTests { @@ -114,6 +115,44 @@ DumpJsonFlatParse("[1,2,\"\",[3,4],{\"info\": [5,6]},{\"num\": [7,8,null]}, null,[null]]"); } + [Fact] + public void XmlToJsonTransform() { + var person = new Person { + FirstName = "Charlie", + LastName = "Brown", + Age = 19, + AgeSpecified = true + }; + + var doc = SerializationHelpers.SerializeAsXmlDocument(person); + + using (var writer = new StringWriter()) { + XmlToJson.Default.Transform(doc,null, writer); + Console.WriteLine(writer.ToString()); + } + } + + [Fact] + public void JsonSerialization() { + var person = new Person { + FirstName = "Charlie", + LastName = "Brown", + Age = 19, + AgeSpecified = true, + Tags = new [] { "brave", "stupid" } + }; + + var data = SerializationHelpers.SerializeJsonAsString(person); + Console.WriteLine(data); + var clone = SerializationHelpers.DeserializeJsonFromString<Person>(data); + + Assert.Equal(person.FirstName, clone.FirstName); + Assert.Equal(person.LastName, clone.LastName); + Assert.Equal(person.Age, clone.Age); + Assert.Equal(person.AgeSpecified, clone.AgeSpecified); + Assert.Equal(person.Tags, person.Tags); + } + void AssertRead(XmlReader reader, XmlNodeType expected) { Assert.True(reader.Read()); Console.WriteLine($"{new string(' ', reader.Depth * 2)}{reader}");