Ejemplo n.º 1
0
 private async IAsyncEnumerable <ResponseMessage> ListHandler(IncomingMessage message, IValidHandle matchedHandle)
 {
     foreach (var entry in _karmaRepositoryPlugin.GetTop(_karmaPlugin.ParseNumberFromEndOfRequest(message.FullText)))
     {
         yield return(message.ReplyToChannel(_karmaPlugin.GenerateCurrentKarmaMessage(entry)));
     }
 }
        public void WhenNameIncludesUnderscore_ShouldDisplaySpaceInPlaceOfUnderscore()
        {
            string      expected = ":downboat: Bob Ross: -1";
            KarmaPlugin plugin   = new KarmaPlugin();

            ChangeRequest testChangeRequest = new ChangeRequest("Bob_Ross", -1);
            var           result            = plugin.GenerateCurrentKarmaMessage(testChangeRequest, -1);

            Assert.Equal(expected, result);
        }
        public void WhenNegativeChange_ShouldgenerateDownboatMessage()
        {
            string      expected = $":downboat: {_testName}: -1";
            KarmaPlugin plugin   = new KarmaPlugin();

            ChangeRequest testChangeRequest = new ChangeRequest(_testName, -1);
            var           result            = plugin.GenerateCurrentKarmaMessage(testChangeRequest, -1);

            Assert.Equal(expected, result);
        }
        public void WhenPositiveChange_ShouldGenerateUpboatMessage()
        {
            string      expected = $":upboat: {_testName}: 1";
            KarmaPlugin plugin   = new KarmaPlugin();

            ChangeRequest testChangeRequest = new ChangeRequest(_testName, 1);
            var           result            = plugin.GenerateCurrentKarmaMessage(testChangeRequest, 1);

            Assert.Equal(expected, result);
        }
        public void GivenEntry_WhenNameIncludesUnderscore_ShouldDisplaySpaceInPlaceOfUnderscore()
        {
            string      expected = "Bob Ross: -1";
            KarmaPlugin plugin   = new KarmaPlugin();

            var testEntry = new Entry("Bob_Ross", -1);
            var result    = plugin.GenerateCurrentKarmaMessage(testEntry);

            Assert.Equal(expected, result);
        }
        public void GivenEntry_ShouldGenerateMessage()
        {
            string      expected = "test: 9";
            KarmaPlugin plugin   = new KarmaPlugin();

            var testEntry = new Entry(_testName, 9);
            var result    = plugin.GenerateCurrentKarmaMessage(testEntry);

            Assert.Equal(expected, result);
        }
        public void WhenReasonIncluded_ShouldAddReasonToMessage()
        {
            string expected = ":upboat: BobRoss: 1 for test";
            var    plugin   = new KarmaPlugin();

            ChangeRequest testChangeRequest = new ChangeRequest("BobRoss", 1, "for test");
            var           result            = plugin.GenerateCurrentKarmaMessage(testChangeRequest, 1);

            Assert.Equal(expected, result);
        }
Ejemplo n.º 8
0
 private ResponseMessage HandleKarmaChange(IncomingMessage message, ChangeRequest changeRequest)
 {
     try
     {
         _karmaRepositoryPlugin.Update(changeRequest);
         var currentKarma = _karmaRepositoryPlugin.Get(changeRequest.Name);
         return(message.ReplyToChannel(_karmaPlugin.GenerateCurrentKarmaMessage(changeRequest, currentKarma)));
     }
     catch (Exception e)
     {
         return(ResponseMessage.ChannelMessage("bots", e.Message + "\n" + e.StackTrace, new List <Attachment>()));
     }
 }