コード例 #1
0
        public void GetValue_GuardClauses()
        {
            // Arrange
            var valueProvider = new NameValuePairsValueProvider(_backingStore, null);

            // Act & assert
            Assert.ThrowsArgumentNull(() => valueProvider.GetValue(null), "key");
        }
コード例 #2
0
        public void GetValue_ReturnsNullIfKeyNotFound()
        {
            // Arrange
            var valueProvider = new NameValuePairsValueProvider(_backingStore, null);

            // Act
            ValueProviderResult vpResult = valueProvider.GetValue("bar");

            // Assert
            Assert.Null(vpResult);
        }
コード例 #3
0
        public void GetValue_SingleValue()
        {
            // Arrange
            var culture       = CultureInfo.GetCultureInfo("fr-FR");
            var valueProvider = new NameValuePairsValueProvider(_backingStore, culture);

            // Act
            ValueProviderResult vpResult = valueProvider.GetValue("bar.baz");

            // Assert
            Assert.NotNull(vpResult);
            Assert.Equal("someOtherValue", vpResult.RawValue);
            Assert.Equal("someOtherValue", vpResult.AttemptedValue);
            Assert.Equal(culture, vpResult.Culture);
        }
コード例 #4
0
        public void GetValue_NullValue(string key)
        {
            // Arrange
            var culture       = CultureInfo.GetCultureInfo("fr-FR");
            var valueProvider = new NameValuePairsValueProvider(_backingStore, culture);

            // Act
            ValueProviderResult vpResult = valueProvider.GetValue(key);

            // Assert
            Assert.NotNull(vpResult);
            Assert.Null(vpResult.RawValue);
            Assert.Null(vpResult.AttemptedValue);
            Assert.Equal(culture, vpResult.Culture);
        }
コード例 #5
0
        static void Main(string[] args)
        {
            List<KeyValuePair<string, string>> list = new List<KeyValuePair<string, string>>();
            list.Add(new KeyValuePair<string, string>("foobar", "1"));
            list.Add(new KeyValuePair<string, string>("foobar", "2"));
            list.Add(new KeyValuePair<string, string>("foobar", "3"));

            NameValuePairsValueProvider valueProvider = new NameValuePairsValueProvider(list, null);
            var result = valueProvider.GetValue("foobar");

            int[] value1 = (int[])result.ConvertTo(typeof(int[]));
            int value2 = (int)result.ConvertTo(typeof(int));

            Console.WriteLine("{0,-16}{1}", "RawValue", "NewValue");
            Console.WriteLine("{0,-16}{1}", result.RawValue.ConvertToString(), value1.ConvertToString());
            Console.WriteLine("{0,-16}{1}", result.RawValue.ConvertToString(), value2.ConvertToString());
        }
コード例 #6
0
        public void GetValue_MultiValue()
        {
            // Arrange
            var culture       = CultureInfo.GetCultureInfo("fr-FR");
            var valueProvider = new NameValuePairsValueProvider(_backingStore, culture);

            // Act
            ValueProviderResult vpResult = valueProvider.GetValue("foo");

            // Assert
            Assert.NotNull(vpResult);
            Assert.Equal(new List <string>()
            {
                "fooValue1", "fooValue2"
            }, (List <string>)vpResult.RawValue);
            Assert.Equal("fooValue1,fooValue2", vpResult.AttemptedValue);
            Assert.Equal(culture, vpResult.Culture);
        }
コード例 #7
0
        public void GetValue_NullMultipleValue()
        {
            // Arrange
            var backingStore = new KeyValuePair <string, string>[]
            {
                new KeyValuePair <string, string>("key", null),
                new KeyValuePair <string, string>("key", null),
                new KeyValuePair <string, string>("key", "value")
            };
            var culture       = CultureInfo.GetCultureInfo("fr-FR");
            var valueProvider = new NameValuePairsValueProvider(backingStore, culture);

            // Act
            ValueProviderResult vpResult = valueProvider.GetValue("key");

            // Assert
            Assert.Equal(new[] { null, null, "value" }, vpResult.RawValue as IEnumerable <string>);
            Assert.Equal(",,value", vpResult.AttemptedValue);
        }
コード例 #8
0
        public void GetValue_ReturnsNullIfKeyNotFound()
        {
            // Arrange
            var valueProvider = new NameValuePairsValueProvider(_backingStore, null);

            // Act
            ValueProviderResult vpResult = valueProvider.GetValue("bar");

            // Assert
            Assert.Null(vpResult);
        }
コード例 #9
0
        public void GetValue_MultiValue()
        {
            // Arrange
            var culture = CultureInfo.GetCultureInfo("fr-FR");
            var valueProvider = new NameValuePairsValueProvider(_backingStore, culture);

            // Act
            ValueProviderResult vpResult = valueProvider.GetValue("foo");

            // Assert
            Assert.NotNull(vpResult);
            Assert.Equal(new List<string>() { "fooValue1", "fooValue2" }, (List<string>)vpResult.RawValue);
            Assert.Equal("fooValue1,fooValue2", vpResult.AttemptedValue);
            Assert.Equal(culture, vpResult.Culture);
        }
コード例 #10
0
        public void GetValue_SingleValue()
        {
            // Arrange
            var culture = CultureInfo.GetCultureInfo("fr-FR");
            var valueProvider = new NameValuePairsValueProvider(_backingStore, culture);

            // Act
            ValueProviderResult vpResult = valueProvider.GetValue("bar.baz");

            // Assert
            Assert.NotNull(vpResult);
            Assert.Equal("someOtherValue", vpResult.RawValue);
            Assert.Equal("someOtherValue", vpResult.AttemptedValue);
            Assert.Equal(culture, vpResult.Culture);
        }
コード例 #11
0
        public void GetValue_GuardClauses()
        {
            // Arrange
            var valueProvider = new NameValuePairsValueProvider(_backingStore, null);

            // Act & assert
            Assert.ThrowsArgumentNull(
                () => valueProvider.GetValue(null),
                "key");
        }
コード例 #12
0
        public void GetValue_NullMultipleValue()
        {
            // Arrange
            var backingStore = new KeyValuePair<string, string>[] 
            { 
                new KeyValuePair<string, string>("key", null),
                new KeyValuePair<string, string>("key", null),
                new KeyValuePair<string, string>("key", "value")
            };
            var culture = CultureInfo.GetCultureInfo("fr-FR");
            var valueProvider = new NameValuePairsValueProvider(backingStore, culture);

            // Act
            ValueProviderResult vpResult = valueProvider.GetValue("key");

            // Assert
            Assert.Equal(new[] { null, null, "value" }, vpResult.RawValue as IEnumerable<string>);
            Assert.Equal(",,value", vpResult.AttemptedValue);
        }
コード例 #13
0
        public void GetValue_NullValue(string key)
        {
            // Arrange
            var culture = CultureInfo.GetCultureInfo("fr-FR");
            var valueProvider = new NameValuePairsValueProvider(_backingStore, culture);

            // Act
            ValueProviderResult vpResult = valueProvider.GetValue(key);

            // Assert
            Assert.NotNull(vpResult);
            Assert.Equal(null, vpResult.RawValue);
            Assert.Equal(null, vpResult.AttemptedValue);
            Assert.Equal(culture, vpResult.Culture);
        }