Esempio n. 1
0
        public void AddPlayer_PlayerDoesNotExist_Should_Add_Player()
        {
            var playerToAdd = new Player("test");
            this.engine.AddPlayer(playerToAdd);

            Assert.AreEqual(playerToAdd.Name, this.engine.Table.Players[0].Name);
        }
Esempio n. 2
0
        public void AddPlayer_PlayerDoesNotExist_Should_Return_True()
        {
            var playerToAdd = new Player("test");
            var result = this.engine.AddPlayer(playerToAdd);

            Assert.IsTrue(result);
        }
Esempio n. 3
0
        public void AddPlayer_PlayerExists_Should_Not_Add_Player_Again()
        {
            var playerToAdd = new Player("test");
            this.engine.AddPlayer(playerToAdd);
            this.engine.AddPlayer(playerToAdd);

            Assert.AreEqual(1, this.engine.Table.Players.Count());
        }
Esempio n. 4
0
        public void AddPlayer_PlayerExists_Should_Return_False()
        {
            var playerToAdd = new Player("test");
            this.engine.AddPlayer(playerToAdd);
            var result = this.engine.AddPlayer(playerToAdd);

            Assert.IsFalse(result);
        }
 internal static Player ToPlayerModel(this PlayerEntity playerEntity)
 {
     var player = new Player(playerEntity.Name)
     {
         Id = Guid.Parse(playerEntity.PlayerId),
         State = (Player.States) playerEntity.State,
         Cards = Util.DeSerialize<List<Card>>(playerEntity.Cards)
     };
     return player;
 }
Esempio n. 6
0
        public void ToPlayerModel_EmptyCards_Should_Return_PlayerModel_With_Empty_Cards()
        {
            var tableId = Guid.NewGuid();
            var player = new Player("Test");

            var playerEntity = player.ToPlayerEntity(tableId);
            var playerModel = playerEntity.ToPlayerModel();

            Assert.AreEqual(0, playerModel.Cards.Count());
        }
Esempio n. 7
0
        public void AssignSeatToPlayer_SeatNotOccupied_Player_Should_Be_Assigned_To_Seat()
        {
            var player = new Player("test");

            this.engine.AddPlayer(player);

            this.engine.AssignSeatToPlayer(1, player.Id);

            Assert.AreEqual(player.Id, this.engine.Table.Seats[0].PlayerId);
        }
Esempio n. 8
0
        public void JoingTable_SameNameAsExistingPlayer_Returns_ExistingPlayersGuid()
        {
            var expectedPlayer = new Player("RoboCop");
            var table = new Table("TableName", "TablePassword");
            table.Players.Add(expectedPlayer);
            var someTableGuid = Guid.NewGuid();
            this.repositoryMock.Setup(x => x.GetTableIdByTablePassword(It.IsAny<string>())).Returns(someTableGuid);
            this.repositoryMock.Setup(x => x.LoadTable(someTableGuid)).Returns(table);

            var playerGuid = this.engine.JoinTable("Some Password", expectedPlayer.Name);

            Assert.AreEqual(expectedPlayer.Id, playerGuid);
        }
Esempio n. 9
0
        public void ToPlayerEntity_Should_Return_PlayerEntity_With_Valid_Values()
        {
            var tableId = Guid.NewGuid();
            var player = new Player("Test");
            player.Cards.Add(new Card
            {
                Color = Card.Colors.Black,
                State = Card.States.Available,
                Suite = Card.Suites.Clubs,
                Value = 2
            });
            var result = player.ToPlayerEntity(tableId);

            Assert.IsNotNull(result);
            Assert.IsInstanceOfType(result, typeof(PlayerEntity));
            Assert.AreEqual(tableId.ToString(), result.PartitionKey);
            Assert.AreEqual(string.Format("Player-{0}", player.Id), result.RowKey);
            Assert.AreEqual(player.Id.ToString(), result.PlayerId);
            Assert.AreEqual(player.Name, result.Name);
            Assert.AreEqual((int)player.State, result.State);
            Assert.IsTrue(!string.IsNullOrEmpty(result.Cards));
        }
Esempio n. 10
0
        public void ToPlayerModel_Should_Return_PlayerModel_With_Valid_Values()
        {
            var tableId = Guid.NewGuid();
            var player = new Player("Test");
            player.Cards.Add(new Card
            {
                Color = Card.Colors.Black,
                State = Card.States.Available,
                Suite = Card.Suites.Clubs,
                Value = 2
            });
            var playerEntity = player.ToPlayerEntity(tableId);
            var playerModel = playerEntity.ToPlayerModel();

            Assert.IsNotNull(playerModel);
            Assert.IsInstanceOfType(playerModel, typeof(Player));
            Assert.AreEqual(player.Id, playerModel.Id);
            Assert.AreEqual(player.Name, playerModel.Name);
            Assert.AreEqual(player.Cards.Count(), playerModel.Cards.Count());
            Assert.AreEqual(player.Cards[0].Color, playerModel.Cards[0].Color);
            Assert.AreEqual(player.Cards[0].State, playerModel.Cards[0].State);
            Assert.AreEqual(player.Cards[0].Suite, playerModel.Cards[0].Suite);
            Assert.AreEqual(player.Cards[0].Value, playerModel.Cards[0].Value);
        }
