示例#1
0
        public void Should_match_segment_and_flag_with_value()
        {
            var command      = "test -f test".Split(' ');
            var commandRoute = new CommandRoute("test [-f|flag]");

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

            mockSegment.Setup(x => x.Match("test")).Returns(() => matchResult);
            mockOptionalSegment.Setup(x => x.Name).Returns("flag");
            mockOptionalSegment.Setup(x => x.Match("-f test")).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));
        }
示例#2
0
        public void Should_return_null_if_segment_doesnt_match()
        {
            var command      = "test".Split(' ');
            var commandRoute = new CommandRoute("test");

            var matchResult = new MatchResult();
            var mockSegment = new Mock <ISegment>();

            mockSegment.Setup(x => x.Match("baaad")).Returns(() => matchResult);

            commandRoute.AddSegment(mockSegment.Object);

            var result = commandRoute.Match(command);

            Assert.Null(result);
        }
示例#3
0
        public void Should_match_segment()
        {
            var command = "test".Split(' ');
            var commandRoute = new CommandRoute("test");

            var matchResult = new MatchResult();
            var mockSegment = new Mock<ISegment>();

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

            commandRoute.AddSegment(mockSegment.Object);

            var result = commandRoute.Match(command);

            Assert.NotNull(result);
            Assert.Equal(1, result.MatchResults.Count);
            Assert.Equal(0, result.OptionalMatchResults.Count);
            Assert.True(result.MatchResults.Contains(matchResult));
        }
示例#4
0
        public void Should_match_segment()
        {
            var command      = "test".Split(' ');
            var commandRoute = new CommandRoute("test");

            var matchResult = new MatchResult();
            var mockSegment = new Mock <ISegment>();

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

            commandRoute.AddSegment(mockSegment.Object);

            var result = commandRoute.Match(command);

            Assert.NotNull(result);
            Assert.Equal(1, result.MatchResults.Count);
            Assert.Equal(0, result.OptionalMatchResults.Count);
            Assert.True(result.MatchResults.Contains(matchResult));
        }
示例#5
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);
        }
示例#6
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));
        }
示例#7
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));
        }
示例#8
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));
        }
示例#9
0
        public void Should_return_null_if_segment_doesnt_match()
        {
            var command = "test".Split(' ');
            var commandRoute = new CommandRoute("test");

            var matchResult = new MatchResult();
            var mockSegment = new Mock<ISegment>();

            mockSegment.Setup(x => x.Match("baaad")).Returns(() => matchResult);

            commandRoute.AddSegment(mockSegment.Object);

            var result = commandRoute.Match(command);

            Assert.Null(result);
        }
示例#10
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);
        }