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

            var setts1 = new SettsMock1()
            {
                Field1 = "AAA",
                Field2 = 10
            };

            var setts2 = new SettsMock2()
            {
                Field1 = "BBB",
                Field3 = 12.5,
                Field4 = true
            };

            var res1 = new StringBuilder();
            var res2 = new StringBuilder();

            srv.StoreSettings(setts1, new StringWriter(res1));
            srv.StoreSettings(setts2, new StringWriter(res2));

            Assert.AreEqual("{\"Field1\":\"AAA\",\"Field2\":10.0}", res1.ToString());
            Assert.AreEqual("{\"Field1\":\"BBB\",\"Field3\":12.5,\"Field4\":true,\"__version\":\"2.1.0\"}", res2.ToString());
        }
Ejemplo n.º 2
0
        public void WriteSettingsTest()
        {
            var srv = new UserSettingsService(m_ServHelper.WorkingDir,
                                              new UserSettingsAttribute("SettsStorage", true));

            var setts1 = new SettsMock1()
            {
                Field1 = "AAA",
                Field2 = 10
            };

            var setts2 = new SettsMock2()
            {
                Field1 = "BBB",
                Field3 = 12.5,
                Field4 = true
            };

            var settsFile1 = Path.Combine(m_ServHelper.WorkingDir, "SettsStorage", "mock1.setts");
            var settsFile2 = Path.Combine(m_ServHelper.WorkingDir, "SettsStorage", "mock2.setts");

            srv.StoreSettings(setts1, "mock1");
            srv.StoreSettings(setts2, "mock2");

            Assert.IsTrue(File.Exists(settsFile1));
            Assert.IsTrue(File.Exists(settsFile2));
            Assert.AreEqual("{\"Field1\":\"AAA\",\"Field2\":10.0,\"__version\":\"0.0\"}", File.ReadAllText(settsFile1));
            Assert.AreEqual("{\"Field1\":\"BBB\",\"Field3\":12.5,\"Field4\":true,\"__version\":\"2.1.0\"}", File.ReadAllText(settsFile2));
        }
Ejemplo n.º 3
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);
        }