コード例 #1
0
        public void IRC_CloneMessage_WithMessage_UsesNewMessage()
        {
            const string user    = "******";
            const string message = "test";

            var ircMessage = new IrcMessage(message, "#calledude", new User(user, true));

            const string expectedContent = "hello";
            var          clonedMessage   = ircMessage.CloneWithMessage(expectedContent);

            Assert.Equal(expectedContent, clonedMessage.Content);
            Assert.Equal(ircMessage.Channel, clonedMessage.Channel);
            Assert.Equal(ircMessage.Sender, clonedMessage.Sender);
        }
コード例 #2
0
        public async Task Mods_Only_Evaluates_Once_Per_Context()
        {
            var fakeCommands = Enumerable
                               .Range(1, 10)
                               .Select(x =>
            {
                var cmdMock = new Mock <SpecialCommand <CommandParameter> >();

                cmdMock
                .SetupGet(x => x.RequiresMod)
                .Returns(true);

                cmdMock
                .SetupGet(x => x.Name)
                .Returns("!" + x);

                return(cmdMock.Object);
            })
                               .Cast <Command>();

            var commandContainer = new Lazy <CommandContainer>(new CommandContainer(fakeCommands));

            var botMock = new Mock <IMessageBot <IrcMessage> >();
            var logger  = new Logger <CommandHandler <IrcMessage> >(NullLoggerFactory.Instance);
            var twitchCommandHandler = new CommandHandler <IrcMessage>(logger, botMock.Object, commandContainer);

            var message = new IrcMessage(
                "",
                "",
                new User("", () =>
            {
                _counter++;
                return(Task.FromResult(true));
            }));

            var commandExecutions = fakeCommands.Select(x =>
            {
                message = message.CloneWithMessage(x.Name);
                return(twitchCommandHandler.Handle(message, CancellationToken.None));
            });

            await Task.WhenAll(commandExecutions);

            Assert.Equal(1, _counter);
        }