Пример #1
0
        public void AddNewPlayer_9thPlayer_ThrowsError()
        {
            var sessionKey = Guid.NewGuid();
            var eightPlayers = new List<PlayerEntity>();
            var order = new List<PlayerOrder>();
            for (int i = 0; i < 8; i++)
            {
                var player = new PlayerEntity();
                eightPlayers.Add(player);
                order.Add(new PlayerOrder() { SessionId = 1, Player = player, Value = i });
            }

            var fakeSession = new Session()
            {
                Key = sessionKey,
                ExpirationDate = DateTime.MaxValue,
                Players = eightPlayers,
                PlayerOrder = order,
            };

            var fakeContext = LogicalHelpers.GetSimpleSessionContext(fakeSession);
            var logic = new GameSetupLayer(fakeContext.Object);

            logic.AddPlayer(sessionKey, LogicalHelpers.GetValidPlayer());
        }
Пример #2
0
        public void GetNextPlayer_SinglePlayedSetPlayed_ReturnsFirstPlayer()
        {
            var sessionKey = Guid.NewGuid();
            var firstPlayer = new PlayerEntity()
            {
                Key = Guid.NewGuid(),
                Id = 1,
            };
            var secondPlayer = new PlayerEntity() { Key = Guid.NewGuid(), Id = 2 };
            var firstSet = new PlayedSet() { PlayedBy = firstPlayer, PlayedById = firstPlayer.Id };

            var fakeSession = new Session();
            fakeSession.Key = sessionKey;
            fakeSession.StartDate = DateTime.MinValue;
            fakeSession.ExpirationDate = DateTime.MaxValue;
            fakeSession.Players = new List<PlayerEntity>() { firstPlayer, secondPlayer };
            fakeSession.PlayedSet = new List<PlayedSet>() { firstSet };

            fakeSession.PlayerOrder = new List<PlayerOrder>() { new PlayerOrder() { Player = firstPlayer, Value = 0, PlayerId = firstPlayer.Id },
                new PlayerOrder{ Player = secondPlayer, Value = 1, PlayerId = secondPlayer.Id }
            };

            var fakeContext = LogicalHelpers.GetSimpleSessionContext(fakeSession);
            var logic = new GameplayLayer(fakeContext.Object, fakeSession.Key);

            Guid? nextPlayerKey = logic.GetNextPlayerKey();

            Assert.AreEqual(secondPlayer.Key, nextPlayerKey.Value);
        }
Пример #3
0
        public void CallBullshit_BullshitEventInserted()
        {
            var sessionKey = Guid.NewGuid();
            var fakeSession = new Session()
            {
                Key = sessionKey,
                StartDate = DateTime.Now,
                RoundNumber = 1,
                SetNumber = 1,
            };
            var player1 = new PlayerEntity() { Key = Guid.NewGuid() };
            LogicalHelpers.AttachPlayer(fakeSession, player1);
            LogicalHelpers.SetCurrentPlayer(fakeSession, player1);

            Guid player2Key = Guid.NewGuid();
            var player2 = new PlayerEntity() { Key = player2Key };
            LogicalHelpers.AttachPlayer(fakeSession, player2);
            LogicalHelpers.PlayCardSet(fakeSession, player1, new PlayedSet() { });

            var fakeContext = LogicalHelpers.GetSimpleSessionContext(fakeSession);
            fakeContext.Setup(x => x.Get<PlayerEntity>()).Returns(new[] { player1, player2 }.AsQueryable());
            var layer = new PlayerDetailsLayer(fakeContext.Object, sessionKey, player2Key);

            layer.CallBullshit();

            fakeContext.Verify(x => x.Add<BullshitEvent>(It.Is<BullshitEvent>(y => y.CalledBy == player2)), Times.Once());
            fakeContext.Verify(x => x.SaveChanges(), Times.Once());
            Assert.AreEqual(player2, fakeSession.CurrentPlayer);
        }
Пример #4
0
        public void GetNextPlayer_NewSession_ReturnsFirstPlayer()
        {
            var key = Guid.NewGuid();
            var firstPlayer = new PlayerEntity() { Key = Guid.NewGuid() };
            var fakeSession = new Session();
            fakeSession.Key = key;
            fakeSession.StartDate = DateTime.MinValue;
            fakeSession.ExpirationDate = DateTime.MaxValue;
            fakeSession.Players = new List<PlayerEntity>() { firstPlayer };

            var fakeContext = LogicalHelpers.GetSimpleSessionContext(fakeSession);
            var logic = new GameplayLayer(fakeContext.Object, fakeSession.Key);

            Guid? playerKey = logic.GetNextPlayerKey();

            Assert.AreEqual(firstPlayer.Key, playerKey.Value);
        }
