SetRoutes() public method

public SetRoutes ( List routes ) : void
routes List
return void
コード例 #1
0
        public void Parse_CommandNameOnlyWithTrailingSpace()
        {
            // Arrange
            var parser = new OrderedCommandParser();
            parser.SetRoutes(_simpleRoute);

            var commandName = "";

            // Act
            var param = parser.Parse("ls ", out commandName);

            // Assert
            Assert.AreEqual(0, param.Count());
            Assert.AreEqual("ls", commandName);
        }
コード例 #2
0
        public void Parse_OrderedCommandParser_HandlesSwitchesAndRoutesTheCommandCorrectly()
        {
            // Arrange
            var parser = new OrderedCommandParser();
            var commandName = "";

            parser.SetRoutes(_routing.GetRoutes());

            // Act
            var param = parser.Parse("ls c:\\ProgramFiles *.csv /s /switch", out commandName);
            var route = _routing.FindRoute(commandName, param);

            // Assert
            Assert.AreEqual("ls", commandName);
            Assert.AreEqual(4, param.Count); // two param and 2 switches

            Assert.IsNotNull(route);
            Assert.AreEqual("ls", route.Name);
        }
コード例 #3
0
        public void Parse_OrderedCommandParser_AddsSwitchesToTheParamsCorrectly()
        {
            // Arrange
            var parser = new OrderedCommandParser();

            var commandName = "";
            parser.SetRoutes(_routing.GetRoutes());

            // Act
            var param = parser.Parse("ls c:\\ProgramFiles *.csv /s /switch", out commandName);
            var route = _routing.FindRoute(commandName, param);

            // Assert
            Assert.IsTrue(param.ContainsKey("/s"));
            Assert.IsTrue(param.ContainsKey("/switch"));

            Assert.IsNotNull(route);
            Assert.AreEqual("ls", route.Name);
        }
コード例 #4
0
        public void Parse_WithSingleKeyValueParameter()
        {
            // Arrange
            var parser = new OrderedCommandParser();
            parser.SetRoutes(_singleParamRoute);

            var commandName = "";

            // Act
            var param = parser.Parse(@"ls c:\", out commandName);

            // Assert
            Assert.AreEqual(1, param.Count());
            Assert.AreEqual("ls", commandName);
        }
コード例 #5
0
        public void Parse_TwoParamsSecondOneEscappedIncorrectlyAndThrowsAnException()
        {
            // Arrange
            var parser = new OrderedCommandParser();
            parser.SetRoutes(_twoParamRoute);

            var commandName = "";

            // Act
            var param = parser.Parse("ls c:\\ProgramFiles \"*.csv", out commandName);
        }
コード例 #6
0
        public void Parse_TwoParamsSecondOneEscapped()
        {
            // Arrange
            var parser = new OrderedCommandParser();
            parser.SetRoutes(_twoParamRoute);

            var commandName = "";

            // Act
            var param = parser.Parse("ls c:\\ProgramFiles \"*.csv\"", out commandName);

            // Assert
            Assert.AreEqual(2, param.Count());
            Assert.AreEqual("path", param.Keys.First());
            Assert.AreEqual("c:\\ProgramFiles", param.Values.First());

            Assert.AreEqual("filter", param.Keys.Skip(1).Take(1).Single());
            Assert.AreEqual(@"*.csv", param.Values.Skip(1).Take(1).Single());
        }
コード例 #7
0
        public void Parse_ParamsGetExtraSpacesTrimmed()
        {
            // Arrange
            var parser = new OrderedCommandParser();
            parser.SetRoutes(_singleParamRoute);

            var commandName = "";

            // Act
            var param = parser.Parse("ls  c:\\ProgramFiles\\", out commandName);

            // Assert
            Assert.AreEqual(1, param.Count());
            Assert.AreEqual("path", param.Keys.First());
            Assert.AreEqual("c:\\ProgramFiles\\", param.Values.First());
        }
コード例 #8
0
        public void Parse_SingleEscappedParam()
        {
            // Arrange
            var parser = new OrderedCommandParser();
            parser.SetRoutes(_singleParamRoute);

            var commandName = "";

            // Act
            var param = parser.Parse("ls \"c:\\Program Files\"", out commandName);

            // Assert
            Assert.AreEqual(1, param.Count());
            Assert.AreEqual("path", param.Keys.First());
            Assert.AreEqual("c:\\Program Files", param.Values.First());
        }
コード例 #9
0
        public void Parse_TwoParamAreSplitCorrectly()
        {
            // Arrange
            var parser = new OrderedCommandParser();
            parser.SetRoutes(_twoParamRoute);

            var commandName = "";

            // Act
            var param = parser.Parse(@"ls c:\ *.csv", out commandName);

            // Assert
            Assert.AreEqual(2, param.Count());
            Assert.AreEqual("path", param.Keys.First());
            Assert.AreEqual(@"c:\", param.Values.First());

            Assert.AreEqual("filter", param.Keys.Skip(1).Take(1).Single());
            Assert.AreEqual(@"*.csv", param.Values.Skip(1).Take(1).Single());
        }
コード例 #10
0
        public void Parse_WithTwoParamsOptionalNotSpecified()
        {
            // Arrange
            var parser = new OrderedCommandParser();
            parser.SetRoutes(_twoParamWithOptionalRoute);

            var commandName = "";

            // Act
            var param = parser.Parse(@"ls c:\", out commandName);

            // Assert
            Assert.AreEqual(1, param.Count());
            Assert.AreEqual("ls", commandName);
        }
コード例 #11
0
        public void Parse_WithTwoParameters()
        {
            // Arrange
            var parser = new OrderedCommandParser();
            parser.SetRoutes(_twoParamRoute);

            var commandName = "";

            // Act
            var param = parser.Parse(@"ls c:\ *.csv", out commandName);

            // Assert
            Assert.AreEqual(2, param.Count());
            Assert.AreEqual("ls", commandName);
        }
コード例 #12
0
        public void Parse_SingleParamIsSplitCorrectly()
        {
            // Arrange
            var parser = new OrderedCommandParser();
            parser.SetRoutes(_singleParamRoute);

            var commandName = "";

            // Act
            var param = parser.Parse(@"ls c:\", out commandName);

            // Assert
            Assert.AreEqual(1, param.Count());
            Assert.AreEqual("path", param.Keys.First());
            Assert.AreEqual(@"c:\", param.Values.First());
        }