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;
        }
        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);
            }
        }
        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");
        }
Exemple #5
0
        public bool IsCardPicked(int draftId, int cardId)
        {
            IPickRepository pr = new PickRepository();
            IDraftRepository dr = new DraftRepository();
            ICardRepository cr = new CardRepository();

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

            var picks = pr.GetPicksByCardAndDraft(card, draft);
            return picks.Count > 0;
        }
Exemple #6
0
        public List<Pick> GetPickList(int draftId)
        {
            IPickRepository pickRepository = new PickRepository();
            IDraftRepository dr = new DraftRepository();

            var draft = dr.GetById(draftId);
            var ret = pickRepository.GetPicksByDraft(draft);
            return ret == null ? new List<Pick>() : ret.ToList();
        }
Exemple #7
0
        public List<Pick> GetLatestPicksByPlayer(int draftId, int memberId)
        {
            IDraftRepository dr = new DraftRepository();
            IPickRepository pr = new PickRepository();
            IMemberRepository mr = new MemberRepository();

            var draft = dr.GetById(draftId);
            var member = mr.GetById(memberId);
            var picksCollection = pr.GetPicksByDraftAndMember(draft, member);

            if (picksCollection == null)
                return new List<Pick>();

            var picks = picksCollection.ToList();
            picks.Sort((p1, p2) => p1.CreatedDate.CompareTo(p2.CreatedDate));

            return picks;
        }