Esempio n. 11
0
        public void AssignSeatToPlayer_SeatNotOccupied_Should_Return_True()
        {
            var player = new Player("test");

            this.engine.AddPlayer(player);

            var result = this.engine.AssignSeatToPlayer(1, player.Id);

            Assert.IsTrue(result);
        }
Esempio n. 12
0
        public Guid JoinTable(string tablePassword, string playerName)
        {
            var tableId = this.repository.GetTableIdByTablePassword(tablePassword);

            if (tableId.HasValue)
            {
                this.LoadTable(tableId.Value);
            }

            if (this.Table == null)
            {
                throw new TableDoesNotExistException();
            }

            Player player = null;

            if (this.Table.Players.Any(x => x.Name == playerName))
            {
                return this.Table.Players.Single(x => x.Name == playerName).Id;
            }
            else
            {
                player = new Player(playerName);
                this.AddPlayer(player);
                return player.Id;
            }
        }
Esempio n. 13
0
        public void RemovePlayer_PlayerInSeat_PlayerRemoved_From_Seat()
        {
            var playerToAdd = new Player("test");
            this.engine.AddPlayer(playerToAdd);
            this.engine.AssignSeatToPlayer(1, playerToAdd.Id);

            this.engine.RemovePlayer(playerToAdd.Id);

            Assert.AreEqual(null, this.engine.Table.Seats[0].PlayerId);
        }
Esempio n. 14
0
        public void RemovePlayer_PlayerExists_Should_Return_True()
        {
            var playerToAdd = new Player("test");
            this.engine.AddPlayer(playerToAdd);

            var result = this.engine.RemovePlayer(playerToAdd.Id);

            Assert.IsTrue(result);
        }
Esempio n. 15
0
        public void RemovePlayer_PlayerExists_Player_Is_Removed()
        {
            var playerToAdd = new Player("test");
            this.engine.AddPlayer(playerToAdd);

            this.engine.RemovePlayer(playerToAdd.Id);

            Assert.AreEqual(0, this.engine.Table.Players.Count());
        }
Esempio n. 16
0
        public void RemovePlayerFromSeat_By_SeatId_SeatOccupied_Should_Return_True()
        {
            var player = new Player("test");
            this.engine.AddPlayer(player);
            this.engine.AssignSeatToPlayer(1, player.Id);

            var result = this.engine.RemovePlayerFromSeat(1);

            Assert.IsTrue(result);
        }
Esempio n. 17
0
        public void RemovePlayerFromSeat_By_SeatId_SeatOccupied_PlayerID_Should_Be_Null()
        {
            var player = new Player("test");
            this.engine.AddPlayer(player);
            this.engine.AssignSeatToPlayer(1, player.Id);

            this.engine.RemovePlayerFromSeat(1);

            Assert.IsNull(this.engine.Table.Seats[0].PlayerId);
        }
Esempio n. 18
0
        public void RemovePlayerFromSeat_By_PlayerId_PlayerInASeat_Should_Set_Seats_PlayerId_To_Null()
        {
            var player = new Player("test");
            this.engine.AddPlayer(player);
            this.engine.AssignSeatToPlayer(1, player.Id);

            this.engine.RemovePlayerFromSeat(player.Id);

            Assert.IsNull(this.engine.Table.Seats[0].PlayerId);
        }
Esempio n. 19
0
        public bool AddPlayer(Player player)
        {
            bool playerAdded = false;
            try
            {
                if (this.Table.Players.All(x => x.Id != player.Id))
                {
                    this.Table.Players.Add(player);
                    this.repository.SavePlayer(this.Table.Id, player);
                    playerAdded = true;
                }
            }
            catch (Exception)
            {
                playerAdded = false;
            }

            return playerAdded;
        }
Esempio n. 20
0
        public void AssignSeatToPlayer_SeatOccupied_Should_Return_False()
        {
            var player1 = new Player("player1");
            var player2 = new Player("player2");

            this.engine.AddPlayer(player1);
            this.engine.AddPlayer(player2);
            this.engine.AssignSeatToPlayer(1, player1.Id);

            var result = this.engine.AssignSeatToPlayer(1, player2.Id);

            Assert.IsFalse(result);
        }
Esempio n. 21
0
        public void AssignSeatToPlayer__PlayerAlreadyInSeat_Should_Be_Moved_To_New_Seat()
        {
            var player = new Player("test");

            this.engine.AddPlayer(player);
            this.engine.AssignSeatToPlayer(1, player.Id);
            this.engine.AssignSeatToPlayer(2, player.Id);

            Assert.IsNull(this.engine.Table.Seats[0].PlayerId);
            Assert.AreEqual(player.Id, this.engine.Table.Seats[1].PlayerId);
        }