Beispiel #1
0
        private void CreateHandler(
            IOptionsMonitor <BotConfiguration> options,
            IFileScoresheetGenerator scoresheetGenerator,
            out ReaderCommandHandler handler,
            out GameState game,
            out MessageStore messageStore)
        {
            messageStore = new MessageStore();
            ICommandContext commandContext = CommandMocks.CreateCommandContext(
                messageStore,
                DefaultIds,
                DefaultGuildId,
                DefaultChannelId,
                userId: DefaultReaderId,
                updateMockGuild: UpdateMockGuild,
                out _);
            GameStateManager manager = new GameStateManager();

            manager.TryCreate(DefaultChannelId, out game);
            game.TeamManager = new ByCommandTeamManager();
            IDatabaseActionFactory dbActionFactory = CommandMocks.CreateDatabaseActionFactory(
                this.botConfigurationfactory);

            handler = new ReaderCommandHandler(commandContext, manager, options, dbActionFactory, scoresheetGenerator);
        }
Beispiel #2
0
        private void InitializeHandler(
            ulong voiceChannelId    = 9999,
            string voiceChannelName = "Voice",
            IGoogleSheetsGeneratorFactory googleSheetsGeneratorFactory = null)
        {
            this.MessageStore = new MessageStore();
            ICommandContext commandContext = CommandMocks.CreateCommandContext(
                this.MessageStore,
                DefaultIds,
                DefaultGuildId,
                DefaultChannelId,
                DefaultReaderId,
                (mockGuild, textChannel) =>
            {
                Mock <IVoiceChannel> mockVoiceChannel = new Mock <IVoiceChannel>();
                mockVoiceChannel.Setup(voiceChannel => voiceChannel.Id).Returns(voiceChannelId);
                mockVoiceChannel.Setup(voiceChannel => voiceChannel.Name).Returns(voiceChannelName);
                mockGuild
                .Setup(guild => guild.GetVoiceChannelAsync(It.IsAny <ulong>(), It.IsAny <CacheMode>(), It.IsAny <RequestOptions>()))
                .Returns(Task.FromResult(mockVoiceChannel.Object));

                List <IVoiceChannel> voiceChannels = new List <IVoiceChannel>()
                {
                    mockVoiceChannel.Object
                };
                mockGuild
                .Setup(guild => guild.GetVoiceChannelsAsync(It.IsAny <CacheMode>(), It.IsAny <RequestOptions>()))
                .Returns(Task.FromResult <IReadOnlyCollection <IVoiceChannel> >(voiceChannels));
                mockGuild
                .Setup(guild => guild.Roles)
                .Returns(DefaultRoles.Select((role, index) =>
                {
                    Mock <IRole> mockRole = new Mock <IRole>();
                    mockRole
                    .Setup(r => r.Name)
                    .Returns(role);
                    mockRole
                    .Setup(r => r.Id)
                    .Returns((ulong)index);
                    return(mockRole.Object);
                }).ToArray());
            },
                out IGuildTextChannel guildTextChannel);

            this.GuildTextChannel = guildTextChannel;
            IOptionsMonitor <BotConfiguration> options         = CommandMocks.CreateConfigurationOptionsMonitor();
            IDatabaseActionFactory             dbActionFactory = CommandMocks.CreateDatabaseActionFactory(
                this.botConfigurationfactory);

            this.GoogleSheetsGeneratorFactory = googleSheetsGeneratorFactory ?? (new Mock <IGoogleSheetsGeneratorFactory>()).Object;

            this.Handler = new AdminCommandHandler(commandContext, dbActionFactory, this.GoogleSheetsGeneratorFactory);
        }
        private void CreateHandler(out BotOwnerCommandHandler handler, out MessageStore messageStore)
        {
            messageStore = new MessageStore();
            ICommandContext commandContext = CommandMocks.CreateCommandContext(
                messageStore,
                DefaultIds,
                DefaultGuildId,
                DefaultChannelId,
                DefaultReaderId);
            IDatabaseActionFactory dbActionFactory = CommandMocks.CreateDatabaseActionFactory(
                this.botConfigurationfactory);
            IOptionsMonitor <BotConfiguration> options = CommandMocks.CreateConfigurationOptionsMonitor();

            handler = new BotOwnerCommandHandler(commandContext, options, dbActionFactory);
        }
Beispiel #4
0
        public async Task ClearAllRemovesGame()
        {
            GameStateManager manager = new GameStateManager();

            manager.TryCreate(DefaultChannelId, out GameState currentGame);
            MessageStore    messageStore   = new MessageStore();
            ICommandContext commandContext = CommandMocks.CreateCommandContext(
                messageStore, DefaultIds, DefaultGuildId, DefaultChannelId, DefaultReaderId);
            IDatabaseActionFactory dbActionFactory = CommandMocks.CreateDatabaseActionFactory(
                this.botConfigurationfactory);
            IOptionsMonitor <BotConfiguration> options             = CommandMocks.CreateConfigurationOptionsMonitor();
            IFileScoresheetGenerator           scoresheetGenerator = (new Mock <IFileScoresheetGenerator>()).Object;

            ReaderCommandHandler handler = new ReaderCommandHandler(
                commandContext, manager, options, dbActionFactory, scoresheetGenerator);

            await handler.ClearAllAsync();

            Assert.IsFalse(
                manager.TryGet(DefaultChannelId, out _),
                "Game should have been removed from the manager.");
            Assert.AreEqual(1, messageStore.ChannelMessages.Count, "Unexpected number of messages sent.");
        }
        private void CreateHandler(
            ulong voiceChannelId,
            string voiceChannelName,
            out AdminCommandHandler handler,
            out MessageStore messageStore,
            out IGuildTextChannel guildTextChannel)
        {
            messageStore = new MessageStore();
            ICommandContext commandContext = CommandMocks.CreateCommandContext(
                messageStore,
                DefaultIds,
                DefaultGuildId,
                DefaultChannelId,
                DefaultReaderId,
                (mockGuild, textChannel) =>
            {
                Mock <IVoiceChannel> mockVoiceChannel = new Mock <IVoiceChannel>();
                mockVoiceChannel.Setup(voiceChannel => voiceChannel.Id).Returns(voiceChannelId);
                mockVoiceChannel.Setup(voiceChannel => voiceChannel.Name).Returns(voiceChannelName);
                mockGuild
                .Setup(guild => guild.GetVoiceChannelAsync(It.IsAny <ulong>(), It.IsAny <CacheMode>(), It.IsAny <RequestOptions>()))
                .Returns(Task.FromResult(mockVoiceChannel.Object));

                List <IVoiceChannel> voiceChannels = new List <IVoiceChannel>()
                {
                    mockVoiceChannel.Object
                };
                mockGuild
                .Setup(guild => guild.GetVoiceChannelsAsync(It.IsAny <CacheMode>(), It.IsAny <RequestOptions>()))
                .Returns(Task.FromResult <IReadOnlyCollection <IVoiceChannel> >(voiceChannels));
            },
                out guildTextChannel);
            IDatabaseActionFactory dbActionFactory = CommandMocks.CreateDatabaseActionFactory(
                this.botConfigurationfactory);

            handler = new AdminCommandHandler(commandContext, dbActionFactory);
        }