public void ShouldIgnoreCommandsToFastIfModerator() { var sut = new FritzBot(_config.Object, _serviceProvider.Object, _loggerFactory.Object); Task.WaitAll(sut.StartAsync(new CancellationToken())); var args = new ChatMessageEventArgs { Message = "!help", ServiceName = "TestService", UserName = "******", IsModerator = true, IsOwner = false }; _chatservice.Raise(cs => cs.ChatMessage += null, args); _chatservice.Raise(cs => cs.ChatMessage += null, args); var verifyTimes = Moq.Times.Once(); #if !DEBUG verifyTimes = Moq.Times.Exactly(2); #endif _chatservice.Verify(sm => sm.SendMessageAsync( It.Is <string>(x => x.StartsWith("Supported commands:"))), verifyTimes); }
public void ShouldLogIfCommandsToFast() { var sut = new FritzBot(_config.Object, _serviceProvider.Object, _loggerFactory.Object); Task.WaitAll(sut.StartAsync(new CancellationToken())); var args = new ChatMessageEventArgs { Message = "!help", ServiceName = "TestService", UserName = "******", IsModerator = false, IsOwner = false, }; _chatservice.Raise(cs => cs.ChatMessage += null, args); _chatservice.Raise(cs => cs.ChatMessage += null, args); const string expectWarning = "Ignoring command help from testusername on TestService. Cooldown active"; //_logger.Verify( // m => m.Log( // LogLevel.Warning, // It.IsAny<EventId>(), // //It.Is<FormattedLogValues>(v => v.ToString().Contains(expectWarning)), // It.IsAny<Exception>(), // It.IsAny<Func<object, Exception, string>>()) //); }
public void ShouldSetDefaultCooldownTimeIsMissingInConfiguration() { var sut = new FritzBot(_config.Object, _serviceProvider.Object); Task.WaitAll(sut.StartAsync(new CancellationToken())); Assert.Equal(TimeSpan.Zero, sut.CooldownTime); }
public void ShouldSetCooldownTimeWhenSetInConfiguration(int cooldownTime) { _config.SetupGet(s => s[FritzBot.ConfigurationRoot + ":CooldownTime"]).Returns(cooldownTime.ToString()); var sut = new FritzBot(_config.Object, _serviceProvider.Object); Task.WaitAll(sut.StartAsync(new CancellationToken())); Assert.Equal(TimeSpan.Parse(cooldownTime.ToString()), sut.CooldownTime); }
public void ShouldReturnHelpMessage() { var sut = new FritzBot(_config.Object, _serviceProvider.Object, _loggerFactory.Object); Task.WaitAll(sut.StartAsync(new CancellationToken())); var args = new ChatMessageEventArgs { Message = "!help", UserName = "******", IsModerator = false, IsOwner = false }; _chatservice.Raise(cs => cs.ChatMessage += null, args); _chatservice.Verify(sm => sm.SendMessageAsync( <<<<<<< HEAD It.Is<string>(x => x.Contains("Supported commands: "))), Times.AtLeastOnce);
public void ShouldReturnEchoMessage() { var sut = new FritzBot(_config.Object, _serviceProvider.Object, _loggerFactory.Object); Task.WaitAll(sut.StartAsync(new CancellationToken())); var args = new ChatMessageEventArgs { Message = "!echo Test Message", UserName = "******", IsModerator = false, IsOwner = false }; _chatservice.Raise(cs => cs.ChatMessage += null, args); _chatservice.Verify(sm => sm.SendWhisperAsync( It.IsAny<string>() , It.Is<string>(x => x.StartsWith("Echo reply: Test Message"))), Times.AtLeastOnce); }
public void ShouldInvokeExtendedCommand() { var sut = new FritzBot(_config.Object, _serviceProvider.Object); Task.WaitAll(sut.StartAsync(new CancellationToken())); var args = new ChatMessageEventArgs { Message = "FakeExtendedCommand", UserName = "******" }; _chatservice.Raise(cs => cs.ChatMessage += null, args); _chatservice.Verify(sm => sm.SendWhisperAsync( It.IsAny <string>(), It.Is <string>(x => x.Equals(_extendedCommand.ExecutedAnswer))), Times.Once); }
public void ShouldReturnInfoWhenTryInvokeNonRegisterCommand() { var sut = new FritzBot(_config.Object, _serviceProvider.Object); Task.WaitAll(sut.StartAsync(new CancellationToken())); var args = new ChatMessageEventArgs { Message = "!SpecialNonExistingCommand", UserName = "******" }; _chatservice.Raise(cs => cs.ChatMessage += null, args); _chatservice.Verify(sm => sm.SendWhisperAsync( It.IsAny <string>(), It.Is <string>(x => x.Equals(FritzBot.UnknownCommandMessage))), Times.Once); }
public void ShouldReturnLinkTitle() { var sut = new FritzBot(_config.Object, _serviceProvider.Object, _loggerFactory.Object); Task.WaitAll(sut.StartAsync(new CancellationToken())); var args = new ChatMessageEventArgs { Message = "Hey! Check this link: www.google.com", UserName = "******", IsModerator = false, IsOwner = false }; _chatservice.Raise(cs => cs.ChatMessage += null, args); _chatservice.Verify(sm => sm.SendMessageAsync( It.Is <string>(x => x.StartsWith("testusername's linked page title:"))), Times.Once); }
public void ShouldIgnoreCooldownIfSendByModerator() { var sut = new FritzBot(_config.Object, _serviceProvider.Object); Task.WaitAll(sut.StartAsync(new CancellationToken())); var args = new ChatMessageEventArgs { Message = "!FakeCooldownBasicCommand", UserName = "******", IsModerator = true }; _chatservice.Raise(cs => cs.ChatMessage += null, args); _chatservice.Raise(cs => cs.ChatMessage += null, args); _chatservice.Verify(sm => sm.SendWhisperAsync( It.IsAny <string>(), It.Is <string>(x => x.Equals(_basicCommandWithCooldown.ExecutedAnswer))), Times.Exactly(2)); }
public void ShouldReturnHelpSkeetMessage() { var sut = new FritzBot(_config.Object, _serviceProvider.Object, _loggerFactory.Object); Task.WaitAll(sut.StartAsync(new CancellationToken())); var command = "skeet"; var args = new ChatMessageEventArgs { Message = $"!help {command}", UserName = "******", IsModerator = false, IsOwner = false }; var description = new SkeetCommand().Description; _chatservice.Raise(cs => cs.ChatMessage += null, args); _chatservice.Verify(sm => sm.SendMessageAsync( It.Is <string>(x => x.StartsWith($"{command}: {description}"))), Times.AtLeastOnce); }
public void ShouldInovkeOnlyFinalExtendedCommandIfBasicCommandPatternAlsoMatch() { var sut = new FritzBot(_config.Object, _serviceProvider.Object); Task.WaitAll(sut.StartAsync(new CancellationToken())); var args = new ChatMessageEventArgs { Message = "!FakeExtendedCommandWithFinal", UserName = "******" }; _chatservice.Raise(cs => cs.ChatMessage += null, args); _chatservice.Verify(sm => sm.SendWhisperAsync( It.IsAny <string>(), It.Is <string>(x => x.Equals(_finalBasicCommandWithExtendedCommandPattern.ExecutedAnswer))), Times.Never); _chatservice.Verify(sm => sm.SendWhisperAsync( It.IsAny <string>(), It.Is <string>(x => x.Equals(_finalExtendedCommand.ExecutedAnswer))), Times.Once); }