Example #1
0
        public void TestEqualityOperatorClient()
        {
            var options = new JsonSerializerOptions();

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

            var json = JsonSerializer.Serialize(new Dictionary <string, object>()
            {
                { "type", "org.raisingthefloor.morphic.client" },
                { "solution", "thesolution" },
                { "preference", "thepreference" }
            });
            ClientSettingHandlerDescription client           = (ClientSettingHandlerDescription)JsonSerializer.Deserialize <SettingHandlerDescription>(json, options);
            ClientSettingHandlerDescription sameclient       = new ClientSettingHandlerDescription(new Preferences.Key("thesolution", "thepreference"));
            ClientSettingHandlerDescription differentclient1 = new ClientSettingHandlerDescription(new Preferences.Key("differentsolution", "thepreference"));
            ClientSettingHandlerDescription differentclient2 = new ClientSettingHandlerDescription(new Preferences.Key("thesolution", "differentpreference"));

            Assert.NotNull(client);
            Assert.NotNull(sameclient);
            Assert.NotNull(differentclient1);
            Assert.NotNull(differentclient2);
            Assert.Equal(client, sameclient);
            Assert.NotEqual(client, differentclient1);
            Assert.NotEqual(client, differentclient2);
        }
Example #2
0
        public void TestJsonDeserializeClient(string solution, string preference, 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", "org.raisingthefloor.morphic.client" },
                { "solution", solution },
                { "preference", preference }
            });
            var handler = JsonSerializer.Deserialize <SettingHandlerDescription>(json, options);

            Assert.NotNull(handler);
            if (success)
            {
                Assert.Equal(SettingHandlerDescription.HandlerKind.Client, handler.Kind);
                Assert.IsType <ClientSettingHandlerDescription>(handler);
                ClientSettingHandlerDescription client = (ClientSettingHandlerDescription)handler;
                Assert.Equal(solution, client.Key.Solution);
                Assert.Equal(preference, client.Key.Preference);
            }
            else
            {
                Assert.Equal(SettingHandlerDescription.HandlerKind.Unknown, handler.Kind);
            }
        }