コード例 #1
0
        static void Main(string[] args)
        {
            Dictionary<string, string> dictionary = new Dictionary<string, string>();
            dictionary.Add("contacts[0].Name", "张三");
            dictionary.Add("contacts[0].PhoneNo", "123456789");
            dictionary.Add("contacts[0].EmailAddress", "*****@*****.**");
            dictionary.Add("contacts[1].Name", "李四");
            dictionary.Add("contacts[1].PhoneNo", "987654321");
            dictionary.Add("contacts[1].EmailAddress", "*****@*****.**");

            NameValuePairsValueProvider valueProvider = new NameValuePairsValueProvider(dictionary.ToArray(), null);

            //Prefix=""
            Console.WriteLine("Prefix: <Empty>");
            Console.WriteLine("{0,-14}{1}", "Key", "Value");
            IDictionary<string, string> keys = valueProvider.GetKeysFromPrefix(string.Empty);
            foreach (var item in keys)
            {
                Console.WriteLine("{0,-14}{1}", item.Key, item.Value);
            }

            //Prefix="contact"
            Console.WriteLine("\nPrefix: contact");
            Console.WriteLine("{0,-14}{1}", "Key", "Value");
            keys = valueProvider.GetKeysFromPrefix("contact");
            foreach (var item in keys)
            {
                Console.WriteLine("{0,-14}{1}", item.Key, item.Value);
            }

            //Prefix="contacts[0]"
            Console.WriteLine("\nPrefix: contacts[0]");
            Console.WriteLine("{0,-14}{1}", "Key", "Value");
            keys = valueProvider.GetKeysFromPrefix("contacts[0]");
            foreach (var item in keys)
            {
                Console.WriteLine("{0,-14}{1}", item.Key, item.Value);
            }

            //Prefix="contacts[1]"
            Console.WriteLine("\nPrefix: contacts[1]");
            Console.WriteLine("{0,-14}{1}", "Key", "Value");
            keys = valueProvider.GetKeysFromPrefix("contacts[1]");
            foreach (var item in keys)
            {
                Console.WriteLine("{0,-14}{1}", item.Key, item.Value);
            }
        }
コード例 #2
0
        public void GetKeysFromPrefix_GuardClauses()
        {
            // Arrange
            var valueProvider = new NameValuePairsValueProvider(_backingStore, null);

            // Act & assert
            Assert.ThrowsArgumentNull(() => valueProvider.GetKeysFromPrefix(null), "prefix");
        }
コード例 #3
0
        public void GetKeysFromPrefix_UnknownPrefix_ReturnsEmptyDictionary()
        {
            // Arrange
            var valueProvider = new NameValuePairsValueProvider(_backingStore, null);

            // Act
            IDictionary <string, string> result = valueProvider.GetKeysFromPrefix("abc");

            // Assert
            Assert.Empty(result);
        }
コード例 #4
0
        public void GetKeysFromPrefix_EmptyPrefix_ReturnsAllPrefixes()
        {
            // Arrange
            var valueProvider = new NameValuePairsValueProvider(_backingStore, null);

            // Act
            IDictionary <string, string> result = valueProvider.GetKeysFromPrefix("");

            // Assert
            Assert.Equal(2, result.Count);
            Assert.Equal("foo", result["foo"]);
            Assert.Equal("bar", result["bar"]);
        }
コード例 #5
0
        static void Main(string[] args)
        {
            Dictionary<string, string> dictionary = new Dictionary<string, string>();
            dictionary.Add("contact.Name", "张三");
            dictionary.Add("contact.PhoneNo", "123456789");
            dictionary.Add("contact.EmailAddress", "*****@*****.**");
            dictionary.Add("contact.Address.Province", "江苏");
            dictionary.Add("contact.Address.City", "苏州");
            dictionary.Add("contact.Address.District", "工业园区");
            dictionary.Add("contact.Address.Street", "星湖街328号");
            NameValuePairsValueProvider valueProvider = new NameValuePairsValueProvider(dictionary.ToArray(), null);

            //Prefix=""
            Console.WriteLine("Prefix: <Empty>");
            Console.WriteLine("{0,-14}{1}", "Key", "Value");
            IDictionary<string, string> keys = valueProvider.GetKeysFromPrefix(string.Empty);
            foreach (var item in keys)
            {
                Console.WriteLine("{0,-14}{1}", item.Key, item.Value);
            }

            //Prefix="contact"
            Console.WriteLine("\nPrefix: contact");
            Console.WriteLine("{0,-14}{1}", "Key", "Value");
            keys = valueProvider.GetKeysFromPrefix("contact");
            foreach (var item in keys)
            {
                Console.WriteLine("{0,-14}{1}", item.Key, item.Value);
            }

            //Prefix="contact.Address"
            Console.WriteLine("\nPrefix: contact.Address");
            Console.WriteLine("{0,-14}{1}", "Key", "Value");
            keys = valueProvider.GetKeysFromPrefix("contact.Address");
            foreach (var item in keys)
            {
                Console.WriteLine("{0,-14}{1}", item.Key, item.Value);
            }
        }
