public void FormatMessageString() { var attr = new DA.RangeAttribute(-10, 10); Assert.AreEqual("The field MyField must be between -10 and 10.", attr.FormatErrorMessage("MyField"), "#A1"); attr.ErrorMessage = "Param 0: {0}"; Assert.AreEqual("Param 0: MyField", attr.FormatErrorMessage("MyField"), "#A2-1"); #if !NET_4_0 attr = new DA.RangeAttribute(-10, 10); #endif attr.ErrorMessage = "Param 0: {0}; Param 1: {1}"; Assert.AreEqual("Param 0: MyField; Param 1: -10", attr.FormatErrorMessage("MyField"), "#A2-2"); #if !NET_4_0 attr = new DA.RangeAttribute(-10, 10); #endif attr.ErrorMessage = "Param 0: {0}; Param 1: {1}; Param 2: {2}"; Assert.AreEqual("Param 0: MyField; Param 1: -10; Param 2: 10", attr.FormatErrorMessage("MyField"), "#A2-3"); #if !NET_4_0 attr = new DA.RangeAttribute(-10, 10); #endif attr.ErrorMessage = "Param 0: {0}; Param 1: {1}; Param 2: {2}; Param 3: {3}"; AssertExtensions.Throws <FormatException> (() => { attr.FormatErrorMessage("MyField"); }, "#A2-1"); }
public void Constructor_Type_String_String() { var attr = new DA.RangeAttribute(typeof(int), "-10", "10"); Assert.IsNotNull(attr.Minimum, "#A1-1"); Assert.IsNotNull(attr.Maximum, "#A1-2"); Assert.AreEqual(typeof(string), attr.Minimum.GetType(), "#A2-1"); Assert.AreEqual(typeof(string), attr.Maximum.GetType(), "#A2-2"); Assert.AreEqual("-10", attr.Minimum, "#A3-1"); Assert.AreEqual("10", attr.Maximum, "#A3-2"); Assert.IsNotNull(attr.OperandType, "#A4-1"); Assert.AreEqual(typeof(int), attr.OperandType, "#A4-2"); }
public void Constructor_Int_Int() { var attr = new DA.RangeAttribute(-10, 10); Assert.IsNotNull(attr.Minimum, "#A1-1"); Assert.IsNotNull(attr.Maximum, "#A1-2"); Assert.AreEqual(typeof(int), attr.Minimum.GetType(), "#A2-1"); Assert.AreEqual(typeof(int), attr.Maximum.GetType(), "#A2-2"); Assert.AreEqual(-10, attr.Minimum, "#A3-1"); Assert.AreEqual(10, attr.Maximum, "#A3-2"); Assert.IsNotNull(attr.OperandType, "#A4-1"); Assert.AreEqual(typeof(int), attr.OperandType, "#A4-2"); }
public void Constructor_Double_Double() { var attr = new DA.RangeAttribute(-10.123D, 10.123D); Assert.IsNotNull(attr.Minimum, "#A1-1"); Assert.IsNotNull(attr.Maximum, "#A1-2"); Assert.AreEqual(typeof(double), attr.Minimum.GetType(), "#A2-1"); Assert.AreEqual(typeof(double), attr.Maximum.GetType(), "#A2-2"); Assert.AreEqual(-10.123D, attr.Minimum, "#A3-1"); Assert.AreEqual(10.123D, attr.Maximum, "#A3-2"); Assert.IsNotNull(attr.OperandType, "#A4-1"); Assert.AreEqual(typeof(double), attr.OperandType, "#A4-2"); }
public void Constructor_Int_Int () { var attr = new DA.RangeAttribute (-10, 10); Assert.IsNotNull (attr.Minimum, "#A1-1"); Assert.IsNotNull (attr.Maximum, "#A1-2"); Assert.AreEqual (typeof (int), attr.Minimum.GetType (), "#A2-1"); Assert.AreEqual (typeof (int), attr.Maximum.GetType (), "#A2-2"); Assert.AreEqual (-10, attr.Minimum, "#A3-1"); Assert.AreEqual (10, attr.Maximum, "#A3-2"); Assert.IsNotNull (attr.OperandType, "#A4-1"); Assert.AreEqual (typeof (int), attr.OperandType, "#A4-2"); }
public void Constructor_Double_Double () { var attr = new DA.RangeAttribute (-10.123D, 10.123D); Assert.IsNotNull (attr.Minimum, "#A1-1"); Assert.IsNotNull (attr.Maximum, "#A1-2"); Assert.AreEqual (typeof (double), attr.Minimum.GetType (), "#A2-1"); Assert.AreEqual (typeof (double), attr.Maximum.GetType (), "#A2-2"); Assert.AreEqual (-10.123D, attr.Minimum, "#A3-1"); Assert.AreEqual (10.123D, attr.Maximum, "#A3-2"); Assert.IsNotNull (attr.OperandType, "#A4-1"); Assert.AreEqual (typeof (double), attr.OperandType, "#A4-2"); }
public void IsValid() { var attr = new DA.RangeAttribute(typeof(int), "-10", "10"); Assert.IsTrue(attr.IsValid("0"), "#A1-1"); Assert.IsFalse(attr.IsValid("12"), "#A1-2"); Assert.IsTrue(attr.IsValid(null), "#A1-3"); Assert.IsTrue(attr.IsValid(String.Empty), "#A1-4"); Assert.Throws <Exception> (() => { attr.IsValid("zero"); }, "#A1-5"); Assert.IsTrue(attr.IsValid(null), "#A1-6"); attr = new DA.RangeAttribute(typeof(int), "minus ten", "ten"); Assert.Throws <Exception> (() => { attr.IsValid("0"); }, "#A2-1"); Assert.Throws <Exception> (() => { attr.IsValid("12"); }, "#A2-2"); Assert.Throws <Exception> (() => { attr.IsValid("zero"); }, "#A2-3"); attr = new DA.RangeAttribute(typeof(RangeAttributeTest), "-10", "10"); Assert.Throws <InvalidOperationException> (() => { attr.IsValid(null); }, "#A3-1"); Assert.Throws <InvalidOperationException> (() => { attr.IsValid(String.Empty); }, "#A3-2"); Assert.Throws <InvalidOperationException> (() => { // The type MonoTests.System.ComponentModel.DataAnnotations.RangeAttributeTest must implement System.IComparable. attr.IsValid("10"); }, "#A3-3"); attr = new DA.RangeAttribute(null, "-10", "10"); Assert.Throws <InvalidOperationException> (() => { // The OperandType must be set when strings are used for minimum and maximum values. attr.IsValid("10"); }, "#A4"); attr = new DA.RangeAttribute(typeof(int), null, "10"); Assert.Throws <InvalidOperationException> (() => { // The minimum and maximum values must be set. attr.IsValid(10); }, "#A5-1"); attr = new DA.RangeAttribute(typeof(int), "10", null); Assert.Throws <InvalidOperationException> (() => { // The minimum and maximum values must be set. attr.IsValid(10); }, "#A5-2"); attr = new DA.RangeAttribute(typeof(int), "-10", "10"); Assert.AreEqual(typeof(string), attr.Minimum.GetType(), "#A6-1"); Assert.AreEqual(typeof(string), attr.Maximum.GetType(), "#A6-2"); // IsValid appears to reassign Minimum and Maximum with objects of the OperandType type, converted from the original strings attr.IsValid(12); Assert.AreEqual(typeof(int), attr.Minimum.GetType(), "#A7-1"); Assert.AreEqual(typeof(int), attr.Maximum.GetType(), "#A7-2"); }
//LAMESPEC: documented to throw public void Constructor_Type_String_String_Null_Type() { var attr = new DA.RangeAttribute(null, "-10", "10"); Assert.IsNull(attr.OperandType, "#A1"); }
public void FormatMessageString () { var attr = new DA.RangeAttribute (-10, 10); Assert.AreEqual ("The field MyField must be between -10 and 10.", attr.FormatErrorMessage ("MyField"), "#A1"); attr.ErrorMessage = "Param 0: {0}"; Assert.AreEqual ("Param 0: MyField", attr.FormatErrorMessage ("MyField"), "#A2-1"); #if !NET_4_0 attr = new DA.RangeAttribute (-10, 10); #endif attr.ErrorMessage = "Param 0: {0}; Param 1: {1}"; Assert.AreEqual ("Param 0: MyField; Param 1: -10", attr.FormatErrorMessage ("MyField"), "#A2-2"); #if !NET_4_0 attr = new DA.RangeAttribute (-10, 10); #endif attr.ErrorMessage = "Param 0: {0}; Param 1: {1}; Param 2: {2}"; Assert.AreEqual ("Param 0: MyField; Param 1: -10; Param 2: 10", attr.FormatErrorMessage ("MyField"), "#A2-3"); #if !NET_4_0 attr = new DA.RangeAttribute (-10, 10); #endif attr.ErrorMessage = "Param 0: {0}; Param 1: {1}; Param 2: {2}; Param 3: {3}"; AssertExtensions.Throws<FormatException> (() => { attr.FormatErrorMessage ("MyField"); }, "#A2-1"); }
public void IsValid () { var attr = new DA.RangeAttribute (typeof (int), "-10", "10"); Assert.IsTrue (attr.IsValid ("0"), "#A1-1"); Assert.IsFalse (attr.IsValid ("12"), "#A1-2"); Assert.IsTrue (attr.IsValid (null), "#A1-3"); Assert.IsTrue (attr.IsValid (String.Empty), "#A1-4"); AssertExtensions.Throws <Exception> (() => { attr.IsValid ("zero"); }, "#A1-5"); Assert.IsTrue (attr.IsValid (null), "#A1-6"); #if NET_4_0 attr = new DA.RangeAttribute (typeof (int), "minus ten", "ten"); AssertExtensions.Throws<Exception> (() => { attr.IsValid ("0"); }, "#A2-1"); AssertExtensions.Throws<Exception> (() => { attr.IsValid ("12"); }, "#A2-2"); AssertExtensions.Throws<Exception> (() => { attr.IsValid ("zero"); }, "#A2-3"); attr = new DA.RangeAttribute (typeof (RangeAttributeTest), "-10", "10"); AssertExtensions.Throws<InvalidOperationException> (() => { attr.IsValid (null); }, "#A3-1"); AssertExtensions.Throws<InvalidOperationException> (() => { attr.IsValid (String.Empty); }, "#A3-2"); AssertExtensions.Throws<InvalidOperationException> (() => { // The type MonoTests.System.ComponentModel.DataAnnotations.RangeAttributeTest must implement System.IComparable. attr.IsValid ("10"); }, "#A3-3"); attr = new DA.RangeAttribute (null, "-10", "10"); AssertExtensions.Throws<InvalidOperationException> (() => { // The OperandType must be set when strings are used for minimum and maximum values. attr.IsValid ("10"); }, "#A4"); attr = new DA.RangeAttribute (typeof (int), null, "10"); AssertExtensions.Throws<InvalidOperationException> (() => { // The minimum and maximum values must be set. attr.IsValid (10); }, "#A5-1"); attr = new DA.RangeAttribute (typeof (int), "10", null); AssertExtensions.Throws<InvalidOperationException> (() => { // The minimum and maximum values must be set. attr.IsValid (10); }, "#A5-2"); attr = new DA.RangeAttribute (typeof (int), "-10", "10"); Assert.AreEqual (typeof (string), attr.Minimum.GetType (), "#A6-1"); Assert.AreEqual (typeof (string), attr.Maximum.GetType (), "#A6-2"); // IsValid appears to reassign Minimum and Maximum with objects of the OperandType type, converted from the original strings attr.IsValid (12); Assert.AreEqual (typeof (int), attr.Minimum.GetType (), "#A7-1"); Assert.AreEqual (typeof (int), attr.Maximum.GetType (), "#A7-2"); #else AssertExtensions.Throws<Exception> (() => { attr = new DA.RangeAttribute (typeof (int), "minus ten", "ten"); }, "#A2"); AssertExtensions.Throws<ArgumentException> (() => { attr = new DA.RangeAttribute (typeof (RangeAttributeTest), "-10", "10"); }, "#A3"); AssertExtensions.Throws<ArgumentNullException> (() => { attr = new DA.RangeAttribute (null, "-10", "10"); }, "#A4"); AssertExtensions.Throws<NotSupportedException> (() => { attr = new DA.RangeAttribute (typeof (int), null, "10"); }, "#A5-1"); AssertExtensions.Throws<NotSupportedException> (() => { attr = new DA.RangeAttribute (typeof (int), "10", null); }, "#A5-2"); attr = new DA.RangeAttribute (typeof (int), "-10", "10"); Assert.AreEqual (typeof (int), attr.Minimum.GetType (), "#A6-1"); Assert.AreEqual (typeof (int), attr.Maximum.GetType (), "#A6-2"); #endif }
public void Constructor_Type_String_String_Null_Type () { var attr = new DA.RangeAttribute (null, "-10", "10"); Assert.IsNull (attr.OperandType, "#A1"); }
public void Constructor_Type_String_String () { var attr = new DA.RangeAttribute (typeof (int), "-10", "10"); Assert.IsNotNull (attr.Minimum, "#A1-1"); Assert.IsNotNull (attr.Maximum, "#A1-2"); #if NET_4_0 Assert.AreEqual (typeof (string), attr.Minimum.GetType (), "#A2-1"); Assert.AreEqual (typeof (string), attr.Maximum.GetType (), "#A2-2"); Assert.AreEqual ("-10", attr.Minimum, "#A3-1"); Assert.AreEqual ("10", attr.Maximum, "#A3-2"); #else Assert.AreEqual (typeof (int), attr.Minimum.GetType (), "#A2-1"); Assert.AreEqual (typeof (int), attr.Maximum.GetType (), "#A2-2"); Assert.AreEqual (-10, attr.Minimum, "#A3-1"); Assert.AreEqual (10, attr.Maximum, "#A3-2"); #endif Assert.IsNotNull (attr.OperandType, "#A4-1"); Assert.AreEqual (typeof (int), attr.OperandType, "#A4-2"); }