예제 #1
0
        public void WhenUsingNegativeKarmaOperator_ShouldHaveChangeAmoutNegativeOne()
        {
            var plugin = new KarmaPlugin();

            var result = plugin.ParseKarmaChange("test--");

            Assert.Equal(-1, result.Amount);
        }
예제 #2
0
        public void WhenGeneratingChangeRequest_ShouldNotIncludeOperator()
        {
            var expected = "test";
            var plugin   = new KarmaPlugin();

            var result = plugin.ParseKarmaChange("test++");

            Assert.Equal(expected, result.Name);
        }
예제 #3
0
        private IEnumerable <ResponseMessage> KarmaHandler(IncomingMessage message, IValidHandle matchedHandle)
        {
            var matches = _karmaPlugin.GetMessageMatches(message.FullText);

            foreach (Match match in matches)
            {
                var changeRequest = _karmaPlugin.ParseKarmaChange(match.Value);
                yield return(HandleKarmaChange(message, changeRequest));
            }
        }
예제 #4
0
        private async IAsyncEnumerable <ResponseMessage> KarmaHandler(IncomingMessage message, IValidHandle matchedHandle)
        {
            var operatorMatches = _karmaPlugin.GetOperatorMatchesInMessage(message.FullText);
            var reasonMatches   = _karmaPlugin.GetReasonMatchesInMessage(message.FullText);

            operatorMatches = operatorMatches.Where(x => reasonMatches.All(y => y.Index != x.Index)).ToList();

            foreach (Match match in operatorMatches)
            {
                var changeRequest = _karmaPlugin.ParseKarmaChange(match.Value);
                yield return(HandleKarmaChange(message, changeRequest));
            }
            foreach (Match match in reasonMatches)
            {
                var changeRequest = _karmaPlugin.ParseKarmaChangeWithReason(match.Value);
                yield return(HandleKarmaChange(message, changeRequest));
            }
        }