Пример #1
0
        /// <summary>
        /// Configure the deserializer using relevant configuration parameter(s) in <paramref name="config" /> (if present)
        /// </summary>
        /// <param name="config">A collection containing configuration parameter(s) relevant to this deserializer.</param>
        /// <param name="isKey">Must be true - indicates this class is used to serialize keys. </param>
        /// <returns>An updated configuration collection.</returns>
        public IEnumerable <KeyValuePair <string, object> > Configure(IEnumerable <KeyValuePair <string, object> > config, bool isKey)
        {
            if (!isKey)
            {
                throw new InvalidOperationException($"{nameof(isKey)} must be true.");
            }

            return(InnerDeserializer.Configure(config, true));
        }
Пример #2
0
        public void DeserializerConstructValueViaConfig()
        {
            string testString = "hello world";
            var    serialized = new StringSerializer(Encoding.UTF8).Serialize("mytopic", testString);
            var    config     = new Dictionary <string, object>();

            config.Add("dotnet.string.deserializer.encoding.value", "utf-8");
            var deserializer = new StringDeserializer();
            var newConfig    = deserializer.Configure(config, false);

            Assert.Equal(0, newConfig.Count());
            Assert.Equal(testString, deserializer.Deserialize("mytopic", serialized));
        }
Пример #3
0
        public void DeserializeNoConfigValue()
        {
            try
            {
                var deserializer = new StringDeserializer();
                deserializer.Configure(new Dictionary <string, object>(), false);
            }
            catch (Exception)
            {
                return;
            }

            Assert.True(false, "Exception expected");
        }
Пример #4
0
        public void DeserializeInvalidConfigValue()
        {
            var config = new Dictionary <string, object>();

            config.Add("dotnet.string.deserializer.encoding.value", "invalid-encoding");
            try
            {
                var deserializer = new StringDeserializer();
                deserializer.Configure(config, false);
            }
            catch (Exception)
            {
                return;
            }

            Assert.True(false, "Exception expected");
        }
Пример #5
0
        public void DeserializeDoubleConfigValue()
        {
            var config = new Dictionary <string, object>();

            config.Add("dotnet.string.deserializer.encoding.value", "utf-8");
            try
            {
                var deserializer = new StringDeserializer(Encoding.UTF32);
                deserializer.Configure(config, false);
            }
            catch (ArgumentException)
            {
                return;
            }

            Assert.True(false, "Exception expected");
        }