コード例 #1
0
        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);
        }
コード例 #2
0
        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>>())
            //);
        }
コード例 #3
0
        public void ShouldSetDefaultCooldownTimeIsMissingInConfiguration()
        {
            var sut = new FritzBot(_config.Object, _serviceProvider.Object);

            Task.WaitAll(sut.StartAsync(new CancellationToken()));

            Assert.Equal(TimeSpan.Zero, sut.CooldownTime);
        }
コード例 #4
0
        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);
        }
コード例 #5
0
		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);
コード例 #6
0
		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);
		}
コード例 #7
0
        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);
        }
コード例 #8
0
        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);
        }
コード例 #9
0
        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);
        }
コード例 #10
0
        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));
        }
コード例 #11
0
        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);
        }
コード例 #12
0
        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);
        }