public void CreateTurtle_ReturnNotNull() { var boardServiceStub = new Mock <IBoardService>(); var coordinateServiceStub = new Mock <ICoordinateService>(); var turtleService = new TurtleService(boardServiceStub.Object, coordinateServiceStub.Object); var turtle = turtleService.Create(new Coordinate(), Orientation.East); Assert.NotNull(turtle); }
public void CreateTurtle_ReturnOrientation() { var boardServiceStub = new Mock <IBoardService>(); var coordinateServiceStub = new Mock <ICoordinateService>(); var turtleService = new TurtleService(boardServiceStub.Object, coordinateServiceStub.Object); var turtle = turtleService.Create(new Coordinate(), Orientation.East); var result = turtle.Orientation; Assert.Equal(Orientation.East, result); }
public void CreateTurtle_EmptyBoard_ThrowsNullException() { var boardServiceStub = new Mock <IBoardService>(); boardServiceStub.Setup(z => z.PositionInRange(It.IsAny <int>(), It.IsAny <int>())).Returns(true); var coordinateServiceStub = new Mock <ICoordinateService>(); var turtleService = new TurtleService(boardServiceStub.Object, coordinateServiceStub.Object); Assert.Throws <NullReferenceException>(() => turtleService.CreateTurtle("0 0 N")); }
public TurtleServiceTests() { _turtleRepositoryMock = new Mock <ITurtleRepository>(MockBehavior.Strict); _validatorMock = new Mock <TurtleValidator>(MockBehavior.Strict); _diFactoryMock = new Mock <IDIFactory>(MockBehavior.Strict); _instance = new TurtleService( _turtleRepositoryMock.Object, _validatorMock.Object, _diFactoryMock.Object); }
public void CreateTurtle_InvalidPosition_ThrowsException() { var boardServiceStub = new Mock <IBoardService>(); boardServiceStub.Setup(z => z.PositionInRange(It.IsAny <int>(), It.IsAny <int>())).Returns(true); boardServiceStub.Setup(z => z.ValidPosition(It.IsAny <Coordinate>(), It.IsAny <string>())).Returns(new Exception()); var coordinateServiceStub = new Mock <ICoordinateService>(); var turtleService = new TurtleService(boardServiceStub.Object, coordinateServiceStub.Object); Assert.Throws <Exception>(() => turtleService.CreateTurtle("1 1 N")); }
public void TurnRight_ReturnUpdatedOrientation(Orientation startingOrientation, Orientation expectedOrientation) { var boardServiceStub = new Mock <IBoardService>(); var coordinateServiceStub = new Mock <ICoordinateService>(); var turtleService = new TurtleService(boardServiceStub.Object, coordinateServiceStub.Object); var turtle = turtleService.Create(new Coordinate(), startingOrientation); turtleService.Move("R"); var result = turtle.Orientation; Assert.Equal(expectedOrientation, result); }
public void CreateTurtle_ReturnCoordinateY() { var boardServiceStub = new Mock <IBoardService>(); var coordinateServiceStub = new Mock <ICoordinateService>(); var turtleService = new TurtleService(boardServiceStub.Object, coordinateServiceStub.Object); var turtle = turtleService.Create(new Coordinate { X = 0, Y = 0 }, Orientation.East); var result = turtle.Position.Y; Assert.Equal(0, result); }
public void Move_UpdateStatus_ReturnInvalidOperationException(int x, int y, Orientation direction) { var boardServiceStub = new Mock <IBoardService>(); boardServiceStub.Setup(z => z.PositionInRange(It.IsAny <int>(), It.IsAny <int>())).Returns(false); var coordinateServiceStub = new Mock <ICoordinateService>(); var turtleService = new TurtleService(boardServiceStub.Object, coordinateServiceStub.Object); turtleService.Create(new Coordinate { X = x, Y = y }, direction); Assert.Throws <InvalidOperationException>(() => turtleService.Move("M")); }
public void GetStatus_ReturnsStatus(int x, int y, Orientation direction) { var boardServiceStub = new Mock <IBoardService>(); boardServiceStub.Setup(z => z.PositionInRange(It.IsAny <int>(), It.IsAny <int>())).Returns(true); var coordinateServiceStub = new Mock <ICoordinateService>(); var turtleService = new TurtleService(boardServiceStub.Object, coordinateServiceStub.Object); turtleService.Create(new Coordinate { X = x, Y = y }, direction); var result = turtleService.GetStatus(); Assert.Equal("Still in Danger", result); }
public void Move_UpdateStatus_ReturnStillInDanger(int x, int y, Orientation direction) { var boardServiceStub = new Mock <IBoardService>(); boardServiceStub.Setup(z => z.PositionInRange(It.IsAny <int>(), It.IsAny <int>())).Returns(true); var coordinateServiceStub = new Mock <ICoordinateService>(); var turtleService = new TurtleService(boardServiceStub.Object, coordinateServiceStub.Object); var turtle = turtleService.Create(new Coordinate { X = x, Y = y }, direction); turtleService.Move("M"); var result = turtle.Status; Assert.Equal(TurtleStatus.InDanger, result); }
public void Move_MoveForward_ReturnUpdatedPositionX(int x, int y, Orientation direction, int expectedResult) { var boardServiceStub = new Mock <IBoardService>(); boardServiceStub.Setup(z => z.PositionInRange(It.IsAny <int>(), It.IsAny <int>())).Returns(true); var coordinateServiceStub = new Mock <ICoordinateService>(); var turtleService = new TurtleService(boardServiceStub.Object, coordinateServiceStub.Object); var turtle = turtleService.Create(new Coordinate { X = x, Y = y }, direction); turtleService.Move("M"); var result = turtle.Position.X; Assert.Equal(expectedResult, result); }