示例#1
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);
        }
示例#2
0
        public void CallBullshit_NoPlayedSet_Fails()
        {
            var sessionKey = Guid.NewGuid();
            var fakeContext = new Mock<IBullshitContext>();

            var layer = new PlayerDetailsLayer(fakeContext.Object, sessionKey, Guid.Empty);
            layer.CallBullshit();
        }
示例#3
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();
        }
示例#4
0
        public void CanCallBullshit_AnotherPlayer_ReturnsTrue()
        {
            var session = LogicalHelpers.OngoingGame;
            var fakeContext = LogicalHelpers.GetSimpleSessionContext(session);
            var secondPlayer = session.Players.Skip(1).First();
            var layer = new PlayerDetailsLayer(fakeContext.Object, session.Key, secondPlayer.Key);

            session.SetNumber = 1;
            session.RoundNumber = 1;
            LogicalHelpers.PlayCardSet(session, session.Players.First(), new PlayedSet());

            Assert.IsTrue(layer.CanCallBullshit);
        }
示例#5
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",
            });
        }
示例#6
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));
        }
示例#7
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);
        }
示例#8
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);
        }
示例#9
0
        public void CanCallBullshit_SamePlayer_ReturnsFalse()
        {
            var session = LogicalHelpers.OngoingGame;
            var fakeContext = LogicalHelpers.GetSimpleSessionContext(session);
            var currentPlayer = session.Players.First();
            var layer = new PlayerDetailsLayer(fakeContext.Object, session.Key, currentPlayer.Key);

            LogicalHelpers.SetCurrentPlayer(session, currentPlayer);

            Assert.IsFalse(layer.CanCallBullshit);
        }
示例#10
0
        public void CanCallBullshit_HasBullshitCallUnderway_ReturnsFalse()
        {
            var session = LogicalHelpers.OngoingGame;
            var fakeContext = LogicalHelpers.GetSimpleSessionContext(session);
            var secondPlayer = session.Players.Skip(1).First();
            var layer = new PlayerDetailsLayer(fakeContext.Object, session.Key, secondPlayer.Key);

            LogicalHelpers.AddBullshit(session, new BullshitEvent());

            Assert.IsFalse(layer.CanCallBullshit);
        }
示例#11
0
        public void CanCallBullshit_FinishedGame_ReturnsFalse()
        {
            var session = LogicalHelpers.OngoingGame;
            session.FinishedDate = DateTime.Now;

            var fakeContext = LogicalHelpers.GetSimpleSessionContext(session);
            var layer = new PlayerDetailsLayer(fakeContext.Object, session.Key, session.Players.First().Key);

            Assert.IsFalse(layer.CanCallBullshit);
        }
示例#12
0
        public void CanCallBullshit_BadSession_ThrowsException()
        {
            var session = LogicalHelpers.OngoingGame;
            var fakeContext = LogicalHelpers.GetSimpleSessionContext(session);
            var layer = new PlayerDetailsLayer(fakeContext.Object, session.Key, Guid.Empty);

            Assert.IsFalse(layer.CanCallBullshit);
        }