public async Task CanSetUserWithReaderRoleAsNewReader() { using (BotConfigurationContext context = this.botConfigurationfactory.Create()) using (DatabaseAction action = new DatabaseAction(context)) { await action.SetReaderRolePrefixAsync(DefaultGuildId, "Reader"); } ulong newReaderId = GetExistingNonReaderUserId(); string newReaderMention = $"@User_{newReaderId}"; this.CreateHandler( out ReaderCommandHandler handler, out GameState currentGame, out MessageStore messageStore); currentGame.ReaderId = DefaultReaderId; Mock <IGuildUser> mockUser = new Mock <IGuildUser>(); mockUser.Setup(user => user.Id).Returns(newReaderId); mockUser.Setup(user => user.Mention).Returns(newReaderMention); mockUser.Setup(user => user.RoleIds).Returns(new ulong[] { DefaultReaderRoleId }); await handler.SetNewReaderAsync(mockUser.Object); Assert.AreEqual(newReaderId, currentGame.ReaderId, "Reader ID was not set correctly."); Assert.AreEqual(1, messageStore.ChannelMessages.Count, "Unexpected number of messages sent."); string expectedMessage = $"{newReaderMention} is now the reader."; messageStore.VerifyChannelMessages(expectedMessage); }
private async Task SetRostersFromRolesForGoogleSheetsWithBadUrlFails( GoogleSheetsType type, Func <string, Task> setRosters) { Mock <IGoogleSheetsGenerator> mockGenerator = new Mock <IGoogleSheetsGenerator>(); mockGenerator .Setup(generator => generator.TryUpdateRosters(It.IsAny <IByRoleTeamManager>(), It.IsAny <Uri>())) .Returns(Task.FromResult <IResult <string> >(new SuccessResult <string>(string.Empty))); Mock <IGoogleSheetsGeneratorFactory> mockFactory = new Mock <IGoogleSheetsGeneratorFactory>(); mockFactory .Setup(factory => factory.Create(type)) .Returns(mockGenerator.Object); this.InitializeHandler(googleSheetsGeneratorFactory: mockFactory.Object); using (BotConfigurationContext context = this.botConfigurationfactory.Create()) using (DatabaseAction action = new DatabaseAction(context)) { await action.SetTeamRolePrefixAsync(DefaultGuildId, TeamRolePrefix); } await setRosters("this URL does not parse"); this.MessageStore.VerifyChannelMessages( "The link to the Google Sheet wasn't understandable. Be sure to copy the full URL from the address bar."); mockFactory.Verify(factory => factory.Create(It.IsAny <GoogleSheetsType>()), Times.Never); }
private async Task SetRostersFromRolesForGoogleSheetsSucceeds( GoogleSheetsType type, Func <string, Task> setRosters) { Mock <IGoogleSheetsGenerator> mockGenerator = new Mock <IGoogleSheetsGenerator>(); mockGenerator .Setup(generator => generator.TryUpdateRosters(It.IsAny <IByRoleTeamManager>(), It.IsAny <Uri>())) .Returns(Task.FromResult <IResult <string> >(new SuccessResult <string>(string.Empty))) .Verifiable(); Mock <IGoogleSheetsGeneratorFactory> mockFactory = new Mock <IGoogleSheetsGeneratorFactory>(); mockFactory .Setup(factory => factory.Create(type)) .Returns(mockGenerator.Object); this.InitializeHandler(googleSheetsGeneratorFactory: mockFactory.Object); using (BotConfigurationContext context = this.botConfigurationfactory.Create()) using (DatabaseAction action = new DatabaseAction(context)) { await action.SetTeamRolePrefixAsync(DefaultGuildId, TeamRolePrefix); } await setRosters("http://localhost/sheetsUrl"); mockFactory.Verify(); this.MessageStore.VerifyChannelMessages("Rosters updated."); }
public void InitializeTest() { this.botConfigurationfactory = new InMemoryBotConfigurationContextFactory(); // Make sure the database is initialized before running the test using (BotConfigurationContext context = this.botConfigurationfactory.Create()) { context.Database.Migrate(); } }
public async Task PairNewChannelAndUpdateChannel() { const ulong textChannelId = 12345; const ulong voiceChannelId = 123456; const ulong newVoiceChannelId = 123567; using (InMemoryBotConfigurationContextFactory factory = new InMemoryBotConfigurationContextFactory()) using (BotConfigurationContext context = factory.Create()) using (DatabaseAction action = new DatabaseAction(context)) { await action.MigrateAsync(); await action.PairChannelsAsync(guildId, new (ulong, ulong)[] { (textChannelId, voiceChannelId) });
public async Task DisableBonusesByDefault() { this.InitializeHandler(); // Enable, then disable the bonuses using (BotConfigurationContext context = this.botConfigurationfactory.Create()) using (DatabaseAction action = new DatabaseAction(context)) { await action.SetUseBonuses(DefaultGuildId, true); } await this.Handler.GetDefaultFormatAsync(); Assert.AreEqual( 1, this.MessageStore.ChannelEmbeds.Count, "Unexpected number of messages after getting the default format"); string getEmbed = this.MessageStore.ChannelEmbeds[0]; Assert.IsTrue( getEmbed.Contains("Require scoring bonuses?: Yes", StringComparison.InvariantCulture), $"Enabled setting not in message \"{getEmbed}\""); this.MessageStore.Clear(); await this.Handler.DisableBonusesByDefaultAsync(); Assert.AreEqual( 1, this.MessageStore.ChannelMessages.Count, "Unexpected number of messages after disabling bonuses"); string setMessage = this.MessageStore.ChannelMessages[0]; Assert.AreEqual( "Scoring bonuses will no longer be enabled for every game in this server.", setMessage, "Unexpected message when enabled"); this.MessageStore.Clear(); await this.Handler.GetDefaultFormatAsync(); Assert.AreEqual( 1, this.MessageStore.ChannelEmbeds.Count, "Unexpected number of messages after getting the default format after disabling bonuses"); getEmbed = this.MessageStore.ChannelEmbeds[0]; Assert.IsTrue( getEmbed.Contains("Require scoring bonuses?: No", StringComparison.InvariantCulture), $"Disabled setting not in message \"{getEmbed}\""); }
public void InitializeTest() { this.botConfigurationfactory = new InMemoryBotConfigurationContextFactory(); // Make sure the database is initialized before running the test using (BotConfigurationContext context = this.botConfigurationfactory.Create()) { context.Database.Migrate(); } // Clear out the old fields this.Handler = null; this.GoogleSheetsGeneratorFactory = null; this.GuildTextChannel = null; this.MessageStore = null; }
public async Task EnableBuzzQueue() { this.InitializeHandler(); // Enable, then disable the buzz queue using (BotConfigurationContext context = this.botConfigurationfactory.Create()) using (DatabaseAction action = new DatabaseAction(context)) { await action.SetDisableBuzzQueueAsync(DefaultGuildId, true); } await this.Handler.GetDefaultFormatAsync(); Assert.AreEqual( 1, this.MessageStore.ChannelEmbeds.Count, "Unexpected number of messages after getting the default format"); string getEmbed = this.MessageStore.ChannelEmbeds[0]; Assert.IsTrue( getEmbed.Contains("Queue buzzes?: No", StringComparison.InvariantCulture), $"Disabled setting not in message \"{getEmbed}\""); this.MessageStore.Clear(); await this.Handler.EnableBuzzQueueAsync(); Assert.AreEqual( 1, this.MessageStore.ChannelMessages.Count, "Unexpected number of messages after disabling the buzz queue"); string setMessage = this.MessageStore.ChannelMessages[0]; Assert.IsTrue( setMessage.StartsWith("The buzz queue is enabled for future games.", StringComparison.InvariantCulture), $@"Couldn't find correct prefix in message ""{setMessage}"""); this.MessageStore.Clear(); await this.Handler.GetDefaultFormatAsync(); Assert.AreEqual( 1, this.MessageStore.ChannelEmbeds.Count, "Unexpected number of messages after enabling the buzz queue"); getEmbed = this.MessageStore.ChannelEmbeds[0]; Assert.IsTrue( getEmbed.Contains("Queue buzzes?: Yes", StringComparison.InvariantCulture), $"Enabled setting not in message \"{getEmbed}\""); }
public async Task UnbanUser() { const ulong bannedUser = 123; this.CreateHandler(out BotOwnerCommandHandler handler, out MessageStore messageStore); using (BotConfigurationContext context = this.botConfigurationfactory.Create()) using (DatabaseAction action = new DatabaseAction(context)) { await action.AddCommandBannedUser(bannedUser); } await handler.UnbanUserAsync(bannedUser); using (BotConfigurationContext context = this.botConfigurationfactory.Create()) using (DatabaseAction action = new DatabaseAction(context)) { bool banned = await action.GetCommandBannedAsync(bannedUser); Assert.IsFalse(banned, "User should be unbanned"); } }
public async Task DisableBonusesSucceedsIfEnableBonusSetByDefault() { this.CreateHandler( out ReaderCommandHandler handler, out GameState currentGame, out MessageStore messageStore); currentGame.Format = Format.TossupBonusesShootout; using (BotConfigurationContext context = this.botConfigurationfactory.Create()) using (DatabaseAction action = new DatabaseAction(context)) { await action.SetUseBonuses(DefaultGuildId, true); } await handler.DisableBonusesAsync(); Assert.AreEqual(1, messageStore.ChannelMessages.Count, "Unexpected number of channel messages."); string message = messageStore.ChannelMessages.First(); Assert.AreEqual( "Bonuses are no longer being tracked for this game only. Run !disableBonusesAlways to stop tracking bonuses on this server by default.", message, $"Unexpected message"); Assert.AreEqual(Format.TossupShootout, currentGame.Format, "Unexpected format"); }