コード例 #6
0
        public void GetKeysFromPrefix_KnownPrefix_ReturnsMatchingItems()
        {
            // Arrange
            var valueProvider = new NameValuePairsValueProvider(_backingStore, null);

            // Act
            IDictionary <string, string> result = valueProvider.GetKeysFromPrefix("bar");

            // Assert
            KeyValuePair <string, string> kvp = Assert.Single(result);

            Assert.Equal("baz", kvp.Key);
            Assert.Equal("bar.baz", kvp.Value);
        }
コード例 #7
0
        public void GetKeysFromPrefix_EmptyPrefix_ReturnsAllPrefixes()
        {
            // Arrange
            var valueProvider = new NameValuePairsValueProvider(_backingStore, null);

            // Act
            IDictionary <string, string> result = valueProvider.GetKeysFromPrefix("");

            // Assert
            Assert.Equal <KeyValuePair <string, string> >(
                result.OrderBy(kvp => kvp.Key),
                new Dictionary <string, string> {
                { "bar", "bar" }, { "foo", "foo" }, { "null_value", "null_value" }, { "prefix", "prefix" }
            });
        }
コード例 #8
0
        public void GetKeysFromPrefix_GuardClauses()
        {
            // Arrange
            var valueProvider = new NameValuePairsValueProvider(_backingStore, null);

            // Act & assert
            Assert.ThrowsArgumentNull(
                () => valueProvider.GetKeysFromPrefix(null),
                "prefix");
        }
コード例 #9
0
        public void GetKeysFromPrefix_KnownPrefix_ReturnsMatchingItems()
        {
            // Arrange
            var valueProvider = new NameValuePairsValueProvider(_backingStore, null);

            // Act
            IDictionary<string, string> result = valueProvider.GetKeysFromPrefix("bar");

            // Assert
            KeyValuePair<string, string> kvp = Assert.Single(result);
            Assert.Equal("baz", kvp.Key);
            Assert.Equal("bar.baz", kvp.Value);
        }
コード例 #10
0
        public void GetKeysFromPrefix_UnknownPrefix_ReturnsEmptyDictionary()
        {
            // Arrange
            var valueProvider = new NameValuePairsValueProvider(_backingStore, null);

            // Act
            IDictionary<string, string> result = valueProvider.GetKeysFromPrefix("abc");

            // Assert
            Assert.Empty(result);
        }
コード例 #11
0
        public void GetKeysFromPrefix_EmptyPrefix_ReturnsAllPrefixes()
        {
            // Arrange
            var valueProvider = new NameValuePairsValueProvider(_backingStore, null);

            // Act
            IDictionary<string, string> result = valueProvider.GetKeysFromPrefix("");

            // Assert
            Assert.Equal(2, result.Count);
            Assert.Equal("foo", result["foo"]);
            Assert.Equal("bar", result["bar"]);
        }
コード例 #12
0
        public void GetKeysFromPrefix_EmptyPrefix_ReturnsAllPrefixes()
        {
            // Arrange
            var valueProvider = new NameValuePairsValueProvider(_backingStore, null);

            // Act
            IDictionary<string, string> result = valueProvider.GetKeysFromPrefix("");

            // Assert
            Assert.Equal<KeyValuePair<string, string>>(
                result.OrderBy(kvp => kvp.Key),
                new Dictionary<string, string> { { "bar", "bar" }, { "foo", "foo" }, { "null_value", "null_value" }, { "prefix", "prefix" } });
        }