예제 #1
0
        public void GetKeysFromPrefix_AllValues()
        {
            // Arrange
            var container = new PrefixContainer(
                new[]
            {
                "foo[bar]baz",
                "something[other]",
                "foo.baz",
                "foot[hello]",
                "fo[nothing]",
                "foo"
            }
                );
            string prefix = "";

            // Act
            IDictionary <string, string> result = container.GetKeysFromPrefix(prefix);

            // Assert
            Assert.Equal(4, result.Count());
            Assert.Equal("foo", result["foo"]);
            Assert.Equal("something", result["something"]);
            Assert.Equal("foot", result["foot"]);
            Assert.Equal("fo", result["fo"]);
        }
예제 #2
0
        public void GetKeysFromPrefix_MixedDotsAndBrackets()
        {
            // Arrange
            var container = new PrefixContainer(
                new[]
            {
                "foo[bar]baz",
                "something[other]",
                "foo.baz",
                "foot[hello]",
                "fo[nothing]",
                "foo"
            }
                );
            string prefix = "foo";

            // Act
            IDictionary <string, string> result = container.GetKeysFromPrefix(prefix);

            // Assert
            Assert.Equal(2, result.Count());
            Assert.True(result.ContainsKey("bar"));
            Assert.True(result.ContainsKey("baz"));
            Assert.Equal("foo[bar]", result["bar"]);
            Assert.Equal("foo.baz", result["baz"]);
        }
예제 #3
0
        public void GetKeysFromPrefix_DotsNotation()
        {
            // Arrange
            var container = new PrefixContainer(
                new[]
            {
                "foo.bar.baz",
                "something.other",
                "foo.baz",
                "foot.hello",
                "fo.nothing",
                "foo"
            }
                );
            string prefix = "foo";

            // Act
            IDictionary <string, string> result = container.GetKeysFromPrefix(prefix);

            // Assert
            Assert.Equal(2, result.Count());
            Assert.True(result.ContainsKey("bar"));
            Assert.True(result.ContainsKey("baz"));
            Assert.Equal("foo.bar", result["bar"]);
            Assert.Equal("foo.baz", result["baz"]);
        }
예제 #4
0
        public void ContainsPrefix_PositiveTests(string testValue)
        {
            // Arrange
            var container = new PrefixContainer(new[] { "a.b", "c.b.a", "a[d]", "a.c" });

            // Act & Assert
            Assert.True(container.ContainsPrefix(testValue));
        }
예제 #5
0
        public void ContainsPrefix_NonEmptyCollectionReturnsTrueIfPrefixIsEmptyString()
        {
            // Arrange
            var container = new PrefixContainer(new[] { "Hello" });

            // Act & Assert
            Assert.True(container.ContainsPrefix(""));
        }
예제 #6
0
        public void ContainsPrefix_MatchIsNotSimpleSubstringMatch()
        {
            // Arrange
            var container = new PrefixContainer(new[] { "Hello" });

            // Act & Assert
            Assert.False(container.ContainsPrefix("He"));
        }
예제 #7
0
        public void ContainsPrefix_MatchIsCaseInsensitive()
        {
            // Arrange
            var container = new PrefixContainer(new[] { "Hello" });

            // Act & Assert
            Assert.True(container.ContainsPrefix("hello"));
        }
예제 #8
0
        public void ContainsPrefix_ExactMatch()
        {
            // Arrange
            var container = new PrefixContainer(new[] { "Hello" });

            // Act & Assert
            Assert.True(container.ContainsPrefix("Hello"));
        }
예제 #9
0
        public void ContainsPrefix_EmptyCollectionReturnsFalse()
        {
            // Arrange
            var container = new PrefixContainer(new string[0]);

            // Act & Assert
            Assert.False(container.ContainsPrefix(""));
        }
예제 #10
0
        public void ContainsPrefix_GuardClauses()
        {
            // Arrange
            var container = new PrefixContainer(new string[0]);

            // Act & assert
            Assert.ThrowsArgumentNull(() => container.ContainsPrefix(null), "prefix");
        }
예제 #11
0
        public void ContainsPrefix_ShouldIdentifyCollectionWhenNonCollectionPropertyDoesNotOccurOnBinarySearchBoundary()
        {
            // Arrange
            var container = new PrefixContainer(new[] { "foo.a", "foo.b", "foo.c", "foo.d", "foo.esSomethingElse", "foo.es[0].a", "foo.es[0].b", "foo.es[0].c" });

            // Act & Assert
            Assert.True(container.ContainsPrefix("foo.es"));
        }
예제 #12
0
        public void ContainsPrefix_PrefixBoundaries()
        {
            // Arrange
            var container = new PrefixContainer(new[] { "Hello.There[0]" });

            // Act & Assert
            Assert.True(container.ContainsPrefix("hello"));
            Assert.True(container.ContainsPrefix("hello.there"));
            Assert.True(container.ContainsPrefix("hello.there[0]"));
            Assert.False(container.ContainsPrefix("hello.there.0"));
        }
예제 #13
0
        public void GetKeysFromPrefix_PrefixNotFound()
        {
            // Arrange
            var    container = new PrefixContainer(new[] { "foo[bar]", "something[other]", "foo.baz", "foot[hello]", "fo[nothing]", "foo" });
            string prefix    = "notfound";

            // Act
            IDictionary <string, string> result = container.GetKeysFromPrefix(prefix);

            // Assert
            Assert.Empty(result);
        }