예제 #1
0
        public void TestEqualityOperatorIni()
        {
            var options = new JsonSerializerOptions();

            options.Converters.Add(new JsonElementInferredTypeConverter());
            options.Converters.Add(new SettingHandlerDescription.JsonConverter());

            var json = JsonSerializer.Serialize(new Dictionary <string, object>()
            {
                { "type", "com.microsoft.windows.ini" },
                { "filename", "thefile" },
                { "section", "thesection" },
                { "key", "thekey" }
            });
            IniSettingHandlerDescription ini           = (IniSettingHandlerDescription)JsonSerializer.Deserialize <SettingHandlerDescription>(json, options);
            IniSettingHandlerDescription sameini       = new IniSettingHandlerDescription("thefile", "thesection", "thekey");
            IniSettingHandlerDescription differentini1 = new IniSettingHandlerDescription("differentfile", "thesection", "thekey");
            IniSettingHandlerDescription differentini2 = new IniSettingHandlerDescription("thefile", "differentsection", "thekey");
            IniSettingHandlerDescription differentini3 = new IniSettingHandlerDescription("thefile", "thesection", "differentkey");

            Assert.NotNull(ini);
            Assert.NotNull(sameini);
            Assert.NotNull(differentini1);
            Assert.NotNull(differentini2);
            Assert.NotNull(differentini3);
            Assert.Equal(ini, sameini);
            Assert.NotEqual(ini, differentini1);
            Assert.NotEqual(ini, differentini2);
            Assert.NotEqual(ini, differentini3);
        }
예제 #2
0
        public void TestJsonDeserializeIni(string filename, string section, string key, bool success)
        {
            var options = new JsonSerializerOptions();

            options.Converters.Add(new JsonElementInferredTypeConverter());
            options.Converters.Add(new SettingHandlerDescription.JsonConverter());

            var json = JsonSerializer.Serialize(new Dictionary <string, object>()
            {
                { "type", "com.microsoft.windows.ini" },
                { "filename", filename },
                { "section", section },
                { "key", key }
            });
            var handler = JsonSerializer.Deserialize <SettingHandlerDescription>(json, options);

            Assert.NotNull(handler);
            if (success)
            {
                Assert.Equal(SettingHandlerDescription.HandlerKind.Ini, handler.Kind);
                Assert.IsType <IniSettingHandlerDescription>(handler);
                IniSettingHandlerDescription ini = (IniSettingHandlerDescription)handler;
                Assert.Equal(filename, ini.Filename);
                Assert.Equal(section, ini.Section);
                Assert.Equal(key, ini.Key);
            }
            else
            {
                Assert.Equal(SettingHandlerDescription.HandlerKind.Unknown, handler.Kind);
            }
        }