Exemplo n.º 1
0
        public MatchBet PlaceMatchBet(Match match, Player player)
        {
            bool anyParameterIsInvalid = !PlaceMatchBetParametersAreValid(match, player);

            if (anyParameterIsInvalid)
            {
                return(null);
            }

            MatchBet newMatchBet      = MatchBet.Create(this, match, player);
            MatchBet existingMatchBet = FindMatchBet(match);

            bool createdNewMatchBetSuccessfully    = newMatchBet != null;
            bool matchBetForThisMatchAlreadyExists = existingMatchBet != null;

            if (createdNewMatchBetSuccessfully)
            {
                if (matchBetForThisMatchAlreadyExists)
                {
                    Bets.Remove(existingMatchBet);
                    existingMatchBet.MarkForDeletion();
                }

                Bets.Add(newMatchBet);
                MarkAsModified();
            }

            return(newMatchBet);
        }
Exemplo n.º 2
0
        public void CannotCreateMatchBetForMatchThatIsOngoing()
        {
            SystemTimeMocker.SetOneSecondAfter(firstMatch.StartDateTime);

            MatchBet matchBet = MatchBet.Create(better, firstMatch, firstMatch.Player1);

            matchBet.Should().BeNull();
        }
Exemplo n.º 3
0
        public void CanCreateMatchBet()
        {
            MatchBet matchBet = MatchBet.Create(better, firstMatch, firstMatch.Player1);

            matchBet.Should().NotBeNull();
            matchBet.Id.Should().NotBeEmpty();
            matchBet.BetterId.Should().Be(better.Id);
            matchBet.MatchId.Should().Be(firstMatch.Id);
            matchBet.PlayerId.Should().Be(firstMatch.Player1.Id);
        }
Exemplo n.º 4
0
        public void CannotCreateMatchBetForMatchThatIsFinished()
        {
            SystemTimeMocker.SetOneSecondAfter(firstMatch.StartDateTime);

            int winningScore = (int)Math.Ceiling(firstMatch.BestOf / 2.0);

            firstMatch.Player1.IncreaseScore(winningScore);

            MatchBet matchBet = MatchBet.Create(better, firstMatch, firstMatch.Player1);

            matchBet.Should().BeNull();
        }
Exemplo n.º 5
0
        public void CannotCreateMatchBetWithoutPlayer()
        {
            MatchBet matchBet = MatchBet.Create(better, firstMatch, null);

            matchBet.Should().BeNull();
        }
Exemplo n.º 6
0
        public void CannotCreateMatchBetWithoutBetter()
        {
            MatchBet matchBet = MatchBet.Create(null, firstMatch, firstMatch.Player1);

            matchBet.Should().BeNull();
        }