public void Test_Is_2() { var Validate = new Validator(); Validate.That(26, "Square").Is(x => (int)Math.Pow(Math.Floor(Math.Sqrt((double)x)), 2) == x, "Must be a square number"); Assert.IsTrue(Validate.HasErrors()); }
public void Test_Bool_False_2() { Validator Validate = new Validator(); Validate.That(true, "Bool Value").IsFalse(); Assert.IsTrue(Validate.HasErrors()); }
public void CustomErrorCode_Simple() { var Validate = new Validator(); Validate.That(42, "The Answer").WithErrorCode(666).IsGreaterThan(100); Assert.IsTrue(Validate.HasErrors()); Assert.AreEqual(666, Validate.ValidatorResults[0].ErrorCode); }
public void CustomErrorCode_WithNot() { var Validate = new Validator(); Validate.That(42, "The Answer").WithErrorCode(999).Not().IsLessThan(100); Assert.IsTrue(Validate.HasErrors()); Assert.AreEqual(999, Validate.ValidatorResults[0].ErrorCode); }
public void ErrorCodesSetCorrectly_Date() { var Validate = new Validator(); Validate.That(DateTime.Now.AddDays(-10), "Expires").IsNotAPastDate(); Assert.IsTrue(Validate.HasErrors()); Assert.AreEqual(ValidationErrorCode.DateIsNotAPastDate, Validate.ValidatorResults[0].ErrorCode); }
public void ErrorCodesSetCorrectly_String() { var Validate = new Validator(); Validate.That("blah", "Name").IsLongerThan(10); Assert.IsTrue(Validate.HasErrors()); Assert.AreEqual(ValidationErrorCode.StringIsLongerThan, Validate.ValidatorResults[0].ErrorCode); }
public void ErrorCodesSetCorrectly_Numeric() { var Validate = new Validator(); Validate.That(42, "The Answer").IsGreaterThan(100); Assert.IsTrue(Validate.HasErrors()); Assert.AreEqual(ValidationErrorCode.NumericIsGreaterThan, Validate.ValidatorResults[0].ErrorCode); }
public void Test_Validator_Clear() { Validator Validate = new Validator(); int Amount = 5; //Generate one validation violation Validate.That(Amount, "Amount").IsZero(); //After clear there should be no validation violations anymore. Assert.IsTrue(Validate.HasErrors()); Validate.Clear(); //After clear there should be no validation violations anymore. Assert.IsFalse(Validate.HasErrors()); }
public void Test_String_IsLongerThan_3() { Validator Validate = new Validator(); string Name = "George"; Validate.That(Name, "Name").IsLongerThan(5); Assert.IsFalse(Validate.HasErrors()); }
public void Test_String_IsLength_3() { Validator Validate = new Validator(); string AccountNumber = "01234567890"; Validate.That(AccountNumber, "Account Number").IsLength(10); Assert.IsTrue(Validate.HasErrors()); }
public void Test_String_EndsWith_2() { Validator Validate = new Validator(); string URL = "htp://www.tn-data.se"; Validate.That(URL, "URL").EndsWith(".com"); Assert.IsTrue(Validate.HasErrors()); }
public void Test_String_HasALengthBetween_3() { Validator Validate = new Validator(); string Password = "******"; Validate.That(Password, "Password").HasALengthBetween(3, 10); Assert.IsTrue(Validate.HasErrors()); }
public void Test_String_IsDecimal_4() { Validator Validate = new Validator(); string WeightStr = "Hello"; Validate.That(WeightStr, "Weight").IsDecimal(); Assert.IsTrue(Validate.HasErrors()); }
public void Test_String_IsInteger_6() { Validator Validate = new Validator(); string AmountStr = "-12345"; Validate.That(AmountStr, "Amount").IsInteger(); Assert.IsFalse(Validate.HasErrors()); }
public void Test_String_IsShorterThan_1() { Validator Validate = new Validator(); string Name = "Jonathan"; Validate.That(Name, "Name").IsShorterThan(5); Assert.IsTrue(Validate.HasErrors()); }
public void Test_String_IsInteger_4() { Validator Validate = new Validator(); string AmountStr = "123.456"; Validate.That(AmountStr, "Amount").IsInteger(); Assert.IsTrue(Validate.HasErrors()); }
public void Test_String_IsEmpty_2() { Validator Validate = new Validator(); string Name = "George"; Validate.That(Name, "Name").IsEmpty(); Assert.IsTrue(Validate.HasErrors()); }
public void Test_String_MatchRegex_2() { Validator Validate = new Validator(); string AgeString = "Joe"; Validate.That(AgeString, "Age").MatchRegex("(\\d+)", "Age is not valid"); Assert.IsTrue(Validate.HasErrors()); }
public void Test_String_IsDecimal_3() { Validator Validate = new Validator(); string WeightStr = "-12,34"; Validate.That(WeightStr, "Weight").IsDecimal(); Assert.IsFalse(Validate.HasErrors()); }
public void Test_String_MatchRegex_3() { Validator Validate = new Validator(); string TestString = "OMG IT'S A MONKEY!!!"; Validate.That(TestString, "Monkey").MatchRegex("(monkey)", System.Text.RegularExpressions.RegexOptions.IgnoreCase, "No monkey :-O"); Assert.IsFalse(Validate.HasErrors()); }
public void Test_String_HasALengthBetween_2() { Validator Validate = new Validator(); string Password = "******"; Validate.That(Password, "Password").HasALengthBetween(3, 10); Assert.IsTrue(Validate.HasErrors()); }
public void Test_String_IsEmail_3() { Validator Validate = new Validator(); string Email = "my email is [email protected]"; Validate.That(Email, "Email").IsEmail(); Assert.IsTrue(Validate.HasErrors()); }
public void Test_String_StartsWith_1() { Validator Validate = new Validator(); string URL = "http://www.tn-data.se"; Validate.That(URL, "URL").StartsWith("http://"); Assert.IsFalse(Validate.HasErrors()); }
public void Test_String_IsURL_2() { Validator Validate = new Validator(); string URL = "www.tn-data.se"; Validate.That(URL, "URL").IsURL(); Assert.IsTrue(Validate.HasErrors()); }
public void Test_String_Contains_2() { Validator Validate = new Validator(); string URL = "www.tn-data.se"; Validate.That(URL, "URL").Contains("://"); Assert.IsTrue(Validate.HasErrors()); }
public void Test_String_IsURL_4() { Validator Validate = new Validator(); string URL = "ftp://[email protected]"; Validate.That(URL, "URL").IsURL(); Assert.IsFalse(Validate.HasErrors()); }
public void Test_String_IsLongerThan_2() { Validator Validate = new Validator(); string Name = "Joe"; Validate.That(Name, "Name").IsLongerThan(5); Assert.IsTrue(Validate.HasErrors()); }
public void Test_String_IsURL_7() { Validator Validate = new Validator(); string URL = "http://foo.bar.b-z.ftp.tn-data.se:8080/x/y/z.aspx?y=a%40b+c&z="; Validate.That(URL, "URL").IsURL(); Assert.IsFalse(Validate.HasErrors()); }
public void Check_Languages_Usable() { foreach (ValidationLanguageEnum Lang in Enum.GetValues(typeof(ValidationLanguageEnum))) { var Validate = new Validator(Lang); Validate.That(42, "The Answer").IsGreaterThan(100); Assert.IsTrue(Validate.HasErrors()); Assert.IsFalse(string.IsNullOrEmpty(Validate.ValidatorResults[0].ValidationMessage)); } }
public void Test_String_IsDate_2() { Validator Validate = new Validator(); string DateStr = "20090120 12:23"; Validate.That(DateStr, "SalesDate").IsDate(); Assert.IsTrue(Validate.HasErrors()); }