public void Ctor_StringDataType_Success() { ConstraintAttribute ca = new ConstraintAttribute(Constants.SimpleConstraintString, ParameterDataType.Int32); Assert.AreEqual(ParameterDataType.Int32, ca.DataType); Assert.AreEqual(Constants.SimpleConstraintString, ca.Constraints); Assert.IsTrue(ca.RequiresValidationContext); Assert.IsNotNull(ca.ParsedConstraints); Assert.AreEqual(1, ca.ParsedConstraints.Count); }
public void Ctor_ConstraintsNull_Error() { CustomAssert.ThrowsException<CodedArgumentNullOrWhiteSpaceException>(() => { ConstraintAttribute ca = new ConstraintAttribute(null, ParameterDataType.Int32); }); CustomAssert.ThrowsException<CodedArgumentNullOrWhiteSpaceException>(() => { ConstraintAttribute ca = new ConstraintAttribute(null, ParameterDataType.Int32, Constants.ErrorMessage); }); CustomAssert.ThrowsException<CodedArgumentNullOrWhiteSpaceException>(() => { ConstraintAttribute ca = new ConstraintAttribute(null, ParameterDataType.Int32, new Func<string>(() => { return Constants.ErrorMessage; })); }); }
public void Ctor_TypeInv_Error() { CustomAssert.ThrowsException<CodedArgumentOutOfRangeException>(() => { ConstraintAttribute ca = new ConstraintAttribute(Constants.SimpleConstraintString, ParameterDataType.None); }); CustomAssert.ThrowsException<CodedArgumentOutOfRangeException>(() => { ConstraintAttribute ca = new ConstraintAttribute(Constants.SimpleConstraintString, ParameterDataType.None, Constants.ErrorMessage); }); CustomAssert.ThrowsException<CodedArgumentOutOfRangeException>(() => { ConstraintAttribute ca = new ConstraintAttribute(Constants.SimpleConstraintString, ParameterDataType.None, new Func<string>(() => { return Constants.ErrorMessage; })); }); }
public void IsValid_Results_Success() { ConstraintAttribute ca = new ConstraintAttribute(Constants.MinValueConstraintString, ParameterDataType.Int32); Assert.IsFalse(ca.IsValid(13)); }
public void Ctor_StringDataTypeFunc_Success() { ConstraintAttribute ca = new ConstraintAttribute(Constants.SimpleConstraintString, ParameterDataType.Int32, new Func<string>(() => { return Constants.ErrorMessage; })); Assert.AreEqual(ParameterDataType.Int32, ca.DataType); Assert.AreEqual(Constants.SimpleConstraintString, ca.Constraints); Assert.IsNotNull(ca.ParsedConstraints); Assert.AreEqual(1, ca.ParsedConstraints.Count); Assert.AreEqual(Constants.ErrorMessage, ca.FormatErrorMessage(null)); }