public void Not_Throw_Exception_When_Provided_With_Recievers() { var mockRover = new Mock <IRover>(); var mockLandingSurface = new Mock <ILandingSurface>(); var landingSurfaceSizeCommand = new RoverMoveCommand(null); Assert.DoesNotThrow(() => landingSurfaceSizeCommand.SetReceiver(mockRover.Object, mockLandingSurface.Object)); }
public void Expose_List_Of_Movements() { var expectedMovements = new List <Movement> { Movement.SpinLeft, Movement.SpinRight }; var roverMoveCommand = new RoverMoveCommand(expectedMovements); Assert.AreEqual(expectedMovements, roverMoveCommand.Movements); }
public void Call_Rover_Move_When_Command_Executed() { var expectedMovements = new List <Movement> { Movement.SpinLeft, Movement.SpinRight }; var mockRover = new Mock <IRover>(); var mockLandingSurface = new Mock <ILandingSurface>(); var roverMoveCommand = new RoverMoveCommand(expectedMovements); roverMoveCommand.SetReceiver(mockRover.Object, mockLandingSurface.Object); roverMoveCommand.Execute(); mockRover.Verify(x => x.Move(expectedMovements, mockLandingSurface.Object), Times.Once()); }
public void MoveRoverExpectValidPositionOrThrows(string deployRoverCommandText, string moveRoverCommandText, string expectedPositionText) { ICommand <Rover> roverDeployCommand = new RoverDeployCommand(Plateau); var deployedRover = roverDeployCommand.Execute(deployRoverCommandText); ICommand <Rover> roverMoveCommand = new RoverMoveCommand(deployedRover, Plateau); var regexMoveCommandPattern = new Regex("^[LRM]+$"); if (regexMoveCommandPattern.IsMatch(moveRoverCommandText)) { var splittedPosition = expectedPositionText.Split(' '); int.TryParse(splittedPosition[0], out var expectedRoverXLocation); int.TryParse(splittedPosition[1], out var expectedRoverYLocation); var expectedRoverDirection = EnumHelper.GetValueFromDescription <DirectionType>(splittedPosition[2]); var expectedPosition = new Block { X = expectedRoverXLocation, Y = expectedRoverYLocation }; if (Plateau.ContainsKey(expectedPosition) && Plateau[expectedPosition] == null) { var movedRover = roverMoveCommand.Execute(moveRoverCommandText); Assert.AreSame(deployedRover, movedRover); var actualPosition = Plateau.GetRoverLocation(movedRover); Assert.AreEqual(expectedRoverXLocation, actualPosition.X); Assert.AreEqual(expectedRoverYLocation, actualPosition.Y); Assert.AreEqual(expectedRoverDirection, movedRover.Direction); } else { var ex = Assert.Throws <ArgumentException>(() => roverMoveCommand.Execute(moveRoverCommandText)); Assert.AreEqual($"Direction of {expectedRoverDirection} at order {deployedRover.Order} rover's move command is not valid!", ex.Message); } } else { var ex = Assert.Throws <ArgumentException>(() => roverMoveCommand.Execute(moveRoverCommandText)); Assert.AreEqual($"Invalid character(s) in \"{moveRoverCommandText}\" text for move command.", ex.Message); } }
public void Return_RoverMoveCommand_Type_When_Get_Command_Type_Called() { var roverMoveCommand = new RoverMoveCommand(null); Assert.AreEqual(roverMoveCommand.GetCommandType(), CommandType.RoverMoveCommand); }