private List<VerificationItem> MatchVerifications(List<VerificationItem> verifications, string content, VerificationBehaviour behaviour) { var matchedItems = new List<VerificationItem>(); foreach (VerificationItem item in verifications) { LogItem(behaviour, item); string regex = item.Regex; if (!string.IsNullOrEmpty(regex)) { regex = _variables.ReplaceVariablesIn(regex); item.TransformedRegex = regex; LogRegex(item.Regex, regex); try { bool isMatch = Regex.IsMatch(content, regex, RegexOptions.IgnoreCase); item.Success = true; if (behaviour == VerificationBehaviour.Positive && isMatch == false) { item.Success = false; LogFail(behaviour, item, regex); } else if (behaviour == VerificationBehaviour.Negative && isMatch == true) { item.Success = false; LogFail(behaviour, item, regex); } } catch (ArgumentException e) { // Invalid regex - ignore. item.Success = false; LogException(e); } } else { LogEmpty(); } matchedItems.Add(item); } return matchedItems; }
private void LogItem(VerificationBehaviour behaviour, VerificationItem item) { Log.Information("---------------------------"); Log.Information("Verifying {0} [{1}]", behaviour, item.Description); Log.Information("---------------------------"); }
private void LogFail(VerificationBehaviour behaviour, VerificationItem item, string verifyRegex) { Log.Information("{0} verification failed: {1} - {2}", behaviour, item.Description, verifyRegex); }