Beispiel #1
0
        static void Main(string[] args)
        {
            var service = new RobotService(new SignalRAdapter());

            service.Run();
            Console.Read();
        }
        public void TestGetRobotWithNoRobotThrowsException()
        {
            var boardService = new BoardService(new BoardPositionConverter(), new MockPositionValidator());
            var robotService = new RobotService(boardService, new PositionValidator());

            boardService.CreateNewBoard("test", 5, 5);
            Assert.Throws <RobotPlacedException>(() => robotService.GetRobot("test"));
        }
        public void TestRobotExistsCheckExpectFalse()
        {
            var boardService = new BoardService(new BoardPositionConverter(), new MockPositionValidator());
            var robotService = new RobotService(boardService, new PositionValidator());

            boardService.CreateNewBoard("test", 5, 5);
            Assert.False(robotService.RobotExists("test"));
        }
Beispiel #4
0
 public ChatbotController(BaiduSession session, ChatService chatService, RobotService robotService, CrmService crmService, ChatLogCache sessionCache)
 {
     _baiduSession = session;
     _chatService  = chatService;
     _robotService = robotService;
     _sessionCache = sessionCache;
     _crmService   = crmService;
 }
        public RobotServiceTests()
        {
            var client   = new Mock <IRabbitHandler>();
            var settings = new Mock <IOptions <AppSettings> >();

            m_repositoryMock = new Mock <IRobotRepository>();
            m_explorersTeamRepositoryMock = new Mock <IExplorersTeamRepository>();
            m_robotService = new RobotService(new Mock <ILogger <RobotService> >().Object, m_repositoryMock.Object, m_explorersTeamRepositoryMock.Object, client.Object, settings.Object);
        }
        public void TestRobotMoveOffEdgeExpectFalse()
        {
            var boardService = new BoardService(new BoardPositionConverter(), new MockPositionValidator());
            var robotService = new RobotService(boardService, new PositionValidator());

            boardService.CreateNewBoard("test", 5, 5);
            robotService.PlaceRobot("test", new Vector2(1, 4), Direction.NORTH);
            Assert.Throws <RobotOutOfBoundsException>(() => robotService.MoveForward("test"));
        }
        public void TestRobotExistsCheckExpectTrue()
        {
            var boardService = new BoardService(new BoardPositionConverter(), new MockPositionValidator());
            var robotService = new RobotService(boardService, new PositionValidator());

            boardService.CreateNewBoard("test", 5, 5);
            robotService.PlaceRobot("test", new Vector2(1, 4), Direction.NORTH);
            Assert.True(robotService.RobotExists("test"));
        }
Beispiel #8
0
        public void CalculateCoordinatesTouched_W()
        {
            List <string> coordinateList = new List <string>();
            RobotService  service        = new RobotService();

            coordinateList = service.CalculateCoordinatesTouched("0 0", "W", 10, out string stoppedLocation);
            CollectionAssert.Contains(coordinateList, "0 -10");
            Assert.IsTrue(coordinateList.Count == 10);
        }
Beispiel #9
0
 public RobotServiceTest()
 {
     _commandFactory = Substitute.For <ICommandFactory>();
     _robot          = new Robot {
         XPosition = 1, YPosition = 1, Facing = Direction.NORTH, Placed = false
     };
     _xOriginalPosition = _robot.XPosition;
     _yOriginalPosition = _robot.YPosition;
     _originalFacing    = _robot.Facing;
     _subject           = new RobotService(_robot, _commandFactory);
 }
        public void ReportAfterPlaceExpectSuccess()
        {
            var boardService = new BoardService(new BoardPositionConverter(), new MockPositionValidator());
            var robotService = new RobotService(boardService, new PositionValidator());

            boardService.CreateNewBoard("test", 5, 5);
            robotService.PlaceRobot("test", new Vector2(1, 1), Direction.NORTH);
            var robotReport = robotService.ReportPosition("test");

            Assert.Equal("X: 1 Y: 1 F: NORTH", robotReport);
        }
        public void Movement_InvalidPlaceCommand_ThrowEx()
        {
            //arrange
            var sut = new RobotService();

            //act
            Action act = () => sut.Compute("NO_COMMAND 1,2,EAST");

            //assert
            act.ShouldThrow <Exception>();
        }
        public void TestGetRobotWithPlacedRobot()
        {
            var boardService = new BoardService(new BoardPositionConverter(), new MockPositionValidator());
            var robotService = new RobotService(boardService, new PositionValidator());

            boardService.CreateNewBoard("test", 5, 5);
            robotService.PlaceRobot("test", new Vector2(1, 1), Direction.NORTH);
            var robot = robotService.GetRobot("test");

            Assert.NotNull(robot);
        }
        public void RotateRobotRightExpectSuccess()
        {
            var boardService = new BoardService(new BoardPositionConverter(), new MockPositionValidator());
            var robotService = new RobotService(boardService, new PositionValidator());

            boardService.CreateNewBoard("test", 5, 5);
            robotService.PlaceRobot("test", new Vector2(1, 1), Direction.NORTH);
            robotService.Rotate("test", RotateDirection.RIGHT);
            var robot = robotService.GetRobot("test");

            Assert.Equal(Direction.EAST, robot.Direction);
        }