Пример #5
0
        public void CallBullshit_FinishedGame_ThrowsException()
        {
            var sessionKey = Guid.NewGuid();
            var session = new Session()
            {
                Key = sessionKey,
                StartDate = DateTime.Now,
                FinishedDate = DateTime.Now,
            };

            Guid player1Key = Guid.NewGuid();
            PlayerEntity player1 = new PlayerEntity()
            {
                Key = player1Key,
            };

            LogicalHelpers.AttachPlayer(session, player1);
            var fakeContext = LogicalHelpers.GetSimpleSessionContext(session);
            var layer = new PlayerDetailsLayer(fakeContext.Object, sessionKey, player1Key);
            layer.CallBullshit();
        }
Пример #6
0
        internal static void AttachPlayer(Session session, PlayerEntity player)
        {
            if (session.Players == null)
            {
                session.Players = new List<PlayerEntity>() { };
            }
            session.Players.Add(player);
            if (session.PlayerSesssionHands == null)
            {
                session.PlayerSesssionHands = new Collection<PlayerSesssionHand>();
            }

            session.PlayerSesssionHands.Add(new PlayerSesssionHand()
            {
                Player = player,
                PlayerId = player.Id,
                Session = session,
                SessionId = session.Id,
                LastUpdated = DateTime.Now,
            });

            if (session.PlayerOrder == null)
            {
                session.PlayerOrder = new List<PlayerOrder>();
            }

            var order = new PlayerOrder()
            {
                Id = r.Next(),
                Value = session.PlayerOrder.Count,
                Player = player,
                PlayerId = player.Id,
                Session = session,
                SessionId = session.Id,
            };
            session.PlayerOrder.Add(order);
        }
Пример #7
0
        public void StartGame_NotEnoughPlayers_ThrowsException()
        {
            Guid sessionKey = Guid.NewGuid();
            var basicPlayer = new PlayerEntity() { Name = "Hello" };
            var fakeContext = LogicalHelpers.GetSimpleSessionContext(new Session()
            {
                Key = sessionKey,
                Players = new List<PlayerEntity>(),
            });

            GameSetupLayer layer = new GameSetupLayer(fakeContext.Object);

            layer.StartGame(sessionKey);
        }
Пример #8
0
        public void PlayCardSet_WaitingForBullshit_Fails()
        {
            var sessionKey = Guid.NewGuid();
            var session = new Session()
            {
                Key = sessionKey,
                StartDate = DateTime.Now,
            };

            var player1 = new PlayerEntity()
            {
                Key = Guid.NewGuid()
            };
            LogicalHelpers.AttachPlayer(session, player1);

            var player2 = new PlayerEntity()
            {
                Key = Guid.NewGuid(),
            };
            LogicalHelpers.AttachPlayer(session, player2);
            session.RoundNumber = 1;
            session.SetNumber = 1;

            LogicalHelpers.PlayCardSet(session, player1, new PlayedSet()
            {
                PresumedType = CardType.Club,
                PresumedTypeId = CardType.ClubId,
                PlayedHand = "H1",
            });
            LogicalHelpers.AddBullshit(session, new BullshitEvent());
            LogicalHelpers.SetCurrentPlayer(session, player2);
            var fakeContext = LogicalHelpers.GetSimpleSessionContext(session);
            var layer = new PlayerDetailsLayer(fakeContext.Object, sessionKey, player2.Key);

            layer.PlayCardSet(new PlayedSet()
            {
                PresumedType = CardType.Club,
                PresumedTypeId = CardType.ClubId,
                PlayedHand = "D1",
            });
        }
