示例#1
0
        public async Task AcceptDefaultCommandFromDynamicPrefixAsync()
        {
            var trigger     = new DynamicPrefixTrigger("test.");
            var mockContext = new TestContextObject();

            mockContext.SetService(typeof(DbContext), NewDbContext());
            mockContext.SetService(
                typeof(ICacheClient), new InMemoryCacheClient(new ProtobufSerializer()));

            var mockMessage = new Mock <ITestDiscordMessage>();

            mockMessage.Setup(x => x.Id).Returns(0L);
            mockContext.SetContext(CorePipelineStage.MessageContextKey, mockMessage.Object);
            mockContext.SetContext(CorePipelineStage.QueryContextKey, "test.command");

            var result = await trigger.CheckTriggerAsync(mockContext)
                         .ConfigureAwait(false);

            Assert.Equal("test.", result);
        }
示例#2
0
        public async Task MentionTriggerDoesTriggerAsync()
        {
            var mention = "<@12065984510520>";
            var trigger = new MentionTrigger();
            var mock    = new TestContextObject();

            mock.SetContext(CorePipelineStage.QueryContextKey, mention + " test");

            var selfUserMock = new Mock <IDiscordSelfUser>();

            selfUserMock.Setup(x => x.Id).Returns(12065984510520);

            var clientMock = new Mock <IDiscordClient>();

            clientMock.Setup(x => x.GetSelfAsync())
            .Returns(Task.FromResult(selfUserMock.Object));
            mock.SetService(typeof(IDiscordClient), clientMock.Object);

            var result = await trigger.CheckTriggerAsync(mock)
                         .ConfigureAwait(false);

            Assert.Equal(mention, result);
        }