예제 #1
0
        public void Start_RequestsMoveFromSnakeBotOnMapUpdate()
        {
            var socket = new StubWebSocket(WebSocketState.Open);

            socket.IncomingJson.Enqueue(new JObject {
                { "type", MessageType.PlayerRegistered }
            });
            socket.IncomingJson.Enqueue(new JObject {
                { "type", MessageType.GameStarting }
            });
            socket.IncomingJson.Enqueue(new JObject
            {
                { "type", MessageType.MapUpdated },
                { "map", _sampleMapJson }
            });

            bool receivedCall = false;
            var  bot          = new StubSnakeBot(map => { receivedCall = true; return(Direction.Down); });

            var client = new SnakeClient(socket);

            client.Start(bot);

            Assert.True(receivedCall);
        }
예제 #2
0
        public void Start_RequestsMoveFromBotEventIfNoGameStartingMessageHasBeenReceived()
        {
            // Not an actual requirement, but this test is here for completness.
            var socket = new StubWebSocket(WebSocketState.Open);

            socket.IncomingJson.Enqueue(JObject.Parse(TestResources.GetResourceText("map-update.json", Encoding.UTF8)));

            bool receivedCall = false;
            var  bot          = new StubSnakeBot(map => { receivedCall = true; return(Direction.Down); });

            var client = new SnakeClient(socket);

            client.Start(bot);

            Assert.True(receivedCall);
        }
예제 #3
0
        public void Start_SendsRegisterPlayerRequest()
        {
            var socket = new StubWebSocket(WebSocketState.Open);

            socket.IncomingJson.Enqueue(new JObject {
                { "type", MessageType.PlayerRegistered }
            });
            var client = new SnakeClient(socket, Mock.Of <IGameObserver>());

            var bot = new StubSnakeBot();

            client.Start(bot, true);

            var registerMessage = socket.OutgoingJson[0];

            Assert.Equal("se.cygni.snake.api.request.RegisterPlayer", (string)registerMessage["type"]);
            Assert.Equal(bot.Name, (string)registerMessage["playerName"]);
        }