public void ProfanityCheck_FirstDisallowedCharacter_Returns() { char bad = Convert.ToChar(23); char random = Convert.ToChar(17); var result = ProfanityFilter.FirstDisallowedCharacter("I3" + bad + random); Assert.Equal(result, bad.ToString()); result = ProfanityFilter.FirstDisallowedCharacter("I3"); Assert.Null(result); }
/// <summary> /// Returns validated query string for GET method or null. /// </summary> /// <returns></returns> private ValidationResult ValidateInputForGet() { // do not return anything on empty input if (!Request.Query.ContainsKey(QUERY_STRING_PARAMETER_USER_INPUT)) { return(null); } var userInput = Request.Query[QUERY_STRING_PARAMETER_USER_INPUT][0]; // Check null or spaces or empty if (string.IsNullOrEmpty(userInput) || string.IsNullOrWhiteSpace(userInput)) { return(null); } userInput = userInput.Trim(); // Check minimal length if (userInput.Length < MINIMAL_WORD_LENGTH + 1) { return(null); } // This is what we will return var result = new ValidationResult() { CleanedInput = userInput }; // Check for bad characters. string badCharacter = ProfanityFilter.FirstDisallowedCharacter(result.CleanedInput); // let's only serve alphanumeric for now. if (badCharacter != null) { result.Passed = false; result.ErrorMessage = badCharacter; } return(result); }