Пример #9
0
        public void PlayCardSet_CorrectPlayer_RemovesCardFromCurrentUser()
        {
            var sessionKey = Guid.NewGuid();
            var session = new Session()
            {
                Id = 1,
                Key = sessionKey,
                StartDate = DateTime.Now,
            };

            var player1 = new PlayerEntity()
            {
                Id = 1,
                Key = Guid.NewGuid()
            };
            LogicalHelpers.AttachPlayer(session, player1);

            var player2 = new PlayerEntity()
            {
                Id = 2,
                Key = Guid.NewGuid(),
            };
            LogicalHelpers.AttachPlayer(session, player2);
            session.RoundNumber = 1;
            session.SetNumber = 1;

            LogicalHelpers.PlayCardSet(session, player1, new PlayedSet()
            {
                PresumedType = CardType.Club,
                PresumedTypeId = CardType.ClubId,
                PlayedHand = "H1",
            });

            LogicalHelpers.SetCurrentPlayer(session, player2);
            var fakeContext = LogicalHelpers.GetSimpleSessionContext(session);
            var layer = new PlayerDetailsLayer(fakeContext.Object, sessionKey, player2.Key);
            var playerHand = new PlayerSesssionHand
            {
                SessionId = session.Id,
                PlayerId = player2.Id,
                CurrentHand = "D1",
            };
            fakeContext.Setup(x => x.Get<PlayerSesssionHand>()).Returns(new[] { playerHand }.AsQueryable());
            fakeContext.Setup(x => x.Get<PlayerEntity>()).Returns(new[] { player1, player2 }.AsQueryable());
            string playedHand = "D1";

            var hand = new PlayedSet()
            {
                PlayedHand = playedHand,
                PresumedTypeId = CardType.ClubId,
                PresumedType = CardType.Club
            };
            layer.PlayCardSet(hand);

            CollectionAssert.Contains((ICollection)session.PlayedSet, hand);
            fakeContext.Verify(x => x.SaveChanges(), Times.Once());
            Assert.IsTrue(String.IsNullOrEmpty(playerHand.CurrentHand));
        }
Пример #10
0
        public void IsMyTurn_YourTurn_Yes()
        {
            var sessionKey = Guid.NewGuid();
            var fakeContext = new Mock<IBullshitContext>();

            var session = new Session()
            {
                Key = sessionKey,
                StartDate = DateTime.Now,
                RoundNumber = 1,
                SetNumber = 1,
            };
            var player1 = new PlayerEntity() { Key = Guid.NewGuid() };
            LogicalHelpers.AttachPlayer(session, player1);

            var player2 = new PlayerEntity() { Key = Guid.NewGuid() };
            LogicalHelpers.AttachPlayer(session, player2);

            var player3 = new PlayerEntity() { Key = Guid.NewGuid() };
            LogicalHelpers.AttachPlayer(session, player3);

            LogicalHelpers.SetCurrentPlayer(session, player1);

            fakeContext.Setup(x => x.Get<Session>()).Returns(new List<Session>()
            {
                session
            }.AsQueryable());

            var layer = new PlayerDetailsLayer(fakeContext.Object, sessionKey, player1.Key);
            Assert.IsTrue(layer.IsMyTurn);
        }
Пример #11
0
        public void IsMyTurn_StartedGameNotYourTurn_No()
        {
            var sessionKey = Guid.NewGuid();
            var fakeContext = new Mock<IBullshitContext>();

            var session = new Session() { Key = sessionKey, StartDate = DateTime.Now };
            var player1 = new PlayerEntity() { Key = Guid.NewGuid() };
            LogicalHelpers.AttachPlayer(session, player1);
            var player2 = new PlayerEntity() { Key = Guid.NewGuid() };
            LogicalHelpers.AttachPlayer(session, player2);
            var player3 = new PlayerEntity() { Key = Guid.NewGuid() };
            LogicalHelpers.AttachPlayer(session, player3);
            session.CurrentPlayer = player1;

            fakeContext.Setup(x => x.Get<Session>()).Returns(new List<Session>()
            {
                session
            }.AsQueryable());

            var player2Layer = new PlayerDetailsLayer(fakeContext.Object, sessionKey, player2.Key);
            Assert.IsFalse(player2Layer.IsMyTurn);
            var player3Layer = new PlayerDetailsLayer(fakeContext.Object, sessionKey, player3.Key);
            Assert.IsFalse(player3Layer.IsMyTurn);
        }
Пример #12
0
 internal static void SetCurrentPlayer(Session session, PlayerEntity player)
 {
     session.CurrentPlayer = player;
     session.CurrentPlayerId = player.Id;
 }
Пример #13
0
        internal static void PlayCardSet(Session session, PlayerEntity player1, PlayedSet playedSet)
        {
            session.SetNumber++;
            playedSet.PlayedBy = player1;
            playedSet.PlayedById = player1.Id;
            playedSet.PlayedOn = DateTime.Now;

            if (session.PlayedSet == null)
            {
                session.PlayedSet = new List<PlayedSet>();
            }

            session.PlayedSet.Add(playedSet);
        }