public void Should_setup_competition()
        {
            var competitionData = new InputCompetitionDataDTO
            {
                ArenaBottomLeftCoords = new ArenaCoordinatesDTO {
                    X = "0", Y = "0"
                },
                ArenaUpperRightCoords = new ArenaCoordinatesDTO {
                    X = "5", Y = "5"
                }
            };

            arenaFactoryMock.Setup(m => m.GetArenaCoordinates()).Returns(new ArenaCoordinates());

            gameConsole.SetUpCompetition(competitionData);

            battleArenaMock.Verify(a => a.SetUpArena(It.IsAny <IArenaCoordinates>(), It.IsAny <IArenaCoordinates>()), Times.Once);
            battleArenaMock.Verify(a => a.DeployRobots(It.IsAny <IList <IRobot> >()), Times.Once);
            navigationSystemMock.Verify(ns => ns.ConnectNavigationSystemToBattleArena(It.IsAny <IBattleArena>()), Times.Once);
        }
        public void Should_start_competition()
        {
            var competitionData = new InputCompetitionDataDTO
            {
                ArenaBottomLeftCoords = new ArenaCoordinatesDTO {
                    X = "0", Y = "0"
                },
                ArenaUpperRightCoords = new ArenaCoordinatesDTO {
                    X = "5", Y = "5"
                },
                RobotsToDeploy = new List <InputRobotDTO> {
                    new InputRobotDTO
                    {
                        Id          = 1,
                        BattleMoves = new List <string> {
                            "L", "M"
                        },
                        StartHeadingDirection = "N",
                        StartLocation         = new ArenaCoordinatesDTO {
                            X = "1", Y = "2"
                        }
                    }
                }
            };

            robotFactoryMock.Setup(r => r.GetRobot()).Returns(new Robot(new Compass())
            {
                Position = new RobotPosition(), BattleMoves = new List <RobotMove>()
            });
            arenaFactoryMock.Setup(a => a.GetArenaCoordinates()).Returns(new ArenaCoordinates());

            gameConsole.SetUpCompetition(competitionData);
            gameConsole.StartCompetition();

            consoleMock.Verify(c => c.WriteLine(It.Is <string>(t => t.Equals(">>> Competition started"))), Times.Exactly(1));
            consoleMock.Verify(c => c.WriteLine(It.Is <string>(t => t.Equals(">>> Robot # {0} is moving")), It.Is <int>(id => id == 1)), Times.Exactly(1));
            navigationSystemMock.Verify(ns => ns.MoveRobot(It.Is <int>(id => id == 1), RobotMove.L), Times.Exactly(1));
            navigationSystemMock.Verify(ns => ns.MoveRobot(It.Is <int>(id => id == 1), RobotMove.M), Times.Exactly(1));
            consoleMock.Verify(c => c.WriteLine(It.Is <string>(t => t.Equals(">>> Robot # {0} finished")), It.Is <int>(id => id == 1)), Times.Exactly(1));
        }
Exemple #3
0
 public void Start(InputCompetitionDataDTO competitionData)
 {
     if (competitionData != null)
     {
         try
         {
             _gameConsole.SetUpCompetition(competitionData);
             _gameConsole.StartCompetition();
             _gameConsole.EndCompetition();
             _gameConsole.VisualizeCompetitionResults();
         }
         catch (Exception ex)
         {
             _console.WriteLine("Error. See logs for details.");
             _logWriter.LogError("Error in competition process", ex);
         }
     }
     else
     {
         _logWriter.LogErrorFormat("Cannot start competition, input data is null");
     }
 }
        private static InputCompetitionDataDTO ReadInputCompetitionData()
        {
            var console   = serviceContainer.GetInstance <IConsoleWrapper>();
            var inputData = new InputCompetitionDataDTO();

            var defaultArenaBottomLeftCoords = "0 0";

            inputData.ArenaBottomLeftCoords.TryParseInputCoords(defaultArenaBottomLeftCoords);

            console.Write(">>> Enter upper-right coordinates of the arena in the format [X Y] (e.g: 5 5): ");
            inputData.ArenaUpperRightCoords.TryParseInputCoords(console.ReadArenaUpperRightCoords());

            int  robotIx = 1;
            bool enterNextRobotToDeploy = true;

            while (enterNextRobotToDeploy)
            {
                var robotToDeploy = new InputRobotDTO {
                    Id = robotIx
                };

                console.WriteLine(">>> Enter robot # {0} configuration", robotIx);
                console.Write(">>> robot's position and orientation in the format [X Y Orientation:[N,S,E,W]] (e.g: 1 2 N): ");
                robotToDeploy.TryParseInputLocationAndHeadingDirection(console.ReadRobotLocationAndHeadingDirection());

                console.Write(">>> robot's battle moves in the format [M1M2...Mn, where Mn:[L,R,M]] (e.g: LMLMLM): ");
                robotToDeploy.TryParseInputBattleMoves(console.ReadRobotBattleMoves());

                console.Write("Enter next robot to deploy [Y/N]?: ");
                var proceed = console.ReadLine();
                enterNextRobotToDeploy = proceed != null && proceed.Equals("Y", StringComparison.InvariantCultureIgnoreCase);

                inputData.RobotsToDeploy.Add(robotToDeploy);
                robotIx++;
            }

            return(inputData);
        }