Beispiel #14
0
        static void Main(string[] args)
        {
            Console.WriteLine("Hello World!");

            RobotService robotService = new RobotService("BB", 8);

            RobotManager robotManager = new RobotManager(robotService);

            robotManager.StartRobot();
            robotService.Run();
            robotManager.StartRobot();
        }
        public void Movement_InvalidMovementCommand_ThrowEx()
        {
            //arrange
            var sut = new RobotService();

            sut.Compute("PLACE 1,2,NORTH");

            //act
            Action act = () => sut.Compute("STAY");

            //assert
            act.ShouldThrow <Exception>();
        }
        public void Movement_InvalidInitialDirectionCommand_ThrowEx()
        {
            //arrange
            var sut = new RobotService();

            sut.Compute("PLACE 1,2,DEEP");

            //act
            Action act = () => sut.Movement();

            //assert
            act.ShouldThrow <Exception>();
        }
        public void Movement_InvalidNumberY_ThrowEx()
        {
            //arrange
            var sut = new RobotService();

            sut.Compute("PLACE 2,X,EAST");

            //act
            Action act = () => sut.Movement();

            //assert
            act.ShouldThrow <Exception>();
        }
Beispiel #18
0
        public ServiceAccess(Current.GetTicket getTicket, Current.GetUrl getUrl)
        {
            var repos = new Repos(getUrl);

            BaseMove = new BaseMoveSaverService(this, repos);

            Safe   = new SafeService(this, repos);
            Admin  = new AdminService(this, repos);
            Money  = new MoneyService(this, repos);
            Robot  = new RobotService(this, repos);
            Report = new ReportService(this, repos);

            Current = new Current(Safe, getTicket);
        }
Beispiel #19
0
        public void move_robot_from_12n_goes_to_13n()
        {
            var coord = new Tuple<int, int>(5, 5);
            ITable table = new Table(coord);

            var robotState = new RobotState(1, 2, 'N');
             IRobotService robotService = new RobotService(table, robotState);

            string command = "LMLMLMLMM";
            var pos = robotService.Proceed(command);
            var expectedState = new RobotState(1, 3, 'N');
            Assert.AreEqual(expectedState.RobotCoordinate, pos.RobotCoordinate);
            Assert.AreEqual(expectedState.Heading, pos.Heading);
        }
        public void TestRobotMoveFromDirectionExpectSuccess(Direction startingDirection, int expectedX, int expectedY)
        {
            var boardService = new BoardService(new BoardPositionConverter(), new MockPositionValidator());
            var robotService = new RobotService(boardService, new PositionValidator());

            boardService.CreateNewBoard("test", 5, 5);
            robotService.PlaceRobot("test", new Vector2(1, 1), startingDirection);
            var moveResult = robotService.MoveForward("test");

            Assert.True(moveResult);
            var newRobotPosition = robotService.GetRobot("test");

            Assert.Equal(new Vector2(expectedX, expectedY), newRobotPosition.Position);
        }
Beispiel #21
0
        public void move_robot_from_33e_goes_to_51e()
        {
            var coord = new Tuple<int, int>(5, 5);
            ITable table = new Table(coord);

            var robotState = new RobotState(3, 3, 'e');

             IRobotService robotService = new RobotService(table, robotState);

            string command = "MMRMMRMRRM";
            var pos = robotService.Proceed(command);
            var expectedState = new RobotState(5, 1, 'E');
            Assert.AreEqual(expectedState.RobotCoordinate, pos.RobotCoordinate);
            Assert.AreEqual(expectedState.Heading, pos.Heading);
        }
Beispiel #22
0
        public void ExecuteCommands_Test_Positive()
        {
            string startLocation = "0 0";
            var    commands      = new List <string>
            {
                "E 5",
                "W 5",
                "N 5",
                "S 5"
            };
            var service       = new RobotService();
            int spacesCleaned = service.ExecuteCommands(commands, startLocation);

            Assert.AreEqual(11, spacesCleaned);
        }
Beispiel #23
0
        public void ExecuteCommands_Test_SemiStressTest()
        {
            string startLocation = "10 15";
            var    commands      = new List <string>
            {
                "E 100000",
                "W 100000",
                "N 100000",
                "S 100000"
            };
            var service       = new RobotService();
            int spacesCleaned = service.ExecuteCommands(commands, startLocation);

            Assert.AreEqual(200001, spacesCleaned);
        }
        public void Movement_ValidMoveResultCommand1_ResultValid()
        {
            //arrange
            var sut = new RobotService();

            sut.Compute("PLACE 1,1,NORTH");
            sut.Compute("MOVE");
            sut.Compute("MOVE");

            //act
            var result = sut.Movement();

            //assert
            Assert.AreEqual(result.AxisX, 1);
            Assert.AreEqual(result.AxisY, 3);
            Assert.AreEqual(result.Facing, "NORTH");
        }
        public void Movement_ValidMoveResultCommand3_ResultValid()
        {
            //arrange
            var sut = new RobotService();

            sut.Compute("PLACE 1,2,EAST");
            sut.Compute("MOVE");
            sut.Compute("MOVE");
            sut.Compute("LEFT");
            sut.Compute("LEFT");
            sut.Compute("MOVE");

            //act
            var result = sut.Movement();

            //assert
            Assert.AreEqual(result.AxisX, 2);
            Assert.AreEqual(result.AxisY, 2);
            Assert.AreEqual(result.Facing, "WEST");
        }
