public void ProfanityCheck_GetProfanity_Extensive() { var repo = new Repository <BadWord>(resolver.Resolve <IDataContext>()); var result = ProfanityFilter.GetProfanity(null, null); Assert.Null(result); var badWord = "panty"; var checkPhrase = "She was whereing Panty."; result = ProfanityFilter.GetProfanity(checkPhrase, repo.List()); Assert.Equal(result, badWord); checkPhrase = "panty well"; result = ProfanityFilter.GetProfanity(checkPhrase, repo.List()); Assert.Equal(result, badWord); checkPhrase = " panty well"; result = ProfanityFilter.GetProfanity(checkPhrase, repo.List()); Assert.Equal(result, badWord); checkPhrase = "panty"; result = ProfanityFilter.GetProfanity(checkPhrase, repo.List()); Assert.Equal(result, badWord); checkPhrase = "panty."; result = ProfanityFilter.GetProfanity(checkPhrase, repo.List()); Assert.Equal(result, badWord); checkPhrase = "$panty$"; result = ProfanityFilter.GetProfanity(checkPhrase, repo.List()); Assert.True(result.Contains(badWord)); }
public void ProfanityCheck_Panty_Detected() { var repo = new Repository <BadWord>(resolver.Resolve <IDataContext>()); var badWord = "panty"; var checkPhrase = "She was whereing panty"; var result = ProfanityFilter.GetProfanity(checkPhrase, repo.List()); Assert.True(result == badWord); }
public ProfanityCheckResult CheckProfanity(string input, string culture) { var result = new ProfanityCheckResult(); // Check blank first. if (string.IsNullOrEmpty(input) || string.IsNullOrWhiteSpace(input)) { result.NoData = true; return(result); } // Check funny characters result.HasBadCharacters = !ProfanityFilter.AllCharactersAllowed(input); // Having bad character is enough to not touch cache if (result.HasBadCharacters) { return(LocalizeResult(result, culture)); } // Theoretically this shold never throw exception unless we got some timeout on initialization or something strange. var cachedData = GetCachedData(); result.ProfanityWord = ProfanityFilter.GetProfanity(input, cachedData.Items); return(result.HasIssues ? LocalizeResult(result, culture) : result); }