Beispiel #1
0
        public void Should_match_multiple_segments()
        {
            var command = "test value".Split(' ');
            var commandRoute = new CommandRoute("test {value}");

            var matchResult = new MatchResult();
            var namedMatchResult = new NamedValueMatchResult("value", "value");
            var mockSegment = new Mock<ISegment>();
            var mockVariableSegment = new Mock<ISegment>();

            mockSegment.Setup(x => x.Match("test")).Returns(() => matchResult);
            mockVariableSegment.Setup(x => x.Match("value")).Returns(() => namedMatchResult);

            commandRoute.AddSegment(mockSegment.Object);
            commandRoute.AddSegment(mockVariableSegment.Object);

            var result = commandRoute.Match(command);

            Assert.NotNull(result);
            Assert.Equal(2, result.MatchResults.Count);
            Assert.Equal(0, result.OptionalMatchResults.Count);
            Assert.True(result.MatchResults.Contains(matchResult));
            Assert.True(result.MatchResults.Contains(namedMatchResult));
        }
Beispiel #2
0
        public void Should_match_segment_and_flag()
        {
            var command = "test -f".Split(' ');
            var commandRoute = new CommandRoute("test [-f|flag]");

            var matchResult = new MatchResult();
            var namedMatchResult = new NamedValueMatchResult("flag", true);
            var mockSegment = new Mock<ISegment>();
            var mockOptionalSegment = new Mock<ISegment>();

            mockSegment.Setup(x => x.Match("test")).Returns(() => matchResult);
            mockOptionalSegment.Setup(x => x.Match("-f")).Returns(() => namedMatchResult);

            commandRoute.AddSegment(mockSegment.Object);
            commandRoute.AddOptionalSegment(mockOptionalSegment.Object);

            var result = commandRoute.Match(command);

            Assert.NotNull(result);
            Assert.Equal(1, result.MatchResults.Count);
            Assert.Equal(1, result.OptionalMatchResults.Count);
            Assert.True(result.MatchResults.Contains(matchResult));
            Assert.True(result.OptionalMatchResults.Contains(namedMatchResult));
        }
Beispiel #3
0
        public void Should_return_null_if_optional_segment_doesnt_match()
        {
            var command = "test -f".Split(' ');
            var commandRoute = new CommandRoute("test [-f|flag]");

            var matchResult = new MatchResult();
            var namedMatchResult = new NamedValueMatchResult("flag", true);
            var mockSegment = new Mock<ISegment>();
            var mockOptionalSegment = new Mock<ISegment>();

            mockSegment.Setup(x => x.Match("test")).Returns(() => matchResult);
            mockOptionalSegment.Setup(x => x.Match("-o")).Returns(() => namedMatchResult);

            commandRoute.AddSegment(mockSegment.Object);
            commandRoute.AddOptionalSegment(mockOptionalSegment.Object);

            var result = commandRoute.Match(command);

            Assert.Null(result);
        }