Example #1
0
        public void IsValidHand_PresumedTypeIdSet_Invalid()
        {
            var set = new PlayedSet()
            {
                PresumedTypeId = CardType.SpadeId,
            };

            Assert.IsFalse(set.IsValidHand);
        }
Example #2
0
        public void IsValidHand_PresumedTypeSet_Invalid()
        {
            var set = new PlayedSet()
            {
                PresumedType = CardType.Heart,
            };

            Assert.IsFalse(set.IsValidHand);
        }
Example #3
0
        public void IsValidHand_NoCardsPlayed_Invalid()
        {
            var set = new PlayedSet()
            {
                PresumedTypeId = CardType.DiamondId,
                PresumedType = CardType.Diamond,
            };

            Assert.IsFalse(set.IsValidHand);
        }
Example #4
0
        public void IsValidHand_EverythingSet_ReturnsTrue()
        {
            var set = new PlayedSet()
            {
                PresumedTypeId = CardType.DiamondId,
                PresumedType = CardType.Diamond,
                PlayedHand = "D6",
            };

            Assert.IsTrue(set.IsValidHand);
        }
Example #5
0
        public void IsValidHand_4Cards_Invalid()
        {
            var set = new PlayedSet()
            {
                PresumedTypeId = CardType.DiamondId,
                PresumedType = CardType.Diamond,
                PlayedHand = "D6;D3;D7;H4",
            };

            Assert.IsFalse(set.IsValidHand);
        }
Example #6
0
        internal static void AddSession(Session session, PlayedSet set)
        {
            if (session.PlayedSet == null)
            {
                session.PlayedSet = new List<PlayedSet>();
            }

            set.Session = session;
            set.SessionId = session.Id;

            session.PlayedSet.Add(set);
        }
Example #7
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);
        }
Example #8
0
        public void PlayCardSet(PlayedSet set)
        {
            if (!Session.IsPlayableGame)
            {
                throw new InvalidOperationException("This game is not in a playable state");
            }

            if (!IsMyTurn)
            {
                throw new InvalidOperationException("You are playing out of turn");
            }

            if (Session.HasBullshitCallUnderway)
            {
                throw new InvalidOperationException("Someone's called busllshit, you can't play while under this mode.");
            }

            if (!IsValidCardSet(set))
            {
                throw new InvalidOperationException("Cards played is invalid");
            }

            if (!PlayerHasTheseCards(set.PlayedCards))
            {
                throw new InvalidOperationException("Stop hacking bro, you don't have these cards in your hand");
            }

            Session.PlayedSet.Add(set);
            Hand.Remove(set.PlayedCards);
            Context.SaveChanges();
        }
Example #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));
        }
Example #10
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);
        }
Example #11
0
        public void PlayedCardNumber_3Cards_Returns3()
        {
            var set = new PlayedSet()
            {
                PlayedHand = "D1;D6;H8"
            };

            Assert.AreEqual(3, set.PlayedCardCount);
        }
Example #12
0
        public void PlayedCardNumber_1Cards_Returns1()
        {
            var set = new PlayedSet()
            {
                PlayedHand = "D1"
            };

            Assert.AreEqual(1, set.PlayedCardCount);
        }
Example #13
0
 public void IsValidHand_NoValuesSet_Invalid()
 {
     var set = new PlayedSet() { };
     Assert.IsFalse(set.IsValidHand);
 }
Example #14
0
        public void PlayedCardNumber_NoCards_Returns0()
        {
            var set = new PlayedSet()
            {
            };

            Assert.AreEqual(0, set.PlayedCardCount);
        }