Ejemplo n.º 1
0
        public APIGatewayProxyResponse Handle(APIGatewayProxyRequest request, ILambdaContext context)
        {
            return(new Responder().Respond(response =>
            {
                try
                {
                    var chameleonGame = ChameleonGame.Create();
                    var person = new RoomJoiner(chameleonGame)
                                 .Join(request.Body);

                    response.StatusCode = 200;
                    response.Body = JsonConvert.SerializeObject(person);
                }
                catch (PersonNameMustBeSpecifiedException e)
                {
                    response.StatusCode = 400;
                    response.Body = e.Message;
                }
                catch (RoomCodeMustBeValidException e)
                {
                    response.StatusCode = 400;
                    response.Body = e.Message;
                }
                catch (PersonNameNotUniqueException e)
                {
                    response.StatusCode = 409;
                    response.Body = e.Message;
                }
            }));
        }
Ejemplo n.º 2
0
 public APIGatewayProxyResponse Handle(APIGatewayProxyRequest request, ILambdaContext context)
 {
     return(new Responder().Respond(response =>
     {
         ChameleonGame.Create().LeaveRoom(
             request.GetChameleonRoomCode(),
             request.GetChameleonPersonIdHeader());
         response.StatusCode = 204;
         response.Body = "";
     }));
 }
Ejemplo n.º 3
0
 public APIGatewayProxyResponse Handle(APIGatewayProxyRequest request, ILambdaContext context)
 {
     return(new Responder().Respond(response =>
     {
         var status = ChameleonGame.Create().GetRoomStatus(
             request.GetChameleonRoomCode(),
             request.GetChameleonPersonIdHeader());
         response.StatusCode = 200;
         response.Body = JsonConvert.SerializeObject(status);
         response.Headers.Add("Content-Type", "application/json");
     }));
 }
Ejemplo n.º 4
0
        public void TestCanJoinExistingRoom()
        {
            const string roomCode = "BBBB";

            var roomStore     = new Mock <IRoomStore>();
            var chameleonGame = ChameleonGame.Create(roomStore.Object);

            roomStore.Setup(x => x.DoesRoomExist(roomCode)).Returns(true);

            chameleonGame.JoinRoom(roomCode, "Jacob");

            roomStore.Verify(x => x.CreatePersonInRoom(roomCode, "Jacob"));
        }
Ejemplo n.º 5
0
        public APIGatewayProxyResponse Handle(APIGatewayProxyRequest request, ILambdaContext context)
        {
            return(new Responder().Respond(response =>
            {
                var body = JObject.Parse(request.Body);
                var voteToken = body["Vote"];

                ChameleonGame.Create().Vote(
                    request.GetChameleonRoomCode(),
                    request.GetChameleonPersonIdHeader(),
                    voteToken.ToString());

                response.StatusCode = 204;
                response.Body = "";
            }));
        }
Ejemplo n.º 6
0
        public void CanPlayGame()
        {
            var chameleonGame = ChameleonGame.Create(RoomStore.Create(new InMemoryDynamoTable()));

            // Creating and joining the room
            var personAndRoom = chameleonGame.CreateRoom("Anita");
            var roomCode      = personAndRoom.RoomCode;

            var anita = personAndRoom.PersonId;
            var jacob = chameleonGame.JoinRoom(roomCode, "Jacob").PersonId;
            var paul  = chameleonGame.JoinRoom(roomCode, "Paul").PersonId;

            // Getting the status
            var status = chameleonGame.GetRoomStatus(roomCode, anita);

            Assert.That(status.Name, Is.EqualTo("Anita"));
            Assert.That(status.PeopleCount, Is.EqualTo(3));
            Assert.That(status.State, Is.EqualTo(RoomState.PreGame.ToString()));
            Assert.That(status.Character, Is.Null);
            Assert.That(status.FirstPersonName, Is.Null);

            // Starting a game
            chameleonGame.StartGame(roomCode, jacob);

            var inGameStatus = chameleonGame.GetRoomStatus(roomCode, paul);

            Assert.That(inGameStatus.State, Is.EqualTo(RoomState.InGame.ToString()));
            Assert.That(inGameStatus.Character, Is.Not.Null);
            Assert.That(inGameStatus.FirstPersonName, Is.AnyOf("Anita", "Jacob", "Paul"));

            // Leaving a room
            chameleonGame.LeaveRoom(roomCode, paul);

            var afterLeavingStatus = chameleonGame.GetRoomStatus(roomCode, anita);

            Assert.That(afterLeavingStatus.PeopleCount, Is.EqualTo(2));

            // A new player joining a room with an existing game
            var anna = chameleonGame.JoinRoom(roomCode, "Anna").PersonId;

            var newPlayerStatus = chameleonGame.GetRoomStatus(roomCode, anna);

            Assert.That(newPlayerStatus.State, Is.EqualTo(RoomState.PreGame.ToString()));
            Assert.That(newPlayerStatus.Character, Is.Null);
            Assert.That(newPlayerStatus.FirstPersonName, Is.Null);
        }
Ejemplo n.º 7
0
        public void TestCanCreateRoom()
        {
            const string roomCode = "AAAA";

            var roomStore     = new Mock <IRoomStore>();
            var chameleonGame = ChameleonGame.Create(roomStore.Object);

            roomStore.Setup(x => x.CreateRoom())
            .Returns(new Room {
                RoomCode = roomCode
            });

            chameleonGame.CreateRoom("Jacob");

            roomStore.Verify(x => x.CreateRoom());
            roomStore.Verify(x => x.CreatePersonInRoom(roomCode, "Jacob"));
        }
Ejemplo n.º 8
0
        public void TestCannotJoinNonExistingRoom()
        {
            const string roomCode = "CCCC";

            var roomStore     = new Mock <IRoomStore>();
            var chameleonGame = ChameleonGame.Create(roomStore.Object);

            roomStore.Setup(x => x.DoesRoomExist(roomCode)).Returns(false);

            Assert.Throws <RoomDoesNotExistException>(() =>
            {
                chameleonGame.JoinRoom(roomCode, "Jacob");
            });

            roomStore.Verify(
                x => x.CreatePersonInRoom(roomCode, It.IsAny <string>()),
                Times.Never);
        }
Ejemplo n.º 9
0
        public void TestCanStartGame()
        {
            const string roomCode = "AAAA";

            var mockRoomStore = new Mock <IRoomStore>();
            var chameleonGame = ChameleonGame.Create(mockRoomStore.Object);

            var room = new Room();

            room.AddPerson("person-1", "jacob");
            room.AddPerson("person-2", "anita");
            room.AddPerson("person-3", "robin");

            mockRoomStore.Setup(x => x.GetRoom(roomCode)).Returns(room);

            chameleonGame.StartGame(roomCode, "person-1");

            mockRoomStore.Verify(x => x.StartGame(
                                     roomCode,
                                     It.IsAny <string>(),
                                     It.Is <ISet <string> >(y => y.Count() == 1),
                                     It.Is <string>(y => y.StartsWith("person-"))));
        }