public void ShouldGetKarmaEntryNameFromReasonRequest(string request, string expected) { var plugin = new KarmaPlugin(); string result = plugin.ParseNameFromReasonRequest(request); Assert.Equal(expected, result); }
public KarmaMiddleware(IMiddleware next, KarmaRepositoryPlugin karmaRepositoryPlugin, KarmaPlugin karmaPlugin) : base(next) { _karmaRepositoryPlugin = karmaRepositoryPlugin; _karmaPlugin = karmaPlugin; HandlerMappings = new[] { new HandlerMapping { ValidHandles = RegexHandle.For(KarmaPlugin.OperatorRegex), Description = "Allows upvoting and downvoting on things and people with `--` and `++`.", EvaluatorFunc = KarmaHandler, MessageShouldTargetBot = false, VisibleInHelp = false }, new HandlerMapping { ValidHandles = RegexHandle.For(KarmaPlugin.ListKarmaRegex), Description = "List recorded karma", EvaluatorFunc = ListHandler, MessageShouldTargetBot = true, VisibleInHelp = true }, new HandlerMapping { ValidHandles = RegexHandle.For(KarmaPlugin.ListReasonRegex), Description = "List reasons for a karma entry", EvaluatorFunc = ReasonHandler, MessageShouldTargetBot = true, VisibleInHelp = true } }; }
public void WhenUsingNegativeKarmaOperator_ShouldHaveChangeAmoutNegativeOne() { var plugin = new KarmaPlugin(); var result = plugin.ParseKarmaChange("test--"); Assert.Equal(-1, result.Amount); }
public void GivenReasonRequest_ShouldReturnNumber(string input, int expected) { var plugin = new KarmaPlugin(); var result = plugin.ParseNumberFromEndOfRequest(input); Assert.Equal(expected, result); }
public void WhenGeneratingChangeRequest_ShouldNotIncludeOperator() { string expected = "test"; var plugin = new KarmaPlugin(); var result = plugin.ParseKarmaChangeWithReason("test++ for test"); Assert.Equal(expected, result.Name); }
public void WhenUsingPositiveKarmaOperator_ShouldHaveChangeAmoutOne() { var plugin = new KarmaPlugin(); var result = plugin.ParseKarmaChangeWithReason("test++ for test"); Assert.Equal(1, result.Amount); }
public void WhenNoNumberGiven_ShouldDefaultToTen() { var input = "@termibot karma list"; var plugin = new KarmaPlugin(); int result = plugin.ParseNumberFromEndOfRequest(input); Assert.Equal(10, result); }
public void WhenZeroGivenShouldReturnDefault() { var input = "@termibot karma list 0"; var plugin = new KarmaPlugin(); int result = plugin.ParseNumberFromEndOfRequest(input); Assert.Equal(10, result); }
public void WhenNumberGiven_ShouldReturnNumber(string inputNumber, int expected) { var input = $"@termibot karma list {inputNumber}"; var plugin = new KarmaPlugin(); var result = plugin.ParseNumberFromEndOfRequest(input); Assert.Equal(expected, result); }
public void WhenChangeNegative_ShouldUseDownboat(string name, string reasonValue, string expected) { Reason reason = new Reason(name, -1, reasonValue); var plugin = new KarmaPlugin(); string result = plugin.GenerateReasonMessage(reason); Assert.Equal(expected, result); }
public void ShouldReturnReason(string name, string reasonValue, string expected) { Reason reason = new Reason(name, 1, reasonValue); var plugin = new KarmaPlugin(); string result = plugin.GenerateReasonMessage(reason); Assert.Equal(expected, result); }
public void ShouldFillReasonField() { string expected = "for test"; var plugin = new KarmaPlugin(); var result = plugin.ParseKarmaChangeWithReason("test-- for test"); Assert.Equal(expected, result.Reason); }
public void ShouldNotMatchInvalidReasonInputs(string input) { int expectedCount = 0; var plugin = new KarmaPlugin(); var matches = plugin.GetReasonMatchesInMessage(input); int numberOfMatches = matches.Count; Assert.Equal(expectedCount, numberOfMatches); }
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 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 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 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 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 ShouldNotMatchInvalidInputs(string input) { int expected = 0; var plugin = new KarmaPlugin(); var matches = plugin.GetMessageMatches(input); int numberOfMatches = matches.Count; Assert.Equal(expected, numberOfMatches); }
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); }
public void ShouldMatchValidInputs(string input, string expectedMatch) { int expected = 1; var plugin = new KarmaPlugin(); var matches = plugin.GetOperatorMatchesInMessage(input); int numberOfMatches = matches.Count; Assert.Equal(expected, numberOfMatches); Assert.Equal(expectedMatch, matches[0].Value); }
public void ShouldMatchValidInputs(string input) { int expected = 1; var plugin = new KarmaPlugin(); var matches = plugin.GetMessageMatches(input); int numberOfMatches = matches.Count; Assert.Equal(expected, numberOfMatches); output.WriteLine($"Matched {matches[0].Value}"); }
public void GivenWhitespace_ShouldOnlyMatchCharacters() { int expectedCount = 1; var expectedMatchvalue = "test++"; var plugin = new KarmaPlugin(); var matches = plugin.GetMessageMatches(" test++ "); int numberOfMatches = matches.Count; Assert.Equal(expectedCount, numberOfMatches); Assert.Equal(expectedMatchvalue, matches[0].Value); }
public void GivenHyphenatedPhrase_ShouldTreatNormally() { int expectedCount = 2; var expectedMatchvalueOne = "hyphenated-word--"; var expectedMatchvalueTwo = "part-time-teachers++"; var plugin = new KarmaPlugin(); var matches = plugin.GetMessageMatches("hyphenated-word-- part-time-teachers++"); int numberOfMatches = matches.Count; Assert.Equal(expectedCount, numberOfMatches); Assert.Equal(expectedMatchvalueOne, matches[0].Value); Assert.Equal(expectedMatchvalueTwo, matches[1].Value); }
public KarmaMiddleware(IMiddleware next, KarmaRepositoryPlugin karmaRepositoryPlugin, KarmaPlugin karmaPlugin) : base(next) { _karmaRepositoryPlugin = karmaRepositoryPlugin; _karmaPlugin = karmaPlugin; HandlerMappings = new[] { new HandlerMapping { ValidHandles = RegexHandle.For(KarmaPlugin.IncomingMessageRegex), Description = "Allows upvoting and downvoting on things and people with `--` and `++`.", EvaluatorFunc = KarmaHandler, MessageShouldTargetBot = false, VisibleInHelp = false } }; }
public void GivenAdditionalPlusesOrMinnuses_ShouldMatchOnlyTwo() { int expectedCount = 4; var expectedMatchvalueOne = "test++"; var expectedMatchvalueTwo = "test--"; var plugin = new KarmaPlugin(); var matches = plugin.GetMessageMatches("test+++ test++++++++++ test--- test----------"); int numberOfMatches = matches.Count; Assert.Equal(expectedCount, numberOfMatches); Assert.Equal(expectedMatchvalueOne, matches[0].Value); Assert.Equal(expectedMatchvalueOne, matches[1].Value); Assert.Equal(expectedMatchvalueTwo, matches[2].Value); Assert.Equal(expectedMatchvalueTwo, matches[3].Value); }