Пример #1
0
        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);
        }
Пример #2
0
        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);
        }
Пример #3
0
        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"));
        }
Пример #4
0
 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);
 }
Пример #5
0
        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"));
        }
Пример #6
0
        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);
        }
Пример #7
0
        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);
        }
Пример #8
0
        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"));
        }
Пример #9
0
        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);
        }
Пример #10
0
        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);
        }
Пример #11
0
        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);
        }