Beispiel #1
0
        public void Serialize_Deserialize_Test()
        {
            var textJsonSerializer = new TextJsonSerializer(_serializerOptions);

            // Assert.Null(textJsonSerializer.Serialize(s1));
            Assert.Equal("null", textJsonSerializer.Serialize(null));

            var o1 = new TextJsonSerializerClass1()
            {
                Age  = 3,
                Id   = 1,
                Name = "HaHa"
            };

            var json1         = textJsonSerializer.Serialize(o1);
            var deserializeO1 = textJsonSerializer.Deserialize(json1, typeof(TextJsonSerializerClass1));

            Assert.Equal(typeof(TextJsonSerializerClass1), deserializeO1.GetType());

            var jsonSerializer = _provider.GetService <IJsonSerializer>();
            var json2          = jsonSerializer.Serialize(o1);

            Assert.Equal(json1, json2);

            var deserializeO2 = textJsonSerializer.Deserialize <TextJsonSerializerClass1>(json1);

            Assert.Equal(o1.Id, deserializeO2.Id);
            Assert.Equal(o1.Name, deserializeO2.Name);
            Assert.Equal(o1.Age, deserializeO2.Age);
        }
Beispiel #2
0
        public void TestDeSerialize()
        {
            var jsonSerializer = new TextJsonSerializer();

            var r = jsonSerializer.Serialize(new ValueObject
            {
                A = 10,
                B = 20,
            });

            Assert.AreNotEqual(r, null);

            var s = jsonSerializer.Deserialize <ValueObject>(r);

            Assert.AreEqual(s.A, 10);
        }
Beispiel #3
0
        public void Generics_Serialize_Deserialize_Test()
        {
            var textJsonSerializer = new TextJsonSerializer(_serializerOptions);

            var o = new JsonTestResult <JsonTestResultItem>()
            {
                Success = true,
                Data    = new JsonTestResultItem()
                {
                    Id   = "1",
                    Name = "virtual"
                }
            };

            var json = textJsonSerializer.Serialize(o);

            var o2 = textJsonSerializer.Deserialize <JsonTestResult <JsonTestResultItem> >(json);

            Assert.Equal(o.Success, o2.Success);
            Assert.Equal(o.Data.Id, o2.Data.Id);
            Assert.Equal(o.Data.Name, o2.Data.Name);
        }