public async Task ValidParameter_Should_ChangeChatConfig_And_ReplyMessage(GrammarAlgorithms algorithmParameter) { // Arrange var channelConfigurationServiceMock = new Mock <IDiscordChannelConfigService>(); var command = new SetAlgorithmCommand(channelConfigurationServiceMock.Object); const string replyMessage = "Algorithm updated"; var chatConfig = new DiscordChannelConfig { GrammarAlgorithm = GrammarAlgorithms.YandexSpellerApi }; 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.SetAlgorithm} {(int)algorithmParameter}"); 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 "Algorithm updated" channelMock.Verify(v => v.SendMessageAsync(null, false, It.Is <Embed>(e => e.Description.Contains(replyMessage)), null, null, null, null, null, null, MessageFlags.None)); Assert.Equal(algorithmParameter, chatConfig.GrammarAlgorithm); }
public async Task ParameterNotReceived_Should_ReplyMessage() { // Arrange var channelConfigurationServiceMock = new Mock <IDiscordChannelConfigService>(); var command = new SetAlgorithmCommand(channelConfigurationServiceMock.Object); const string replyMessage = "Parameter not received"; var chatConfig = new DiscordChannelConfig { GrammarAlgorithm = GrammarAlgorithms.InternalAlgorithm }; 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.SetAlgorithm); 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)); Assert.Equal(GrammarAlgorithms.InternalAlgorithm, chatConfig.GrammarAlgorithm); // Make sure SelectedLanguage is still Auto }
public async Task ParameterIsNotNumber_Should_ReplyMessage(string parameter) { // Arrange var chatConfigurationServiceMock = new Mock <IChatConfigurationService>(); var telegramBotClientMock = new Mock <ITelegramBotClientWrapper>(); var command = new SetAlgorithmCommand(chatConfigurationServiceMock.Object, telegramBotClientMock.Object); const string replyMessage = "Invalid parameter"; var chatConfig = new ChatConfiguration { GrammarAlgorithm = GrammarAlgorithms.LanguageToolApi }; var message = new Message { Text = $"{TelegramBotCommands.SetAlgorithm} {parameter}", 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 } } });