public async Task WordExist_Should_RemoveWordFromWhiteList_And_ReplyMessage(string existingWord, string wordToRemove) { // Arrange var channelConfigurationServiceMock = new Mock <IDiscordChannelConfigService>(); var command = new RemoveWhiteListCommand(channelConfigurationServiceMock.Object); const string replyMessage = "removed from the WhiteList"; var chatConfig = new DiscordChannelConfig { WhiteListWords = new() { existingWord } }; var channelMock = new Mock <IMessageChannel>(); var user = new Mock <IGuildUser>(); user.Setup(v => v.GuildPermissions).Returns(GuildPermissions.All); var message = new Mock <IMessage>(); message.Setup(v => v.Content).Returns($"{DiscordBotCommands.RemoveWhiteList} {wordToRemove}"); message.Setup(v => v.Author).Returns(user.Object); message.Setup(v => v.Channel).Returns(channelMock.Object); channelConfigurationServiceMock.Setup(v => v.GetConfigurationByChannelId(message.Object.Channel.Id)) .ReturnsAsync(chatConfig); // Act await command.Handle(message.Object); // Assert // Verify SendMessageAsync was called with the reply message "added to the WhiteList" channelMock.Verify(v => v.SendMessageAsync(null, false, It.Is <Embed>(e => e.Description.Contains(replyMessage)), null, null, null, null, null, null, MessageFlags.None)); Assert.Empty(chatConfig.WhiteListWords); } }
public async Task NoParameter_Should_ReplyMessage() { // Arrange var chatConfigurationServiceMock = new Mock <IChatConfigurationService>(); var telegramBotClientMock = new Mock <ITelegramBotClientWrapper>(); var command = new RemoveWhiteListCommand(chatConfigurationServiceMock.Object, telegramBotClientMock.Object); const string replyMessage = "Parameter not received"; var chatConfig = new ChatConfiguration { WhiteListWords = null }; var message = new Message { Text = TelegramBotCommands.RemoveWhiteList, From = new User { Id = 2 }, Chat = new Chat { Id = 1, Type = ChatType.Group } }; telegramBotClientMock.Setup(v => v.GetChatAdministratorsAsync(message.Chat.Id, default)) .ReturnsAsync(new[] { new ChatMemberMember { User = new() { Id = message.From.Id } } });
public async Task NoParameter_Should_ReplyMessage() { // Arrange var channelConfigurationServiceMock = new Mock <IDiscordChannelConfigService>(); var command = new RemoveWhiteListCommand(channelConfigurationServiceMock.Object); const string replyMessage = "Parameter not received"; var chatConfig = new DiscordChannelConfig { WhiteListWords = new() { "Word" } }; var channelMock = new Mock <IMessageChannel>(); var user = new Mock <IGuildUser>(); user.Setup(v => v.GuildPermissions).Returns(GuildPermissions.All); var message = new Mock <IMessage>(); message.Setup(v => v.Content).Returns(DiscordBotCommands.AddWhiteList); message.Setup(v => v.Author).Returns(user.Object); message.Setup(v => v.Channel).Returns(channelMock.Object); channelConfigurationServiceMock.Setup(v => v.GetConfigurationByChannelId(message.Object.Channel.Id)) .ReturnsAsync(chatConfig); // Act await command.Handle(message.Object); // Assert // Verify SendMessageAsync was called with the reply message "Parameter not received" channelMock.Verify(v => v.SendMessageAsync(null, false, It.Is <Embed>(e => e.Description.Contains(replyMessage)), null, null, null, null, null, null, MessageFlags.None)); }