示例#1
0
        public void TrySetCurrentTournamentWithNoCurrentTournament()
        {
            TournamentsManager manager = new TournamentsManager()
            {
                GuildId = 1
            };

            TournamentState state      = new TournamentState(1, DefaultTournamentName);
            TournamentState otherState = new TournamentState(1, DefaultTournamentName + "2");

            manager.AddOrUpdateTournament(DefaultTournamentName, state, (name, oldState) => oldState);

            Assert.IsTrue(
                manager.TrySetCurrentTournament(DefaultTournamentName, out string errorMessage),
                "Couldn't set current tournament.");
            manager.TryReadActionOnCurrentTournament(currentState =>
            {
                Assert.AreEqual(DefaultTournamentName, currentState.Name, "Unexpected tournament in TryReadAction");
                return(Task.CompletedTask);
            });
            manager.TryReadWriteActionOnCurrentTournament(currentState =>
            {
                Assert.AreEqual(
                    DefaultTournamentName, currentState.Name, "Unexpected tournament in TryReadWriteAction (Action)");
            });
            manager.TryReadWriteActionOnCurrentTournament(currentState =>
            {
                Assert.AreEqual(
                    DefaultTournamentName, currentState.Name, "Unexpected tournament in TryReadWriteAction (Func)");
                return(Task.CompletedTask);
            });
        }
示例#2
0
        public static async Task DoReadWriteActionOnCurrentTournamentForMemberAsync(
            this TournamentsManager manager, IUser user, Func <ITournamentState, Task> action)
        {
            Result <Task> result = manager.TryReadWriteActionOnCurrentTournament(action);

            if (result.Success)
            {
                await result.Value;
                return;
            }

            IDMChannel channel = await user.GetOrCreateDMChannelAsync();

            await channel.SendMessageAsync(BotStrings.UnableToPerformCommand(result.ErrorMessage));
        }