コード例 #1
0
ファイル: TurtleFilter.cs プロジェクト: SureshDunna/Turtle
        public void Execute(string turtleCommandTemplate)
        {
            if (string.IsNullOrWhiteSpace(turtleCommandTemplate))
            {
                throw new BadCommandException();
            }

            var turtleCommands = turtleCommandTemplate.Split(new[] { CommandDelimeter }, StringSplitOptions.RemoveEmptyEntries);

            if (turtleCommands.Length > 2)
            {
                throw new BadCommandException();
            }

            if (!Enum.TryParse <TurtleCommand>(turtleCommands[0], true, out var command))
            {
                throw new BadCommandException();
            }

            switch (command)
            {
            case TurtleCommand.PLACE:
                if (turtleCommands.Length != 2)
                {
                    throw new BadCommandException();
                }

                //validating the positioning arguments
                _positionFilter.Execute(turtleCommands[1]);
                break;

            default:
                if (turtleCommands.Length != 1)
                {
                    throw new BadCommandException();
                }
                break;
            }

            //all good and getting the command and position values
            TurtleCommand = command;
            Position      = _positionFilter.Position;
        }
コード例 #2
0
 public void bad_command_when_argument_template_empty_or_null()
 {
     Assert.Throws <BadCommandException>(() => _positionFilter.Execute(string.Empty));
     Assert.Throws <BadCommandException>(() => _positionFilter.Execute(null));
 }