public void SystemTimeCanBeResetAfterBeingMocked() { SystemTimeMocker.SetOneSecondAfter(DateTime.Now.AddDays(oneDay)); SystemTimeMocker.Reset(); SystemTime.Now.Should().BeCloseTo(DateTime.Now, acceptableInaccuracy); }
public void SolvingTieWhenThereIsNoTieDoesNothing() { PlayerReference maruPlayerReference = tournament.RegisterPlayerReference("Maru"); PlayerReference storkPlayerReference = tournament.RegisterPlayerReference("Stork"); PlayerReference taejaPlayerReference = tournament.RegisterPlayerReference("Taeja"); round.SetPlayersPerGroupCount(3); GroupBase group = round.Groups.First(); Match match; match = round.Groups.First().Matches[0]; SystemTimeMocker.SetOneSecondAfter(match.StartDateTime); match.Player1.IncreaseScore(2); match = round.Groups.First().Matches[1]; SystemTimeMocker.SetOneSecondAfter(match.StartDateTime); match.Player2.IncreaseScore(2); match = round.Groups.First().Matches[2]; SystemTimeMocker.SetOneSecondAfter(match.StartDateTime); match.Player1.IncreaseScore(2); group.HasProblematicTie().Should().BeFalse(); group.SolveTieByChoosing(maruPlayerReference.Id).Should().BeFalse(); }
public void GivenScoreIsAddedToPlayersInGivenMatchesInGroups(Table table) { if (table == null) { throw new ArgumentNullException(nameof(table)); } foreach (TableRow row in table.Rows) { TestUtilities.ParseScoreAddedToMatchPlayer(row, out int _, out int groupIndex, out int matchIndex, out string scoringPlayer, out int scoreAdded); GroupBase group = createdGroups[groupIndex]; Match match = group.Matches[matchIndex]; SystemTimeMocker.SetOneSecondAfter(match.StartDateTime); Player player = match.FindPlayer(scoringPlayer); if (player != null) { player.IncreaseScore(scoreAdded); } else { throw new Exception("Invalid player name in given match within given group"); } } }
public void CanSolveTie() { PlayerReference maruPlayerReference = tournament.RegisterPlayerReference("Maru"); round.SetPlayersPerGroupCount(3); PlayerReference storkPlayerReference = tournament.RegisterPlayerReference("Stork"); round.SetAdvancingPerGroupCount(2); PlayerReference taejaPlayerReference = tournament.RegisterPlayerReference("Taeja"); BracketRound bracketRound = tournament.AddBracketRound(); GroupBase group = round.Groups.First(); foreach (Match match in round.Groups.First().Matches) { SystemTimeMocker.SetOneSecondAfter(match.StartDateTime); match.Player1.IncreaseScore(2); } group.HasProblematicTie().Should().BeTrue(); group.HasSolvedTie().Should().BeFalse(); group.SolveTieByChoosing(taejaPlayerReference.Id).Should().BeFalse(); group.HasProblematicTie().Should().BeTrue(); group.HasSolvedTie().Should().BeFalse(); group.SolveTieByChoosing(storkPlayerReference.Id).Should().BeTrue(); group.HasProblematicTie().Should().BeTrue(); group.HasSolvedTie().Should().BeTrue(); bracketRound.Groups.First().Matches[0].Player1.GetName().Should().Be("Taeja"); bracketRound.Groups.First().Matches[0].Player2.GetName().Should().Be("Stork"); }
public void CannotDecreasePlayerScoreBelowZero() { SystemTimeMocker.SetOneSecondAfter(match.StartDateTime); player.DecreaseScore(1).Should().BeTrue(); player.Score.Should().Be(0); }
public void MockedSystemTimeReturnsMockedNow() { DateTime tomorrow = DateTime.Now.AddDays(oneDay); SystemTimeMocker.SetOneSecondAfter(tomorrow); SystemTime.Now.Should().BeCloseTo(tomorrow, acceptableInaccuracy); }
public void CannotCreateMatchBetForMatchThatIsOngoing() { SystemTimeMocker.SetOneSecondAfter(firstMatch.StartDateTime); MatchBet matchBet = MatchBet.Create(better, firstMatch, firstMatch.Player1); matchBet.Should().BeNull(); }
public void CanGetLosingPlayerWhenMatchIsFinished() { SystemTimeMocker.SetOneSecondAfter(match.StartDateTime); match.Player1.IncreaseScore(GetWinningScore()); Player player = match.GetLosingPlayer(); player.Should().Be(match.Player2); }
public void PlayStateIsEqualToFinishedWhenMatchHasAWinner() { SystemTimeMocker.SetOneSecondAfter(match.StartDateTime); match.Player1.IncreaseScore(GetWinningScore()); PlayStateEnum playState = match.GetPlayState(); playState.Should().Be(PlayStateEnum.Finished); }
public void PlayStateIsEqualToOngoingWhenMatchHasStartedButNotFinished() { SystemTimeMocker.SetOneSecondAfter(match.StartDateTime); match.Player1.IncreaseScore(GetWinningScore() - 1); PlayStateEnum playState = match.GetPlayState(); playState.Should().Be(PlayStateEnum.Ongoing); }
public void CannotChangeBestOfWhenMatchHasStarted() { SystemTimeMocker.SetOneSecondAfter(match.StartDateTime); bool setResult = match.SetBestOf(7); setResult.Should().BeFalse(); match.BestOf.Should().Be(3); }
public void CanIncreaseScore() { SystemTimeMocker.SetOneSecondAfter(match.StartDateTime); int score = 1; player.IncreaseScore(score).Should().BeTrue(); player.Score.Should().Be(score); }
public void CannotGetLosingPlayerWhileMatchIsOngoing() { SystemTimeMocker.SetOneSecondAfter(match.StartDateTime); match.Player1.IncreaseScore(GetWinningScore() - 1); Player player = match.GetLosingPlayer(); player.Should().BeNull(); }
public void CannotPlaceMatchBetOnMatchThatIsOngoing() { Better better = tournament.AddBetter(user); SystemTimeMocker.SetOneSecondAfter(match.StartDateTime); better.PlaceMatchBet(match, match.Player1); better.Bets.Should().BeEmpty(); }
public void CannotDecreasePlayerScoreWhenTournamentHasIssues() { TurnTournamentInvalid(); SystemTimeMocker.SetOneSecondAfter(match.StartDateTime); player.DecreaseScore(1).Should().BeFalse(); player.Score.Should().Be(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(); }
public void GivenGroupsWithinTournamentIsPlayedOutAndBettedOn(Table table) { if (table == null) { throw new ArgumentNullException(nameof(table)); } foreach (TableRow row in table.Rows) { TestUtilities.ParseTargetGroupToPlay(row, out int tournamentIndex, out int roundIndex, out int groupIndex); bool tournamentIndexIsValid = createdTournaments.Count > tournamentIndex; bool roundIndexIsValid = createdTournaments[tournamentIndex].Rounds.Count > roundIndex; bool groupIndexIsValid = createdTournaments[tournamentIndex].Rounds[roundIndex].Groups.Count > groupIndex; if (!tournamentIndexIsValid || !roundIndexIsValid || !groupIndexIsValid) { throw new IndexOutOfRangeException("Tournament, round, or group with given index does not exist"); } SystemTimeMocker.Reset(); Tournament tournament = createdTournaments[tournamentIndex]; RoundBase round = tournament.Rounds[roundIndex]; GroupBase group = round.Groups[groupIndex]; while (group.GetPlayState() != PlayStateEnum.Finished) { bool tournamentHasBetters = tournament.Betters.Count > 0; if (tournamentHasBetters) { PlaceBetsOnAvailableMatchesInGroup(tournament.Betters, group); } foreach (Match match in group.Matches) { if (match.IsReady() && match.GetPlayState() == PlayStateEnum.NotBegun) { SystemTimeMocker.SetOneSecondAfter(match.StartDateTime); break; } } bool playedMatchesSuccessfully = PlayAvailableMatches(group); if (!playedMatchesSuccessfully) { break; } } } }
public void CannotPlaceMatchBetOnMatchThatIsFinished() { Better better = tournament.AddBetter(user); SystemTimeMocker.SetOneSecondAfter(match.StartDateTime); int winningScore = (int)Math.Ceiling(match.BestOf / 2.0); match.Player1.IncreaseScore(winningScore); better.PlaceMatchBet(match, match.Player1); better.Bets.Should().BeEmpty(); }
public void CanDetectWhenRoundRobinRoundContainsProblematicTie() { round.SetPlayersPerGroupCount(3); tournament.RegisterPlayerReference("Maru"); tournament.RegisterPlayerReference("Stork"); tournament.RegisterPlayerReference("Taeja"); foreach (Match match in round.Groups.First().Matches) { SystemTimeMocker.SetOneSecondAfter(match.StartDateTime); match.Player1.IncreaseScore(2); } round.HasProblematicTie().Should().BeTrue(); }
public void RoundIsOngoingUntilTieIsSolved() { round.SetPlayersPerGroupCount(3); tournament.RegisterPlayerReference("Maru"); tournament.RegisterPlayerReference("Stork"); tournament.RegisterPlayerReference("Taeja"); foreach (Match match in round.Groups.First().Matches) { SystemTimeMocker.SetOneSecondAfter(match.StartDateTime); match.Player1.IncreaseScore(2); } round.GetPlayState().Should().Be(PlayStateEnum.Ongoing); }
public void CannotReplaceMatchBetOnMatchThatIsOngoing() { Better better = tournament.AddBetter(user); better.PlaceMatchBet(match, match.Player1); SystemTimeMocker.SetOneSecondAfter(match.StartDateTime); better.PlaceMatchBet(match, match.Player2); better.Bets.Should().HaveCount(1); better.Bets.First().Should().NotBeNull(); MatchBet matchBet = better.Bets.First() as MatchBet; ValidateMatchBet(matchBet, better, match, match.Player1); }
private void PlayMatch(TournamentRepository tournamentRepository, Match match) { bool matchHaveNotStarted = match.StartDateTime > SystemTime.Now; if (matchHaveNotStarted) { SystemTimeMocker.SetOneSecondAfter(match.StartDateTime); } int winningScore = (int)Math.Ceiling(match.BestOf / 2.0); // Give points to player with name that precedes the other alphabetically bool increasePlayer1Score = match.Player1.GetName().CompareTo(match.Player2.GetName()) <= 0; Tournament tournament = match.Group.Round.Tournament; Guid scoringPlayerId = increasePlayer1Score ? match.Player1.Id : match.Player2.Id; tournamentRepository.AddScoreToPlayerInMatch(tournament, match.Id, scoringPlayerId, winningScore); tournamentRepository.Save(); }
public void DoesNotFlagRoundAsProlematicTieWhenNoProblematicTieHappens() { round.SetPlayersPerGroupCount(3); tournament.RegisterPlayerReference("Maru"); tournament.RegisterPlayerReference("Stork"); tournament.RegisterPlayerReference("Taeja"); Match match; match = round.Groups.First().Matches[0]; SystemTimeMocker.SetOneSecondAfter(match.StartDateTime); match.Player1.IncreaseScore(2); match = round.Groups.First().Matches[1]; SystemTimeMocker.SetOneSecondAfter(match.StartDateTime); match.Player2.IncreaseScore(2); match = round.Groups.First().Matches[2]; SystemTimeMocker.SetOneSecondAfter(match.StartDateTime); match.Player1.IncreaseScore(2); round.HasProblematicTie().Should().BeFalse(); }
public void GivenScoreIsAddedToPlayersInGivenMatchesInGroups(string tournamentName, Table table) { if (table == null) { throw new ArgumentNullException(nameof(table)); } using (TournamentRepository tournamentRepository = CreateTournamentRepository()) { Tournament tournament = tournamentRepository.GetTournamentByName(tournamentName); foreach (TableRow row in table.Rows) { TestUtilities.ParseScoreAddedToMatchPlayer(row, out int roundIndex, out int groupIndex, out int matchIndex, out string scoringPlayer, out int scoreAdded); RoundBase round = tournament.Rounds[roundIndex]; GroupBase group = round.Groups[groupIndex]; Match match = group.Matches[matchIndex]; SystemTimeMocker.SetOneSecondAfter(match.StartDateTime); Player player = match.FindPlayer(scoringPlayer); if (player != null) { tournamentRepository.AddScoreToPlayerInMatch(tournament, match.Id, player.Id, scoreAdded); } else { // LOG Error: Invalid player name in given match within given group throw new NotImplementedException(); } } tournamentRepository.Save(); } }
public void MockedSystemTimeReturnsMockedUtcNow() { SystemTimeMocker.SetOneSecondAfter(DateTime.Now.AddDays(oneDay)); SystemTime.UtcNow.Should().BeCloseTo(DateTime.UtcNow.AddDays(oneDay), acceptableInaccuracy); }