public void CanValidatePattern() { IRule testObject = null; try { testObject = new Rule(@"Invalid regex pattern [{("); } catch (Exception ex) { Assert.Fail("Constructor must not throw exception on invalid pattern. {0} caught.", ex.GetType().Name); } Assert.IsFalse(testObject.IsValid, "Unexcpected validation result on invalid regex pattern."); Assert.IsNotNull(testObject.ErrorMessage, "Error message is missing."); Assert.AreNotEqual(string.Empty, testObject.ErrorMessage, "Error message is missing."); Console.WriteLine("Correct error message detected: {0}", testObject.ErrorMessage); try { Assert.IsFalse(testObject.IsMatching("alma"), "Unexpected matching result while regex pattern is invalid."); } catch (Exception ex) { Assert.Fail("IsMatching() must not throw exception. {0} caught.", ex.GetType().Name); } try { var result = testObject.Parse("foo bar"); Assert.IsNotNull(result, "Unexpected parsing result while regex pattern is invalid."); Assert.AreEqual(0, result.Count, "Unexpected parsing result while regex pattern is invalid."); } catch (Exception ex) { Assert.Fail("Parse() must not throw exception. {0} caught.", ex.GetType().Name); } }
public void IsMatchingCanTrue() { const string line = "aki nem lep egyszerre nem kap retest estere"; var testObject = new Rule(line); Assert.IsTrue(testObject.IsMatching(line), "Unexpected result while comparing to an absolutly matching string."); }
public void IsMatchingCanFalse() { var testObject = new Rule(@"a specific text"); Assert.IsFalse(testObject.IsMatching("something absolutely else"), "Unexpected result while comparing to an unmatching string."); }