Esempio n. 1
0
 public void Process(ProfanityFilterArgs args)
 {
     if (args.WordList == null)
     {
         args.WordList = GetProfanityItemContent();
     }
 }
Esempio n. 2
0
 public void Process(ProfanityFilterArgs args)
 {
     if (args.WordList.Any() && CacheManager.ProfanityFilterCache.WorList == null)
     {
         CacheManager.ProfanityFilterCache.WorList = args.WordList;
     }
 }
Esempio n. 3
0
 public void Process(ProfanityFilterArgs args)
 {
     if (args.WordList.Any() && CacheManager.ProfanityFilterCache.WorList == null)
     {
         CacheManager.ProfanityFilterCache.WorList = args.WordList;
     }
 }
Esempio n. 4
0
 public void Process(ProfanityFilterArgs args)
 {
     if (args.WordList == null)
     {
         args.WordList = GetProfanityFileContent();
     }
 }
Esempio n. 5
0
 public void Process(ProfanityFilterArgs args)
 {
     if (CacheManager.ProfanityFilterCache.WordList != null)
     {
         args.WordList = CacheManager.ProfanityFilterCache.WordList;
     }
 }
Esempio n. 6
0
        public void Test(bool wholeWords, string input, bool isAllowed)
        {
            var processor = new ValidateInput
            {
                WholeWordsOnly = wholeWords
            };

            var args = new ProfanityFilterArgs
            {
                Input    = input,
                WordList = new List <string> {
                    "x", "y"
                }
            };

            processor.Process(args);

            if (isAllowed)
            {
                Assert.That(args.Valid, Is.True);
            }
            else
            {
                Assert.That(args.Valid, Is.False);
            }
        }
Esempio n. 7
0
        public void Process_WordsAlreadyPopulated_DoesNothing()
        {
            // arrange
            var database = new Mock <Database>();

            database.Setup(x => x.Name).Returns("fake");

            var itemMock = ItemFactory.CreateItem(database: database.Object);

            database.Setup(x => x.GetItem("item")).Returns(itemMock.Object);

            var field = FieldFactory.CreateField(itemMock.Object, ID.NewID, Constants.Fields.WordList, "lorem\nipsum");

            ItemFactory.AddFields(itemMock, new[] { field });

            var sut = new GetProfanityListFromItem(database.Object);

            sut.ItemPath = "item";
            var args = new ProfanityFilterArgs();

            args.WordList = new[] { "dolor" };

            // act
            sut.Process(args);

            // assert
            Assert.That(args.WordList, Is.EquivalentTo(new[] { "dolor" }));
        }
Esempio n. 8
0
        public void Process_UnknownItem_DoesNotPopulateWords()
        {
            // arrange
            var database = Mock.Of <Database>();
            var sut      = new GetProfanityListFromItem(database);
            var args     = new ProfanityFilterArgs();

            // act
            sut.Process(args);

            // assert
            Assert.That(args.WordList, Is.Empty);
        }
Esempio n. 9
0
 public void Process(ProfanityFilterArgs args)
 {
     foreach (var p in args.WordList)
     {
         var indexOf = GetIndexOfProfanity(p, args.Input);
         if (indexOf >= 0)
         {
             var begin = args.Input.Substring(0, indexOf);
             var end   = args.Input.Substring(indexOf + p.Length);
             args.Input = begin + Replacement + end;
         }
     }
 }
Esempio n. 10
0
 public void Process(ProfanityFilterArgs args)
 {
     if (WholeWordsOnly)
     {
         args.Valid = !args.WordList
                      .Select(GetPattern)
                      .Any(p => Regex.Match(args.Input, p, RegexOptions.IgnoreCase).Success);
     }
     else
     {
         args.Valid = !args.WordList.Any(s => args.Input.IndexOf(s, StringComparison.OrdinalIgnoreCase) >= 0);
     }
 }
Esempio n. 11
0
 public void Process(ProfanityFilterArgs args)
 {
     if (WholeWordsOnly)
     {
         args.Valid = !args.WordList
             .Select(GetPattern)
             .Any(p => Regex.Match(args.Input, p, RegexOptions.IgnoreCase).Success);
     }
     else
     {
         args.Valid = !args.WordList.Any(s => args.Input.IndexOf(s, StringComparison.OrdinalIgnoreCase) >= 0);
     }
 }
        public void Process_FileNotFound_DoesNothing()
        {
            // arrange
            var sut = new GetProfanityListFromFile();

            sut.FilePath = "invalidfile.txt";
            var args = new ProfanityFilterArgs();

            // act
            sut.Process(args);

            // assert
            Assert.That(args.WordList, Is.Empty);
        }
        public void Process_WordListNotNull_DoesNothing()
        {
            // arrange
            var sut  = new GetProfanityListFromFile();
            var args = new ProfanityFilterArgs();

            args.WordList = new[] { "lorem", "ipsum" };

            // act
            sut.Process(args);

            // assert
            Assert.That(args.WordList, Is.EquivalentTo(new[] { "lorem", "ipsum" }));
        }
Esempio n. 14
0
        public void Process(CreateCommentArgs args)
        {
            Assert.IsNotNull(args.Comment, "Comment cannot be null");
            ProfanityFilterArgs filterArgs = new ProfanityFilterArgs
            {
                Input = args.Comment.Text
            };

            CorePipeline.Run("weblogProfanityFilter", filterArgs);
            if (!filterArgs.Valid)
            {
                args.AbortPipeline();
            }
            args.Comment.Text = filterArgs.Input;
        }
        public void Process_FileWithWords_PopulatesWordList()
        {
            // This is an integration test. Sorry.
            // arrange
            File.WriteAllText("words.txt", "lorem\r\nipsum");
            var sut = new GetProfanityListFromFile();

            sut.FilePath = "words.txt";
            var args = new ProfanityFilterArgs();

            // act
            sut.Process(args);

            // assert
            Assert.That(args.WordList, Is.EquivalentTo(new[] { "lorem", "ipsum" }));
        }
        public void Process_FileExistsButIsEmpty_DoesNothing()
        {
            // This is an integration test. Sorry.
            // arrange
            File.WriteAllText("empty.txt", string.Empty);
            var sut = new GetProfanityListFromFile();

            sut.FilePath = "invalidfile.txt";
            var args = new ProfanityFilterArgs();

            // act
            sut.Process(args);

            // assert
            Assert.That(args.WordList, Is.Empty);
        }
Esempio n. 17
0
        public void Test(bool wholeWords, string replacement, string input, string expected)
        {
            var processor = new FilterWords
            {
                WholeWordsOnly = wholeWords,
                Replacement    = replacement
            };

            var args = new ProfanityFilterArgs
            {
                Input    = input,
                WordList = new List <string> {
                    "x", "y"
                }
            };

            processor.Process(args);

            Assert.That(args.Input, Is.EqualTo(expected));
        }