public static ICommandContext CreateCommandContext( MessageStore messageStore, HashSet <ulong> existingUserIds, ulong guildId, ulong messageChannelId, ulong userId, Action <Mock <IGuild>, IGuildTextChannel> updateMockGuild, out IGuildTextChannel guildTextChannel) { Mock <ICommandContext> mockCommandContext = new Mock <ICommandContext>(); IGuild guild = CreateGuild( messageStore, existingUserIds, guildId, messageChannelId, updateMockGuild, null, out guildTextChannel); mockCommandContext .Setup(context => context.User) .Returns(CreateGuildUser(userId)); mockCommandContext .Setup(context => context.Channel) .Returns(guildTextChannel); mockCommandContext .Setup(context => context.Guild) .Returns(guild); return(mockCommandContext.Object); }
private void CreateHandler( out MessageHandler handler, out GameState state, out IGuildUser playerUser, out IGuildUser readerUser, out IGuildTextChannel channel, out MessageStore messageStore) { messageStore = new MessageStore(); IDatabaseActionFactory dbActionFactory = CommandMocks.CreateDatabaseActionFactory( this.botConfigurationfactory); IOptionsMonitor <BotConfiguration> options = CommandMocks.CreateConfigurationOptionsMonitor(); handler = new MessageHandler( options, dbActionFactory, CommandMocks.CreateHubContext(), new Mock <ILogger>().Object); playerUser = CommandMocks.CreateGuildUser(DefaultPlayerId); readerUser = CommandMocks.CreateGuildUser(DefaultReaderId); CommandMocks.CreateGuild( messageStore, DefaultIds, DefaultGuildId, DefaultChannelId, (mockGuild, textChannel) => { Mock <IVoiceChannel> mockVoiceChannel = new Mock <IVoiceChannel>(); mockVoiceChannel.Setup(voiceChannel => voiceChannel.Id).Returns(DefaultVoiceChannelId); mockVoiceChannel.Setup(voiceChannel => voiceChannel.Name).Returns("Voice"); 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)); }, null, out channel); state = new GameState() { ReaderId = DefaultReaderId, TeamManager = new ByCommandTeamManager() }; }
public static IGuild CreateGuild( MessageStore messageStore, HashSet <ulong> existingUserIds, ulong guildId, ulong messageChannelId, Action <Mock <IGuild>, IGuildTextChannel> updateMockGuild, Action <Mock <IGuildTextChannel> > updateMockTextChannel, out IGuildTextChannel channel) { Mock <IGuild> mockGuild = new Mock <IGuild>(); mockGuild .Setup(guild => guild.GetUserAsync(It.IsAny <ulong>(), It.IsAny <CacheMode>(), It.IsAny <RequestOptions>())) .Returns <ulong, CacheMode, RequestOptions>((id, cacheMode, requestOptions) => { if (existingUserIds?.Contains(id) == true) { return(Task.FromResult(CreateGuildUser(id))); } return(Task.FromResult <IGuildUser>(null)); }); mockGuild.Setup(guild => guild.Id).Returns(guildId); mockGuild .Setup(guild => guild.GetUsersAsync(It.IsAny <CacheMode>(), It.IsAny <RequestOptions>())) .Returns <CacheMode, RequestOptions>((cacheMode, requestOptions) => { IReadOnlyCollection <IGuildUser> users = existingUserIds.Select(id => CreateGuildUser(id)).ToList(); return(Task.FromResult(users)); }); Mock <IGuildUser> mockBotUser = new Mock <IGuildUser>(); mockBotUser .Setup(user => user.GetPermissions(It.IsAny <IGuildChannel>())) .Returns(new ChannelPermissions(viewChannel: true, sendMessages: true, embedLinks: true, attachFiles: true)); mockGuild .Setup(guild => guild.GetCurrentUserAsync(It.IsAny <CacheMode>(), It.IsAny <RequestOptions>())) .Returns(Task.FromResult(mockBotUser.Object)); IGuild guild = mockGuild.Object; channel = CreateGuildTextChannel(messageStore, guild, messageChannelId, updateMockTextChannel); updateMockGuild?.Invoke(mockGuild, channel); return(guild); }
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); }