예제 #1
0
        public void CanGetPickList()
        {
            IPickRepository repository = new PickRepository();

            repository.PickCard(_drafts[0], _members[0], _cards[0]);
            repository.PickCard(_drafts[0], _members[1], _cards[1]);
            repository.PickCard(_drafts[0], _members[2], _cards[2]);
            repository.PickCard(_drafts[1], _members[2], _cards[2]);

            ICollection<Pick> picks = repository.GetPicksByDraft(_drafts[0]);

            Assert.AreEqual(3, picks.Count);
        }
        public bool PickCard(int draftId, int memberId, int cardId)
        {
            if (!IsMyTurn(draftId, memberId))
            {
                return FuturePickCard(draftId, memberId, cardId);
            }

            IDraftRepository dr = new DraftRepository();
            IMemberRepository mr = new MemberRepository();
            ICardRepository cr = new CardRepository();

            var draft = dr.GetById(draftId);
            var member = mr.GetById(memberId);
            var card = cr.GetById(cardId);

            if (draft.Finished || !draft.Started)
            {
                return false;
            }

            IPickRepository pickRepository = new PickRepository();
            try
            {
                var pick = pickRepository.PickCard(draft, member, card);
            }
            catch (GenericADOException)
            {
                return false;
            }

            var picks = pickRepository.GetPicksByDraft(draft);

            IDraftMemberPositionsRepository dmpr = new DraftMemberPositionsRepository();
            var nextMemberDraftPosition = dmpr.GetDraftMemberPositionByDraftAndPosition(draft,
                                                                                        GetNextPickPosition(picks.Count, draft.DraftSize));

            draft.CurrentTurn = nextMemberDraftPosition.Member;

            IDraftRepository draftRepository = new DraftRepository();
            draftRepository.Update(draft);

            TryFuturePick(draftId);

            return true;
        }
예제 #3
0
        public void CanMakePick()
        {
            IPickRepository repository = new PickRepository();
            var pick = repository.PickCard(_drafts[0], _members[0], _cards[0]);

            // use session to try to load the pick
            using (ISession session = _sessionFactory.OpenSession())
            {
                var fromDb = session.Get<Pick>(pick.Id);

                // Test that the pick was successfully inserted
                Assert.IsNotNull(fromDb);
                Assert.AreNotSame(pick, fromDb);
                Assert.AreEqual(pick.Member.FullName, fromDb.Member.FullName);
                Assert.AreEqual(pick.Draft.Name, fromDb.Draft.Name);
                Assert.AreEqual(pick.Card.Name, fromDb.Card.Name);
            }
        }
예제 #4
0
        public void CannotPickSameCardTwiceSameMember()
        {
            IPickRepository repository = new PickRepository();

            repository.PickCard(_drafts[0], _members[0], _cards[0]);
            try
            {
                repository.PickCard(_drafts[0], _members[0], _cards[0]);
            }
            catch (GenericADOException)
            {
                return;
            }

            Assert.Fail("Should not be able to pick same card twice");
        }