public async Task EndTournamentAsync() { await this.DoReadWriteActionOnCurrentTournamentAsync( currentTournament => this.CleanupTournamentArtifactsAsync(currentTournament)); TournamentsManager manager = this.GlobalManager.GetOrAdd(this.Context.Guild.Id, CreateTournamentsManager); if (!manager.TryClearCurrentTournament()) { this.Logger.Debug("Tournament cleanup failed"); await this.SendChannelMessage(BotStrings.TournamentWasNotRemoved); return; } this.Logger.Debug("Tournament cleanup finished"); }
public void TryClearCurrentTournament() { const string otherTournamentName = DefaultTournamentName + "2"; TournamentsManager manager = new TournamentsManager() { GuildId = 1 }; TournamentState state = new TournamentState(1, DefaultTournamentName); TournamentState otherState = new TournamentState(1, otherTournamentName); manager.AddOrUpdateTournament(DefaultTournamentName, state, (name, oldState) => oldState); manager.AddOrUpdateTournament(otherTournamentName, otherState, (name, oldState) => oldState); Assert.IsTrue( manager.TrySetCurrentTournament(DefaultTournamentName, out string errorMessage), "Couldn't set current tournament initially."); Assert.IsTrue(manager.TryClearCurrentTournament(), "Couldn't clear current tournament."); // TrySetCurrentTournament should work again if we've just cleared it. Assert.IsTrue( manager.TrySetCurrentTournament(otherTournamentName, out errorMessage), "Couldn't set current tournament after clearing it."); }