public void AssertMatches(ParsedRequest requestObject, string regexKey, string expectedMatch, int expectedMatchCount) { string value = requestObject.ToString(); expectedMatch = Utilities_String.EscapeSpecialRegexCharacters(expectedMatch); List <KeyValuePair <string, object> > matches = requestObject.GetMatches(regexKey); Assert.AreEqual(expectedMatchCount, matches.Count, string.Format("Count for value of {0} in {1}", regexKey, value)); if (matches.Count <= 0) { return; } KeyValuePair <string, object> match = matches.First(); bool isNull = (expectedMatch == null); if (isNull) { Assert.IsNull(match.Value); } else { Assert.IsTrue(Regex.IsMatch(match.Value.ToString(), expectedMatch, RegexOptions.IgnoreCase), Utilities_Assertion.ToString(string.Format("Value of {0} in {1}", regexKey, value), expectedMatch, match.Value)); } System.Console.WriteLine(string.Format("HTTP_Request:\n\tType: {0}\tToString: {1}", requestObject.GetType(), requestObject.ToString())); }
public void Test_ParsedRequest_Parsing_Building_Match(string value, string regexKey, string expectedMatch, int expectedMatchCount) { ParsedRequest requestObject = ParsedRequest.GetParsedRequest(value); Assert.AreEqual(value.ToLower(), requestObject.ToString().ToLower()); AssertMatches(requestObject, regexKey, expectedMatch, expectedMatchCount); }