public void NonGenericTypeStreamTest() { object testModel = TestModelFactory.Create(); var stream0 = testModel.ToStream(); var result0 = (TestModel)stream0.FromStream() !; var stream1 = new MemoryStream(); testModel.PackTo(stream1); var result1 = (TestModel)stream1.FromStream() !; var stream2 = new MemoryStream(); stream2.PackBy(testModel); var result2 = (TestModel)stream2.FromStream() !; Assert.Equal( Tuple.Create(((TestModel)testModel).Id, ((TestModel)testModel).Age, ((TestModel)testModel).CreateTime, ((TestModel)testModel).Name, ((TestModel)testModel).Gender), Tuple.Create(result0.Id, result0.Age, result0.CreateTime, result0.Name, result0.Gender)); Assert.Equal( Tuple.Create(((TestModel)testModel).Id, ((TestModel)testModel).Age, ((TestModel)testModel).CreateTime, ((TestModel)testModel).Name, ((TestModel)testModel).Gender), Tuple.Create(result1.Id, result1.Age, result1.CreateTime, result1.Name, result1.Gender)); Assert.Equal( Tuple.Create(((TestModel)testModel).Id, ((TestModel)testModel).Age, ((TestModel)testModel).CreateTime, ((TestModel)testModel).Name, ((TestModel)testModel).Gender), Tuple.Create(result2.Id, result2.Age, result2.CreateTime, result2.Name, result2.Gender)); }
public void GenericTypeStreamTest() { var testModel = TestModelFactory.Create(); var stream0 = testModel.ToStream(); var result0 = stream0.FromStream <TestModel>() !; var stream1 = new MemoryStream(); testModel.PackTo(stream1); var result1 = stream1.FromStream <TestModel>() !; var stream2 = new MemoryStream(); stream2.PackBy(testModel); var result2 = stream2.FromStream <TestModel>() !; Assert.Equal( Tuple.Create(testModel.Id, testModel.Age, testModel.CreateTime, testModel.Name, testModel.Gender), Tuple.Create(result0.Id, result0.Age, result0.CreateTime, result0.Name, result0.Gender)); Assert.Equal( Tuple.Create(testModel.Id, testModel.Age, testModel.CreateTime, testModel.Name, testModel.Gender), Tuple.Create(result1.Id, result1.Age, result1.CreateTime, result1.Name, result1.Gender)); Assert.Equal( Tuple.Create(testModel.Id, testModel.Age, testModel.CreateTime, testModel.Name, testModel.Gender), Tuple.Create(result2.Id, result2.Age, result2.CreateTime, result2.Name, result2.Gender)); }
public async Task NonGenericTypeStreamAsyncTest() { object testModel = TestModelFactory.Create(); var stream0 = testModel.ToStream(typeof(TestModel)); var result0 = (TestModel)(await stream0.FromStreamAsync(typeof(TestModel))) !; var stream1 = new MemoryStream(); await testModel.PackToAsync(typeof(TestModel), stream1); var result1 = (TestModel)(await stream1.FromStreamAsync(typeof(TestModel))) !; var stream2 = new MemoryStream(); await stream2.PackByAsync(typeof(TestModel), testModel); var result2 = (TestModel)(await stream2.FromStreamAsync(typeof(TestModel))) !; Assert.Equal( Tuple.Create(((TestModel)testModel).Id, ((TestModel)testModel).Age, ((TestModel)testModel).CreateTime, ((TestModel)testModel).Name, ((TestModel)testModel).Gender), Tuple.Create(result0.Id, result0.Age, result0.CreateTime, result0.Name, result0.Gender)); Assert.Equal( Tuple.Create(((TestModel)testModel).Id, ((TestModel)testModel).Age, ((TestModel)testModel).CreateTime, ((TestModel)testModel).Name, ((TestModel)testModel).Gender), Tuple.Create(result1.Id, result1.Age, result1.CreateTime, result1.Name, result1.Gender)); Assert.Equal( Tuple.Create(((TestModel)testModel).Id, ((TestModel)testModel).Age, ((TestModel)testModel).CreateTime, ((TestModel)testModel).Name, ((TestModel)testModel).Gender), Tuple.Create(result2.Id, result2.Age, result2.CreateTime, result2.Name, result2.Gender)); }
public async Task GenericTypeStreamAsyncTest() { var testModel = TestModelFactory.Create(); var stream0 = testModel.ToStream(); var result0 = (await stream0.FromStreamAsync <TestModel>()) !; var stream1 = new MemoryStream(); await testModel.PackToAsync(stream1); var result1 = (await stream1.FromStreamAsync <TestModel>()) !; var stream2 = new MemoryStream(); await stream2.PackByAsync(testModel); var result2 = (await stream2.FromStreamAsync <TestModel>()) !; Assert.Equal( Tuple.Create(testModel.Id, testModel.Age, testModel.CreateTime, testModel.Name, testModel.Gender), Tuple.Create(result0.Id, result0.Age, result0.CreateTime, result0.Name, result0.Gender)); Assert.Equal( Tuple.Create(testModel.Id, testModel.Age, testModel.CreateTime, testModel.Name, testModel.Gender), Tuple.Create(result1.Id, result1.Age, result1.CreateTime, result1.Name, result1.Gender)); Assert.Equal( Tuple.Create(testModel.Id, testModel.Age, testModel.CreateTime, testModel.Name, testModel.Gender), Tuple.Create(result2.Id, result2.Age, result2.CreateTime, result2.Name, result2.Gender)); }
public void ZeroFormatterBytesGenericTest() { var model = TestModelFactory.Create(); #if NET48 model.CreateTime = model.CreateTime.ToUniversalTime(); #endif BytesGenericTest(new ZeroFormatter.Serializer(), model); }
public void ReadOnlySpanBytesTest() { var testModel = TestModelFactory.Create(); var bytes = testModel.ToBytes(); var result = ((ReadOnlySpan <byte>)bytes).FromBytes <TestModel>() !; Assert.Equal( Tuple.Create(testModel.Id, testModel.Age, testModel.CreateTime, testModel.Name, testModel.Gender), Tuple.Create(result.Id, result.Age, result.CreateTime, result.Name, result.Gender)); }
public void TextWriterReaderNonGenericNullTest() { object? testModel = TestModelFactory.Create(); StreamWriter?writer = null; StreamReader?reader = null; testModel.Serialize(writer); writer.WriteJson(testModel); reader.ReadJson(typeof(TestModel)); }
public void GenericTypeXmlTest() { var testModel = TestModelFactory.Create(); var json = testModel.ToXml(); var result = json.FromXml <TestModel>() !; Assert.Equal( Tuple.Create(testModel.Id, testModel.Age, testModel.CreateTime, testModel.Name, testModel.Gender), Tuple.Create(result.Id, result.Age, result.CreateTime, result.Name, result.Gender)); }
public void TextWriterReaderNullTest() { var testModel = TestModelFactory.Create(); StreamWriter?writer = null; StreamReader?reader = null; testModel.Serialize(writer); writer.WriteJson(testModel); reader.ReadJson <TestModel>(); }
public void GenericTypeBytesTest() { var testModel = TestModelFactory.Create(); var bytes = testModel.ToBytes(); var result = bytes.FromBytes <TestModel>() !; Assert.Equal( Tuple.Create(testModel.Id, testModel.Age, testModel.CreateTime, testModel.Name, testModel.Gender), Tuple.Create(result.Id, result.Age, result.CreateTime, result.Name, result.Gender)); }
public void GenericTypeJsonTest() { var testModel = TestModelFactory.Create(); var json = testModel.ToJson(); var result = json.FromJson <TestModel>() !; Assert.Equal( Tuple.Create(testModel.Id, testModel.Age, testModel.CreateTime.ToUniversalTime(), testModel.Name, testModel.Gender), Tuple.Create(result.Id, result.Age, result.CreateTime, result.Name, result.Gender)); }
private static void JsonGenericTest(IJsonSerializer serializer) { var model = TestModelFactory.Create(); var json = serializer.ToJson(model); var deserializeModel = serializer.FromJson <TestModel>(json) !; Assert.Equal( Tuple.Create(model.Id, model.Age, model.CreateTime, model.Name, model.Gender), Tuple.Create(deserializeModel.Id, deserializeModel.Age, deserializeModel.CreateTime, deserializeModel.Name, deserializeModel.Gender)); }
private static void TextGenericTest(ITextSerializer serializer) { var model = TestModelFactory.Create(); var text = serializer.ToText(model); var deserializeModel = serializer.FromText <TestModel>(text) !; Assert.Equal( Tuple.Create(model.Id, model.Age, model.CreateTime, model.Name, model.Gender), Tuple.Create(deserializeModel.Id, deserializeModel.Age, deserializeModel.CreateTime, deserializeModel.Name, deserializeModel.Gender)); }
public void NonGenericTypeBytesTest() { object testModel = TestModelFactory.Create(); var bytes = testModel.ToBytes(); var result = (TestModel)bytes.FromBytes(typeof(TestModel)) !; Assert.Equal( Tuple.Create(((TestModel)testModel).Id, ((TestModel)testModel).Age, ((TestModel)testModel).CreateTime, ((TestModel)testModel).Name, ((TestModel)testModel).Gender), Tuple.Create(result.Id, result.Age, result.CreateTime, result.Name, result.Gender)); }
public void ObjectYamlTest() { object testModel = TestModelFactory.Create(); var yaml = testModel.ToYaml(); var result = (TestModel)yaml.FromYaml(typeof(TestModel)) !; Assert.Equal( Tuple.Create(((TestModel)testModel).Id, ((TestModel)testModel).Age, ((TestModel)testModel).CreateTime, ((TestModel)testModel).Name, ((TestModel)testModel).Gender), Tuple.Create(result.Id, result.Age, result.CreateTime, result.Name, result.Gender)); }
private static void XmlGenericTest(IXmlSerializer serializer) { var model = TestModelFactory.Create(); var xml = serializer.ToXml(model); var deserializeModel = serializer.FromXml <TestModel>(xml) !; Assert.Equal( Tuple.Create(model.Id, model.Age, model.CreateTime, model.Name, model.Gender), Tuple.Create(deserializeModel.Id, deserializeModel.Age, deserializeModel.CreateTime, deserializeModel.Name, deserializeModel.Gender)); }
public void NonGenericTypeXmlTest() { object testModel = TestModelFactory.Create(); var json = testModel.ToXml(typeof(TestModel)); var result = (TestModel)json.FromXml(typeof(TestModel)) !; Assert.Equal( Tuple.Create(((TestModel)testModel).Id, ((TestModel)testModel).Age, ((TestModel)testModel).CreateTime, ((TestModel)testModel).Name, ((TestModel)testModel).Gender), Tuple.Create(result.Id, result.Age, result.CreateTime, result.Name, result.Gender)); }
private static void YamlNonGenericTest(IYamlSerializer serializer) { var model = TestModelFactory.Create(); var type = typeof(TestModel); var yaml = serializer.ToYaml(type, model); var deserializeModel = (TestModel)serializer.FromYaml(type, yaml) !; Assert.Equal( Tuple.Create(model.Id, model.Age, model.CreateTime, model.Name, model.Gender), Tuple.Create(deserializeModel.Id, deserializeModel.Age, deserializeModel.CreateTime, deserializeModel.Name, deserializeModel.Gender)); }
public void TextWriterReaderTest() { var testModel = TestModelFactory.Create(); TestModel result0; using (var fs = new FileStream("TextWriterReaderTest0.json", FileMode.Create)) { var writer = new StreamWriter(fs, Encoding.UTF8); writer.WriteJson(testModel); writer.Close(); } using (var fs = new FileStream("TextWriterReaderTest0.json", FileMode.Open)) { var reader = new StreamReader(fs, Encoding.UTF8); result0 = reader.ReadJson <TestModel>() !; reader.Close(); } TestModel result1; using (var fs = new FileStream("TextWriterReaderTest1.json", FileMode.Create)) { var writer = new StreamWriter(fs, Encoding.UTF8); testModel.Serialize(writer); writer.Close(); } using (var fs = new FileStream("TextWriterReaderTest1.json", FileMode.Open)) { var reader = new StreamReader(fs, Encoding.UTF8); result1 = reader.ReadJson <TestModel>() !; reader.Close(); } Assert.Equal( Tuple.Create(testModel.Id, testModel.Age, testModel.CreateTime.ToUniversalTime(), testModel.Name, testModel.Gender), Tuple.Create(result0.Id, result0.Age, result0.CreateTime, result0.Name, result0.Gender)); Assert.Equal( Tuple.Create(testModel.Id, testModel.Age, testModel.CreateTime.ToUniversalTime(), testModel.Name, testModel.Gender), Tuple.Create(result1.Id, result1.Age, result1.CreateTime, result1.Name, result1.Gender)); using (var fs = new FileStream("TextWriterReaderTest.json", FileMode.Create)) { var writer = new StreamWriter(fs, Encoding.UTF8); JilHelper.Serialize <TestModel>(null, writer); JilHelper.Serialize(null, writer); writer.Close(); } }
public void TextWriterReaderTest() { var testModel = TestModelFactory.Create(); TestModel result0; using (var fs = new FileStream("TextWriterReaderTest0.xml", FileMode.Create)) { var writer = new StreamWriter(fs, Encoding.UTF8); writer.WriteXml(testModel); writer.Close(); } using (var fs = new FileStream("TextWriterReaderTest0.xml", FileMode.Open)) { var reader = new StreamReader(fs, Encoding.UTF8); result0 = reader.ReadXml<TestModel>()!; reader.Close(); } TestModel result1; using (var fs = new FileStream("TextWriterReaderTest1.xml", FileMode.Create)) { var writer = new StreamWriter(fs, Encoding.UTF8); testModel.Serialize(writer); writer.Close(); } using (var fs = new FileStream("TextWriterReaderTest1.xml", FileMode.Open)) { var reader = new StreamReader(fs, Encoding.UTF8); result1 = reader.ReadXml<TestModel>()!; reader.Close(); } Assert.Equal( Tuple.Create(testModel.Id, testModel.Age, testModel.CreateTime, testModel.Name, testModel.Gender), Tuple.Create(result0.Id, result0.Age, result0.CreateTime, result0.Name, result0.Gender)); Assert.Equal( Tuple.Create(testModel.Id, testModel.Age, testModel.CreateTime, testModel.Name, testModel.Gender), Tuple.Create(result1.Id, result1.Age, result1.CreateTime, result1.Name, result1.Gender)); XmlHelper.Serialize((XmlWriter?)null, testModel); XmlHelper.Serialize((TextWriter?)null, testModel); XmlHelper.Serialize(typeof(TestModel), (XmlWriter?)null, testModel); XmlHelper.Serialize(typeof(TestModel), (TextWriter?)null, testModel); }
public void TextWriterReaderNonGenericTest() { object testModel = TestModelFactory.Create(); TestModel result0; using (var fs = new FileStream("TextWriterReaderNonGenericTest0.json", FileMode.Create)) { var writer = new StreamWriter(fs, Encoding.UTF8); writer.WriteJson(testModel); writer.Close(); } using (var fs = new FileStream("TextWriterReaderNonGenericTest0.json", FileMode.Open)) { var reader = new StreamReader(fs, Encoding.UTF8); result0 = (TestModel)reader.ReadJson(typeof(TestModel)) !; reader.Close(); } TestModel result1; using (var fs = new FileStream("TextWriterReaderNonGenericTest1.json", FileMode.Create)) { var writer = new StreamWriter(fs, Encoding.UTF8); testModel.Serialize(writer); writer.Close(); } using (var fs = new FileStream("TextWriterReaderNonGenericTest1.json", FileMode.Open)) { var reader = new StreamReader(fs, Encoding.UTF8); result1 = (TestModel)reader.ReadJson(typeof(TestModel)) !; reader.Close(); } Assert.Equal( Tuple.Create(((TestModel)testModel).Id, ((TestModel)testModel).Age, ((TestModel)testModel).CreateTime.ToUniversalTime(), ((TestModel)testModel).Name, ((TestModel)testModel).Gender), Tuple.Create(result0.Id, result0.Age, result0.CreateTime, result0.Name, result0.Gender)); Assert.Equal( Tuple.Create(((TestModel)testModel).Id, ((TestModel)testModel).Age, ((TestModel)testModel).CreateTime.ToUniversalTime(), ((TestModel)testModel).Name, ((TestModel)testModel).Gender), Tuple.Create(result1.Id, result1.Age, result1.CreateTime, result1.Name, result1.Gender)); }
public void GenericTypeBytesTest() { var testModel = TestModelFactory.Create(); testModel.CreateTime = testModel.CreateTime; var bytes = testModel.ToBytes(); var result = bytes.FromBytes <TestModel>() !; #if NET48 Assert.Equal( Tuple.Create(testModel.Id, testModel.Age, testModel.CreateTime, testModel.Name, testModel.Gender), Tuple.Create(result.Id, result.Age, result.CreateTime.ToLocalTime(), result.Name, result.Gender)); #else Assert.Equal( Tuple.Create(testModel.Id, testModel.Age, testModel.CreateTime, testModel.Name, testModel.Gender), Tuple.Create(result.Id, result.Age, result.CreateTime, result.Name, result.Gender)); #endif }
public void XmlDictionaryWriterReaderTest() { var testModel = TestModelFactory.Create(); TestModel result0; using (var fs = new FileStream("XmlWriterReaderTest0.xml", FileMode.Create)) { var writer = XmlDictionaryWriter.CreateDictionaryWriter(new XmlTextWriter(fs, Encoding.UTF8)); writer.WriteXml(testModel); writer.Close(); } using (var fs = new FileStream("XmlWriterReaderTest0.xml", FileMode.Open)) { var reader = XmlDictionaryReader.CreateDictionaryReader(new XmlTextReader(fs)); result0 = reader.ReadXml <TestModel>() !; reader.Close(); } TestModel result1; using (var fs = new FileStream("XmlWriterReaderTest1.xml", FileMode.Create)) { var writer = XmlDictionaryWriter.CreateDictionaryWriter(new XmlTextWriter(fs, Encoding.UTF8)); testModel.Serialize(writer); writer.Close(); } using (var fs = new FileStream("XmlWriterReaderTest1.xml", FileMode.Open)) { var reader = XmlDictionaryReader.CreateDictionaryReader(new XmlTextReader(fs)); result1 = reader.ReadXml <TestModel>() !; reader.Close(); } Assert.Equal( Tuple.Create(testModel.Id, testModel.Age, testModel.CreateTime, testModel.Name, testModel.Gender), Tuple.Create(result0.Id, result0.Age, result0.CreateTime, result0.Name, result0.Gender)); Assert.Equal( Tuple.Create(testModel.Id, testModel.Age, testModel.CreateTime, testModel.Name, testModel.Gender), Tuple.Create(result1.Id, result1.Age, result1.CreateTime, result1.Name, result1.Gender)); }
public void XmlWriterReaderNonGenericTest() { var testModel = TestModelFactory.Create(); TestModel result0; using (var fs = new FileStream("XmlWriterReaderNonGenericTest0.xml", FileMode.Create)) { var writer = new XmlTextWriter(fs, Encoding.UTF8); writer.WriteXml(typeof(TestModel), testModel); writer.Close(); } using (var fs = new FileStream("XmlWriterReaderNonGenericTest0.xml", FileMode.Open)) { var reader = new XmlTextReader(fs); result0 = (TestModel)reader.ReadXml(typeof(TestModel)) !; reader.Close(); } TestModel result1; using (var fs = new FileStream("XmlWriterReaderNonGenericTest0.xml", FileMode.Create)) { var writer = new XmlTextWriter(fs, Encoding.UTF8); testModel.Serialize(typeof(TestModel), writer); writer.Close(); } using (var fs = new FileStream("XmlWriterReaderNonGenericTest0.xml", FileMode.Open)) { var reader = new XmlTextReader(fs); result1 = (TestModel)reader.ReadXml(typeof(TestModel)) !; reader.Close(); } Assert.Equal( Tuple.Create(testModel.Id, testModel.Age, testModel.CreateTime, testModel.Name, testModel.Gender), Tuple.Create(result0.Id, result0.Age, result0.CreateTime, result0.Name, result0.Gender)); Assert.Equal( Tuple.Create(testModel.Id, testModel.Age, testModel.CreateTime, testModel.Name, testModel.Gender), Tuple.Create(result1.Id, result1.Age, result1.CreateTime, result1.Name, result1.Gender)); }
public void DataContractBytesGenericTest() => BytesGenericTest(new DataContractSerializer.Serializer(), TestModelFactory.Create());
public void YamlDotNetBytesGenericTest() => BytesGenericTest(new YamlDotNet.Serializer(), TestModelFactory.Create());
public void Utf8JsonBytesGenericTest() => BytesGenericTest(new Utf8Json.Serializer(), TestModelFactory.Create());
public void SystemTextJsonBytesGenericTest() => BytesGenericTest(new SystemTextJson.Serializer(), TestModelFactory.Create());
public void XmlBytesGenericTest() => BytesGenericTest(new Xml.Serializer(), TestModelFactory.Create());
public void BinaryBytesGenericTest() => BytesGenericTest(new Binary.Serializer(), TestModelFactory.Create());