Beispiel #26
0
        public void turn_robot_to_left_from_00n_goes_to_00w()
        {
            var coord = new Tuple<int, int>(5, 5);
            ITable table = new Table(coord);

            var robotState = new RobotState(0, 0, 'N');
             IRobotService robotService = new RobotService(table, robotState);

            string command = "L";
            var pos = robotService.Proceed(command);
            var expectedState = new RobotState(0, 0, 'W');
            Assert.AreEqual(expectedState.RobotCoordinate, pos.RobotCoordinate);
            Assert.AreEqual(expectedState.Heading, pos.Heading);
        }
Beispiel #27
0
        public void move_robot_to_out_of_boundries_throws_exception()
        {
            var coord = new Tuple<int, int>(5, 5);
            ITable table = new Table(coord);

            var robotState = new RobotState(4, 5, 'E');

             IRobotService robotService = new RobotService(table, robotState);

            string command = "MML";
            var ex = Assert.Throws<InvalidOperationException>(() => robotService.Proceed(command));
            Assert.That(ex.Message, Is.EqualTo("Out of boundaries"));
        }
Beispiel #28
0
        public void move_robot_with_invalid_command_throws_exception()
        {
            var coord = new Tuple<int, int>(5, 5);
            ITable table = new Table(coord);

            var robotState = new RobotState(3, 3, 'E');

             IRobotService robotService = new RobotService(table, robotState);

            string command = "ABCD1234";
            var pos = robotService.Proceed(command);
            var expectedState = new RobotState(3, 3, 'E');
            Assert.AreEqual(expectedState.RobotCoordinate, pos.RobotCoordinate);
            Assert.AreEqual(expectedState.Heading, pos.Heading);
        }
Beispiel #29
0
 public Factory(RobotService robotService, PartsService partsService)
 {
     _robotService = new RobotService();
     _partsService = new PartsService();
     _carService   = new CarService();
 }
Beispiel #30
0
 public void Setup()
 {
     robotService = new RobotService();
 }
Beispiel #31
0
 public RobotController()
 {
     _robotService = new RobotService();
     _shaService   = new ShaService();
 }
Beispiel #32
0
 public RobotServiceClient(RobotService.RobotServiceClient client)
 {
     this.client = client;
 }
Beispiel #33
0
        private void TimeRun(BackgroundWorker worker)
        {
            if (worker.CancellationPending)
            {
                return;
            }
            var robot = Global.robot;

            if (robot == null)
            {
                worker.ReportProgress(1, "noRobot");
            }
            if (robot.State == 0)
            {
                worker.ReportProgress(2, "processing");
                string loginUrl = protocol.CheckLogin(robot.UUID);
                worker.ReportProgress(3, "processed");
                if (loginUrl == "408")
                {
                    //超时需要重新生成二维码
                }
                else if (loginUrl == "200")
                {
                    //已扫描待确认
                }
                else
                {
                    CookieResult cookieResult = protocol.GetCookie(loginUrl);
                    robot.CookieStr  = cookieResult.CookieStr;
                    robot.Cookie     = cookieResult.wechatCookie;
                    robot.SyncCookie = cookieResult.SyncCookie;

                    InitSyncResult initSyncResult = protocol.Init(robot.Cookie, robot.CookieStr);
                    robot.Uin = initSyncResult.Uin;

                    RobotService service = new RobotService();
                    int          robotId = service.IsRobot(robot.Uin);
                    if (robotId > 0)
                    {
                        robot.Id         = robotId;
                        robot.SyncKey    = initSyncResult.SyncKey;
                        robot.SynckeyStr = initSyncResult.SynckeyStr;
                        robot.UserName   = initSyncResult.UserName;
                        robot.NickName   = initSyncResult.Nickname;
                        protocol.StatusNotify(robot.Cookie, robot.CookieStr, robot.UserName);
                        robot.State   = 1;
                        robot.Contact = protocol.GetContact(robot.Cookie, robot.CookieStr).MemberList.ToList();
                        Global.robot  = robot;
                    }
                    else
                    {
                        loginUrl = "noRobot";
                    }
                }
                worker.ReportProgress(1, loginUrl);
            }
            else
            {
                worker.ReportProgress(1, "1");
            }
        }
Beispiel #34
0
 public RobotHub(RobotService service)
 {
     _service = service;
     _service.CallerResolver = () => Clients.Caller;
 }