Пример #1
0
        public void GroupingsShouldHaveTheCorrectKey()
        {
            var lookup = new QueryLookup("?key=value");
            IGrouping <string, string> group = lookup.Single();

            Assert.That(group.Key, Is.EqualTo("key"));
        }
Пример #2
0
        public void GetEnumeratorShouldReturnAllTheGroups()
        {
            var lookup = new QueryLookup("?key1=value1&key2=value2");

            IGrouping <string, string>[] groups = lookup.ToArray();

            Assert.That(groups, Has.Length.EqualTo(2));
        }
Пример #3
0
        public void GroupingsContainsShouldReturnWhetherTheValueIsPresentOrNot()
        {
            var lookup = new QueryLookup("?key=value");
            ICollection <string> group = (ICollection <string>)lookup.Single();

            Assert.That(group.Contains("value"), Is.True);
            Assert.That(group.Contains("unknown"), Is.False);
        }
Пример #4
0
        public void GroupingsShouldReturnAllTheValues()
        {
            var lookup = new QueryLookup("?key=1&key=2");
            IGrouping <string, string> group = lookup.Single();

            string[] values = group.ToArray();

            Assert.That(values, Is.EqualTo(new[] { "1", "2" }));
        }
Пример #5
0
        public void NonGenericGetEnumeratorShouldReturnAllTheGroups()
        {
            IEnumerable lookup = new QueryLookup("?key1=value1&key2=value2");

            IEnumerator enumerator = lookup.GetEnumerator();

            Assert.That(enumerator.MoveNext(), Is.True);
            Assert.That(enumerator.MoveNext(), Is.True);
            Assert.That(enumerator.MoveNext(), Is.False);
        }
Пример #6
0
        public void GroupingsCopyToShouldCopyAllTheValues()
        {
            var lookup = new QueryLookup("?key=1&key=2");
            ICollection <string> group = (ICollection <string>)lookup.Single();

            string[] target = new string[3];
            group.CopyTo(target, 1);

            Assert.That(target, Is.EqualTo(new[] { null, "1", "2" }));
        }
Пример #7
0
        public void GroupingsShouldBeAReadOnlyCollection()
        {
            var lookup = new QueryLookup("?key=value");
            ICollection <string> group = (ICollection <string>)lookup.Single();

            Assert.That(group.Count, Is.EqualTo(1));
            Assert.That(group.IsReadOnly, Is.True);
            Assert.That(() => group.Add(""), Throws.InstanceOf <NotSupportedException>());
            Assert.That(() => group.Clear(), Throws.InstanceOf <NotSupportedException>());
            Assert.That(() => group.Remove(""), Throws.InstanceOf <NotSupportedException>());
        }
Пример #8
0
        public void GroupingsNonGenericGetEnumeratorShouldReturnTheValues()
        {
            var         lookup     = new QueryLookup("?key=1&key=2");
            IEnumerable group      = lookup.Single();
            IEnumerator enumerator = group.GetEnumerator();

            // We can test the order of the results as well here...
            Assert.That(enumerator.MoveNext(), Is.True);
            Assert.That(enumerator.Current, Is.EqualTo("1"));
            Assert.That(enumerator.MoveNext(), Is.True);
            Assert.That(enumerator.Current, Is.EqualTo("2"));
            Assert.That(enumerator.MoveNext(), Is.False);
        }
Пример #9
0
        public void ShouldHandleKeysWithoutValues()
        {
            var lookup = new QueryLookup("?key");

            Assert.That(lookup.Contains("key"), Is.True);
        }
Пример #10
0
        public void ShouldHandleEmptyQueryStrings()
        {
            var lookup = new QueryLookup(string.Empty);

            Assert.That(lookup.Count, Is.EqualTo(0));
        }
Пример #11
0
        public void IndexShouldReturnAnEmptySequenceIfTheKeyDoesNotExist()
        {
            var lookup = new QueryLookup("?key=value");

            Assert.That(lookup["unknown"], Is.Empty);
        }
Пример #12
0
        public void IndexShouldReturnAllTheValues()
        {
            var lookup = new QueryLookup("?key=1&key=2");

            Assert.That(lookup["key"].ToList(), Is.EqualTo(new[] { "1", "2" }));
        }
Пример #13
0
        public void ContainsShouldReturnTrueIfTheKeyIsPresent()
        {
            var lookup = new QueryLookup("key=value");

            Assert.That(lookup.Contains("key"), Is.True);
        }
Пример #14
0
        public void CountShouldReturnTheNumberOfUniqueKeys()
        {
            var lookup = new QueryLookup("?key1=_&key2=_&key1=_");

            Assert.That(lookup.Count, Is.EqualTo(2));
        }
Пример #15
0
        public void ShouldUnescapePrecentageEscapedKeys()
        {
            var lookup = new QueryLookup("?%41");

            Assert.That(lookup.Contains("A"), Is.True);
        }
Пример #16
0
        public void ContainsShouldReturnFalseIfTheKeyIsNotPresent()
        {
            var lookup = new QueryLookup("?key=value");

            Assert.That(lookup.Contains("unknown"), Is.False);
        }
Пример #17
0
        public void ShouldIgnoreTheCaseOfPercentageEscapedValues()
        {
            var lookup = new QueryLookup("?%2A=%2a");

            Assert.That(lookup["*"].Single(), Is.EqualTo("*"));
        }
Пример #18
0
        public void ShouldUnescapeSpacesEncodedAsPlus()
        {
            var lookup = new QueryLookup("?a+b=c+d");

            Assert.That(lookup["a b"].Single(), Is.EqualTo("c d"));
        }