public void ListDictionary()
        {
            var input = new Dictionary <string, string>
            {
                { "ListDictionary:abc:0", "abc_0" },
                { "ListDictionary:abc:1", "abc_1" },
                { "ListDictionary:def:0", "def_0" },
                { "ListDictionary:def:1", "def_1" },
                { "ListDictionary:def:2", "def_2" }
            };

            var configurationBuilder = new ConfigurationBuilder();

            configurationBuilder.AddInMemoryCollection(input);
            var config = configurationBuilder.Build();

            var options = new OptionsWithDictionary();

            config.FastBind(options);

            Assert.AreEqual(2, options.ListDictionary.Count);
            Assert.AreEqual(2, options.ListDictionary["abc"].Count);
            Assert.AreEqual(3, options.ListDictionary["def"].Count);

            Assert.AreEqual("abc_0", options.ListDictionary["abc"][0]);
            Assert.AreEqual("abc_1", options.ListDictionary["abc"][1]);
            Assert.AreEqual("def_0", options.ListDictionary["def"][0]);
            Assert.AreEqual("def_1", options.ListDictionary["def"][1]);
            Assert.AreEqual("def_2", options.ListDictionary["def"][2]);
        }
        public void AlreadyInitializedStringDictionaryBinding()
        {
            var input = new Dictionary <string, string>
            {
                { "AlreadyInitializedStringDictionaryInterface:abc", "val_1" },
                { "AlreadyInitializedStringDictionaryInterface:def", "val_2" },
                { "AlreadyInitializedStringDictionaryInterface:ghi", "val_3" }
            };

            var configurationBuilder = new ConfigurationBuilder();

            configurationBuilder.AddInMemoryCollection(input);
            var config = configurationBuilder.Build();

            var options = new OptionsWithDictionary();

            config.FastBind(options);

            Assert.IsNotNull(options.AlreadyInitializedStringDictionaryInterface);
            Assert.AreEqual(4, options.AlreadyInitializedStringDictionaryInterface.Count);

            Assert.AreEqual("This was already here", options.AlreadyInitializedStringDictionaryInterface["123"]);
            Assert.AreEqual("val_1", options.AlreadyInitializedStringDictionaryInterface["abc"]);
            Assert.AreEqual("val_2", options.AlreadyInitializedStringDictionaryInterface["def"]);
            Assert.AreEqual("val_3", options.AlreadyInitializedStringDictionaryInterface["ghi"]);
        }
Ejemplo n.º 3
0
        public void NonStringKeyDictionaryBinding()
        {
            var input = new Dictionary <string, string>
            {
                { "NonStringKeyDictionary:abc", "val_1" },
                { "NonStringKeyDictionary:def", "val_2" },
                { "NonStringKeyDictionary:ghi", "val_3" }
            };

            var builder = new ConfigurationBuilder(new MemoryConfigurationSource(input));
            var config  = builder.Build();
            var options = new OptionsWithDictionary();

            config.Bind(options);

            Assert.Equal(0, options.NonStringKeyDictionary.Count);
        }
        public void NonStringKeyDictionaryBinding()
        {
            var input = new Dictionary <string, string>
            {
                { "NonStringKeyDictionary:abc", "val_1" },
                { "NonStringKeyDictionary:def", "val_2" },
                { "NonStringKeyDictionary:ghi", "val_3" }
            };

            var configurationBuilder = new ConfigurationBuilder();

            configurationBuilder.AddInMemoryCollection(input);
            var config = configurationBuilder.Build();

            var options = new OptionsWithDictionary();

            config.FastBind(options);

            Assert.AreEqual(0, options.NonStringKeyDictionary.Count);
        }
Ejemplo n.º 5
0
        public void ObjectDictionary()
        {
            var input = new Dictionary <string, string>
            {
                { "ObjectDictionary:abc:Integer", "1" },
                { "ObjectDictionary:def:Integer", "2" },
                { "ObjectDictionary:ghi:Integer", "3" }
            };

            var builder = new ConfigurationBuilder(new MemoryConfigurationSource(input));
            var config  = builder.Build();
            var options = new OptionsWithDictionary();

            config.Bind(options);

            Assert.Equal(3, options.ObjectDictionary.Count);

            Assert.Equal(1, options.ObjectDictionary["abc"].Integer);
            Assert.Equal(2, options.ObjectDictionary["def"].Integer);
            Assert.Equal(3, options.ObjectDictionary["ghi"].Integer);
        }
Ejemplo n.º 6
0
        public void IntDictionaryBinding()
        {
            var input = new Dictionary <string, string>
            {
                { "IntDictionary:abc", "42" },
                { "IntDictionary:def", "43" },
                { "IntDictionary:ghi", "44" }
            };

            var builder = new ConfigurationBuilder(new MemoryConfigurationSource(input));
            var config  = builder.Build();
            var options = new OptionsWithDictionary();

            config.Bind(options);

            Assert.Equal(3, options.IntDictionary.Count);

            Assert.Equal(42, options.IntDictionary["abc"]);
            Assert.Equal(43, options.IntDictionary["def"]);
            Assert.Equal(44, options.IntDictionary["ghi"]);
        }
        public void StringDictionaryBinding()
        {
            var input = new Dictionary <string, string>
            {
                { "StringDictionary:abc", "val_1" },
                { "StringDictionary:def", "val_2" },
                { "StringDictionary:ghi", "val_3" }
            };

            var configurationBuilder = new ConfigurationBuilder();

            configurationBuilder.AddInMemoryCollection(input);
            var config = configurationBuilder.Build();

            var options = new OptionsWithDictionary();

            config.Bind(options);

            Assert.Equal(3, options.StringDictionary.Count);

            Assert.Equal("val_1", options.StringDictionary["abc"]);
            Assert.Equal("val_2", options.StringDictionary["def"]);
            Assert.Equal("val_3", options.StringDictionary["ghi"]);
        }