コード例 #1
0
        public void AddResultParametersNotNull()
        {
            var result = new WordDetectorResult();

            Assert.ThrowsException <ArgumentNullException>(() =>
                                                           result.AddResult(matchWord: null, matches: new MatchResultCollection()));

            Assert.ThrowsException <ArgumentNullException>(() =>
                                                           result.AddResult(matchWord: "not null", matches: null));
        }
コード例 #2
0
        public void VerifyMatchWordCount()
        {
            var result = new WordDetectorResult();

            // Making sure the count increases with each added word.
            // Try for an arbitrary number of cycles.
            for (int x = 1; x <= 15; x++)
            {
                result.AddResult(x.ToString(), new MatchResultCollection());
                Assert.AreEqual(x, result.MatchWordCount);
            }
        }
コード例 #3
0
        public void VerifyMatchWordCountCaseInsensitive()
        {
            var result = new WordDetectorResult();

            int count = 1;

            for (char let = 'a'; let <= 'z'; let++)
            {
                // Though we're adding two results, the total count should only increase by 1.
                result.AddResult(let.ToString().ToLower(), new MatchResultCollection());
                result.AddResult(let.ToString().ToUpper(), new MatchResultCollection());

                Assert.AreEqual(count, result.MatchWordCount);
                count++;
            }
        }
コード例 #4
0
ファイル: CommentFilter.cs プロジェクト: alexhebert90/ItsBot
        private bool ContainsWordMatch(CommentChildData comment, out WordDetectorResult result)
        {
            if (comment == null)
            {
                throw new ArgumentNullException(nameof(comment));
            }

            // Assign a value to result to return.
            result = default;

            var match = WordDetector.Detect(comment.Body);

            bool containsWordMatch = match.TotalMatches > 0;

            if (containsWordMatch)
            {
                result = match;
            }

            return(containsWordMatch);
        }