Exemplo n.º 1
0
        public void CustomConverterDerivedTypeTest()
        {
            var srv = new UserSettingsService();

            var setts = new SettsMock4()
            {
                Obj = new ObjectType2()
                {
                    Value = "XYZ"
                }
            };

            var res1 = new StringBuilder();

            var ser = new BaseValueSerializer <IObjectType>(x => x.Value, x => new ObjectType2()
            {
                Value = x
            });

            srv.StoreSettings(setts, new StringWriter(res1), ser);
            var res2 = srv.ReadSettings <SettsMock4>(new StringReader("{\"Obj\":\"ABC\"}"), ser);

            Assert.AreEqual("{\"Obj\":\"XYZ\"}", res1.ToString());
            Assert.AreEqual("ABC", res2.Obj.Value);
        }
Exemplo n.º 2
0
        public void CustomConverterAndVersionTest()
        {
            var srv = new UserSettingsService();

            var setts = new SettsMock2()
            {
                Field1 = ""
            };

            var res1 = new StringBuilder();

            var ser = new BaseValueSerializer <string>(x => "ABC", x => "XYZ");

            srv.StoreSettings(setts, new StringWriter(res1), ser);
            var res2 = srv.ReadSettings <SettsMock2>(new StringReader("{\"Field1\":\"ABC\",\"Field3\":0.0,\"Field4\":false,\"__version\":\"2.1.0\"}"), ser);

            Assert.AreEqual("{\"Field1\":\"ABC\",\"Field3\":0.0,\"Field4\":false,\"__version\":\"2.1.0\"}", res1.ToString());
            Assert.AreEqual("XYZ", res2.Field1);
        }