public bool TransferToNextRound(RoundBase currentRound) { bool roundHasFinished = currentRound.GetPlayState() == PlayStateEnum.Finished; if (roundHasFinished) { RoundBase nextRound = currentRound.GetNextRound(); bool hasRoundToTransferTo = nextRound != null; if (hasRoundToTransferTo) { PlayerReferences = currentRound.GetAdvancingPlayerReferences(); bool hasPlayerReferencesToTransfer = PlayerReferences.Count > 0; if (hasPlayerReferencesToTransfer) { nextRound.ReceiveTransferedPlayerReferences(this); return(true); } // LOG Error: Tried to transfer advancing player references to next round without any player references. return(false); } // LOG Error: Tried to transfer advancing player references to nonexistent next round. return(false); } // LOG Error: Tried to transfer advancing player references to next round before current round is finished. return(false); }
public Result Handle(ChangeAdvancingPerGroupCountInRound command) { Tournament tournament = _tournamentRepository.GetTournamentById(command.TournamentId); if (tournament == null) { return(Result.Failure($"Could not change advancing per group count ({ command.AdvancingPerGroupCount }) setting in round ({ command.RoundId }). Tournament ({ command.TournamentId }) not found.")); } RoundBase round = tournament.GetRoundById(command.RoundId); if (round == null) { return(Result.Failure($"Could not change advancing per group count ({ command.AdvancingPerGroupCount }) setting in round ({ command.RoundId }). Round not found.")); } bool changeSuccessful = _tournamentRepository.SetAdvancingPerGroupCountInRound(round, command.AdvancingPerGroupCount); if (!changeSuccessful) { return(Result.Failure($"Could not change advancing per group count ({ command.AdvancingPerGroupCount }) setting in round ({ command.RoundId }).")); } _tournamentRepository.Save(); return(Result.Success()); }
public void ThenRoundsInTournamentShouldBeValidWithValues(int tournamentIndex, Table table) { if (table == null) { throw new ArgumentNullException(nameof(table)); } Tournament tournament = createdTournaments[tournamentIndex]; for (int index = 0; index < table.Rows.Count; ++index) { TestUtilities.ParseRoundTable(table.Rows[index], out ContestTypeEnum roundType, out string name, out int advancingCount, out int playersPerGroupCount); RoundBase round = tournament.Rounds[index]; if (round is BracketRound bracketRound) { roundType.Should().Be(ContestTypeEnum.Bracket); } else if (round is DualTournamentRound dualTournamentRound) { roundType.Should().Be(ContestTypeEnum.DualTournament); } else if (round is RoundRobinRound roundRobinRound) { roundType.Should().Be(ContestTypeEnum.RoundRobin); } CheckRoundValidity(round, name, advancingCount, playersPerGroupCount); } }
public Result Handle(RenameRoundInTournament command) { Tournament tournament = _tournamentRepository.GetTournamentById(command.TournamentId); if (tournament == null) { return(Result.Failure($"Could not rename round ({ command.RoundId }) to { command.NewRoundName } in tournament ({ command.TournamentId }). Tournament not found.")); } RoundBase round = tournament.GetRoundById(command.RoundId); if (round == null) { return(Result.Failure($"Could not rename round ({ command.RoundId }) to { command.NewRoundName } in tournament ({ command.TournamentId }). Round not found.")); } bool renameSuccessful = _tournamentRepository.RenameRoundInTournament(round, command.NewRoundName); if (!renameSuccessful) { return(Result.Failure($"Could not rename round ({ command.RoundId }) to { command.NewRoundName } in tournament ({ command.TournamentId }).")); } _tournamentRepository.Save(); return(Result.Success()); }
public void WhenMatchesInTournamentNamedSwitchesPlayerReferences(string tournamentName, Table table) { using (TournamentRepository tournamentRepository = CreateTournamentRepository()) { Tournament tournament = tournamentRepository.GetTournamentByName(tournamentName); foreach (TableRow row in table.Rows) { ParsePlayerSwitch(row, out int roundIndex, out int groupIndex1, out int matchIndex1, out string playerName1, out int groupIndex2, out int matchIndex2, out string playerName2); RoundBase roundBase = tournament.Rounds[roundIndex]; GroupBase groupBase1 = roundBase.Groups[groupIndex1]; Match match1 = groupBase1.Matches[matchIndex1]; Player player1 = match1.FindPlayer(playerName1); GroupBase groupBase2 = roundBase.Groups[groupIndex2]; Match match2 = groupBase2.Matches[matchIndex2]; Player player2 = match2.FindPlayer(playerName2); tournamentRepository.SwitchPlayersInMatches(player1, player2); } tournamentRepository.Save(); } }
public void Report(RoundBase round, TournamentIssues issue) { int roundIndex = GetIndexOf(round); string description = GetDescriptionFor(issue); Issues.Add(TournamentIssue.Create(roundIndex, -1, -1, description)); }
private bool ManageRoundRemoval(RoundBase round) { bool containsSoughtRound = Rounds.Contains(round); if (containsSoughtRound) { bool removalSuccessful = Rounds.Remove(round); if (removalSuccessful) { round.MarkForDeletion(); bool stillContainsRounds = Rounds.Count > 0; if (stillContainsRounds) { GetFirstRound().Construct(); } FindIssues(); return(true); } } return(false); }
private void RoundFinalComplete(RoundBase r) { if (r.Data == rounds.GetRound(rounds.NumberRound - 1)) { Invoke("ComingHome", 3f); } }
public void GivenBettersPlacesMatchBets(Table table) { foreach (TableRow row in table.Rows) { TestUtilities.ParseBetterMatchBetPlacements(row, out string betterName, out int roundIndex, out int groupIndex, out int matchIndex, out string playerName); RoundBase round = createdRounds[roundIndex]; GroupBase group = createdGroups[groupIndex]; Match match = group.Matches[matchIndex]; bool betterNameIsNotEmpty = betterName.Length > 0; bool playerNameIsNotEmpty = playerName.Length > 0; if (betterNameIsNotEmpty && playerNameIsNotEmpty) { Better better = round.Tournament.GetBetterByName(betterName); Player player = match.FindPlayer(playerName); better.Should().NotBeNull(); player.Should().NotBeNull(); better.PlaceMatchBet(match, player).Should().NotBeNull(); } } }
public void CanRemoveBracketRoundFromTournamentById() { List <Guid> roundIds = new List <Guid>(); using (TournamentRepository tournamentRepository = CreateTournamentRepository()) { Tournament tournament = tournamentRepository.GetTournamentByName(tournamentName); RoundBase round = tournamentRepository.AddBracketRoundToTournament(tournament); roundIds.Add(round.Id); round = tournamentRepository.AddDualTournamentRoundToTournament(tournament); roundIds.Add(round.Id); round = tournamentRepository.AddRoundRobinRoundToTournament(tournament); roundIds.Add(round.Id); tournamentRepository.Save(); } using (TournamentRepository tournamentRepository = CreateTournamentRepository()) { Tournament tournament = tournamentRepository.GetTournamentByName(tournamentName); foreach (Guid roundId in roundIds) { bool removeResult = tournamentRepository.RemoveRoundFromTournament(tournament, roundId); tournamentRepository.Save(); removeResult.Should().BeTrue(); } tournament.Rounds.Should().BeEmpty(); } }
public void ThenFetchedAdvancingPlayersInRoundShouldBeExactly(int roundIndex, string commaSeparatedPlayerNames) { RoundBase round = createdRounds[roundIndex]; List <string> playerNames = StringUtility.ToStringList(commaSeparatedPlayerNames, ","); RoundInteractionStepUtility.FetchingAdvancingPlayersInRoundYieldsGivenPlayerNames(round, playerNames); }
public void ThenPlayStateOfRoundIsSetTo(int roundIndex, string playStateString) { RoundBase round = createdRounds[roundIndex]; PlayStateEnum playState = ParsePlayStateString(playStateString); round.GetPlayState().Should().Be(playState); }
public void FetchingPreviousRoundWithFirstRoundYieldsNull() { RoundBase firstRound = tournament.AddRoundRobinRound(); RoundBase previousRound = firstRound.GetPreviousRound(); previousRound.Should().BeNull(); }
public void CanGetRoundInTournamentByRoundName() { RoundBase fetchedRound = tournament.GetRoundByName(bracketRound.Name); fetchedRound.Should().NotBeNull(); fetchedRound.Id.Should().Be(bracketRound.Id); fetchedRound.Name.Should().Be(bracketRound.Name); }
private static void CheckWhetherLastRoundContainsMoreThanOneGroup(RoundBase round) { bool lastRoundHasSeveralGroups = round.Groups.Count > 1; if (lastRoundHasSeveralGroups) { round.Tournament.TournamentIssueReporter.Report(round, TournamentIssues.LastRoundContainsMoreThanOneGroup); } }
public bool RenameRoundInTournament(RoundBase round, string name) { if (round != null) { return(round.RenameTo(name)); } return(false); }
public bool SetPlayersPerGroupCountInRound(RoundBase round, int count) { if (round != null) { return(round.SetPlayersPerGroupCount(count)); } return(false); }
private void OnPlayerReferencesChanged() { RoundBase firstRound = GetFirstRound(); firstRound.Construct(); firstRound.FillGroupsWithPlayerReferences(); FindIssues(); }
public void CanDetectWhenRoundIsNotTheFirstOne() { RoundBase firstRound = tournament.AddRoundRobinRound(); RoundBase secondRound = tournament.AddRoundRobinRound(); bool isFirstRound = secondRound.IsFirstRound(); isFirstRound.Should().BeFalse(); }
public void FetchingNextRoundWithLastRoundYieldsNull() { RoundBase firstRound = tournament.AddRoundRobinRound(); RoundBase secondRound = tournament.AddRoundRobinRound(); RoundBase nextRound = secondRound.GetNextRound(); nextRound.Should().BeNull(); }
public void CanFetchRoundBeforeThisRound() { RoundBase beforeRound = tournament.AddRoundRobinRound(); RoundBase thisRound = tournament.AddRoundRobinRound(); RoundBase previousRound = thisRound.GetPreviousRound(); previousRound.Should().Be(beforeRound); }
public void CanDetectWhenRoundIsTheLastOne() { RoundBase firstRound = tournament.AddRoundRobinRound(); RoundBase secondRound = tournament.AddRoundRobinRound(); bool isLastRound = secondRound.IsLastRound(); isLastRound.Should().BeTrue(); }
public void CanFetchRoundAfterThisRound() { RoundBase firstRound = tournament.AddRoundRobinRound(); RoundBase secondRound = tournament.AddRoundRobinRound(); RoundBase nextRound = firstRound.GetNextRound(); nextRound.Should().Be(secondRound); }
public void WhenRoundIsRemovedFromTournament(int tournamentIndex, int roundIndex) { RoundBase round = createdRounds[roundIndex]; Tournament tournament = createdTournaments[tournamentIndex]; tournament.RemoveRound(round); createdRounds.Clear(); createdRounds.AddRange(tournament.Rounds); }
public static void FetchingAdvancingPlayersInRoundYieldsGivenPlayerNames(RoundBase round, List <string> playerNames) { List <PlayerReference> playerReferences = round.GetAdvancingPlayerReferences(); playerReferences.Should().HaveCount(playerNames.Count); foreach (string playerName in playerNames) { playerReferences.SingleOrDefault(playerReference => playerReference.Name == playerName).Should().NotBeNull(); } }
public static RoundDto ConvertToRoundDto(RoundBase round) { return(new RoundDto() { Id = round.Id, ContestType = round.ContestType.ToString(), Name = round.Name, Groups = round.Groups.Select(group => ConvertToGroupDto(group)).ToList() }); }
public MatchBetTests() { user = User.Create("Stålberto"); tournament = Tournament.Create("GSL 2019"); round = tournament.AddBracketRound(); tournament.RegisterPlayerReference("Maru"); tournament.RegisterPlayerReference("Stork"); group = round.Groups.First(); match = group.Matches.First(); }
public bool RemoveRoundFromTournament(Tournament tournament, string roundName) { RoundBase roundToRemove = tournament.GetRoundByName(roundName); if (roundToRemove != null) { return(tournament.RemoveRound(roundToRemove)); } return(false); }
public void GivenRoundNamedChangesPlayersPerGroupCountToInTournamentNamed(string roundName, int newPlayersPerGroupCount, string tournamentName) { using (TournamentRepository tournamentRepository = CreateTournamentRepository()) { Tournament tournament = tournamentRepository.GetTournamentByName(tournamentName); RoundBase round = tournament.GetRoundByName(roundName); tournamentRepository.SetPlayersPerGroupCountInRound(round, newPlayersPerGroupCount); tournamentRepository.Save(); } }
public bool RemoveRoundFromTournament(Tournament tournament, Guid roundId) { RoundBase roundToRemove = tournament.GetRoundById(roundId); if (roundToRemove != null) { return(tournament.RemoveRound(roundToRemove)); } return(false); }