public void RangeAttribute_All_Legal_Ctors() { RangeAttribute attr = new RangeAttribute(1, 2); Assert.AreEqual(1, attr.Minimum); Assert.AreEqual(2, attr.Maximum); Assert.AreEqual(typeof(int), attr.OperandType); attr = new RangeAttribute(3.0, 4.0); Assert.AreEqual(3.0, attr.Minimum); Assert.AreEqual(4.0, attr.Maximum); Assert.AreEqual(typeof(double), attr.OperandType); attr = new RangeAttribute(typeof(decimal), "1M", "2M"); Assert.AreEqual("1M", attr.Minimum); Assert.AreEqual("2M", attr.Maximum); Assert.AreEqual(typeof(decimal), attr.OperandType); }
public void RangeAttribute_All_Illegal_Ctors_No_Exceptions() { RangeAttribute attr = new RangeAttribute(2, 1); Assert.AreEqual(2, attr.Minimum); Assert.AreEqual(1, attr.Maximum); Assert.AreEqual(typeof(int), attr.OperandType); attr = new RangeAttribute(4.0, 3.0); Assert.AreEqual(4.0, attr.Minimum); Assert.AreEqual(3.0, attr.Maximum); Assert.AreEqual(typeof(double), attr.OperandType); attr = new RangeAttribute(null, null, null); Assert.IsNull(attr.Minimum); Assert.IsNull(attr.Maximum); Assert.IsNull(attr.OperandType); }
public void RangeAttribute_Constructor_Double_MinGreaterThanMax() { var attr = new RangeAttribute(1000000000.5, 10.5); ExceptionHelper.ExpectException<InvalidOperationException>(delegate() { attr.IsValid(10.0); }, String.Format(CultureInfo.CurrentCulture, Resources.DataAnnotationsResources.RangeAttribute_MinGreaterThanMax, 10.5, 1000000000.5)); }
public void RangeAttribute_Fail_Constructor_ArbitraryType_NotComparableType() { var attr = new RangeAttribute(typeof(RangeAttributeTest), "1", "10"); ExceptionHelper.ExpectException<InvalidOperationException>(delegate() { attr.IsValid(2); }, String.Format(CultureInfo.CurrentCulture, Resources.DataAnnotationsResources.RangeAttribute_ArbitraryTypeNotIComparable, typeof(RangeAttributeTest).FullName, typeof(System.IComparable).FullName)); }
public void RangeAttribute_Fail_Constructor_ArbitraryType_NullParameter() { var attr = new RangeAttribute(null, "1", "10"); ExceptionHelper.ExpectException<InvalidOperationException>(delegate() { attr.IsValid(2); }, Resources.DataAnnotationsResources.RangeAttribute_Must_Set_Operand_Type); }
private void AssertAreFalse(RangeAttribute range, params object[] values) { foreach (var v in values) { Assert.IsFalse(range.IsValid(v), "value = " + v); } }
public void RangeAttribute_Fail_String_Min_Exceed_Max() { var attr = new RangeAttribute(typeof(float), Convert.ToString(3.0), Convert.ToString(1.0)); ExceptionHelper.ExpectException<InvalidOperationException>(delegate() { attr.IsValid(2.0f); }, String.Format(CultureInfo.CurrentCulture, Resources.DataAnnotationsResources.RangeAttribute_MinGreaterThanMax, 1, 3)); }
public void RangeAttribute_Fail_Int32_Min_Exceed_Max() { var attr = new RangeAttribute(3, 1); ExceptionHelper.ExpectException<InvalidOperationException>(delegate() { attr.IsValid(2); }, String.Format(CultureInfo.CurrentCulture, Resources.DataAnnotationsResources.RangeAttribute_MinGreaterThanMax, 1, 3)); }
public void RangeAttribute_FormatErrorMessage() { var attrib = new RangeAttribute(-100.3, 10000000.5); Assert.AreEqual(String.Format(CultureInfo.CurrentCulture, Resources.DataAnnotationsResources.RangeAttribute_ValidationError, "SOME_NAME", -100.3, 10000000.5), attrib.FormatErrorMessage("SOME_NAME")); }
public void RangeAttribute_IsValid_ArbitraryType_Cannot_Convert() { RangeAttribute attr = new RangeAttribute(typeof(DateTime), DateTime.Now.AddDays(-3).ToLongDateString(), DateTime.Now.AddDays(3).ToLongDateString()); Assert.IsFalse(attr.IsValid("xxxx")); // format error is invalid, not an exception Assert.IsFalse(attr.IsValid("2.0")); // string which is valid double but not valid DateTime Assert.IsFalse(attr.IsValid(2.0)); // wrong type is invalid, not an exception }