Example #1
0
        public void GetValues_WhenAskingForNonString_ShouldConvertValuesToType()
        {
            var querystring = new NameValueCollection()
            {
                { "key", "true" }
            };
            var source = new NameValuePairSource(querystring);

            var result = source.GetValues <bool>("key");

            result.ShouldBe(new [] { true });
        }
Example #2
0
        public void GetValues_WhenQuerystringHasValueForQueriedKey_ShouldReturnValue()
        {
            var querystring = new NameValueCollection()
            {
                { "key", "value" }
            };
            var source = new NameValuePairSource(querystring);

            var result = source.GetValues <string>("key");

            result.ShouldBe(new [] { "value" });
        }
Example #3
0
        public void GetValues_WhenQuerystringDoesNotHaveValueForQueriedKey_ShouldReturnEmptyList()
        {
            var querystring = new NameValueCollection()
            {
                { "key", "value" },
                { "key", "value2" }
            };
            var source = new NameValuePairSource(querystring);

            var result = source.GetValues <string>("anotherkey");

            result.ShouldBe(new string[0]);
        }
Example #4
0
        public void GetValues_WhenQuerystringHasValueThatWontMatchRequestedType_ShouldExcludeInvalidValueFromResult()
        {
            var querystring = new NameValueCollection()
            {
                { "key", "true" },
                { "key", "false" },
                { "key", "fal" }
            };
            var source = new NameValuePairSource(querystring);

            var result = source.GetValues <bool>("key");

            result.ShouldBe(new[] { true, false });
        }
Example #5
0
        public void GetValues_GivenMultipleValuesWithDifferentKeys_ShouldOnlyReturnTheResultsThatMatchRequestedKeyAndType()
        {
            var querystring = new NameValueCollection()
            {
                { "key", "true" },
                { "key", "false" },
                { "anotherKey", "value" },
                { "amount", "100.03" }
            };
            var source = new NameValuePairSource(querystring);

            var result = source.GetValues <decimal>("amount");

            result.ShouldBe(new[] { 100.03m });
        }