public void ConstructorTest_SunnyDay() { string pv_strParameterName = "--help"; string pv_strParameterAbbreviation = "-?"; bool pv_blnParameterRequired = false; string pv_strValidationExpression = null; string pv_strParameterHelpResource = null; PaytonByrd.ProcessConfiguration.ProcessParameterAttribute target = new PaytonByrd.ProcessConfiguration.ProcessParameterAttribute( pv_strParameterName, pv_strParameterAbbreviation, pv_blnParameterRequired, pv_strValidationExpression, pv_strParameterHelpResource); Assert.IsNotNull(target); Assert.Equals(target.ParameterName, pv_strParameterName); Assert.Equals(target.ParameterAbbreviation, pv_strParameterAbbreviation); Assert.Equals(target.ValidationExpression, pv_strValidationExpression); Assert.Equals(target.ParameterHelpResource, pv_strParameterHelpResource); }
public static ParameterValidationError Validate( object pv_objInstance, PropertyInfo pv_objPropertyInfo) { ArgumentAssert.IsGenericNotNull <object>(pv_objInstance, "pv_objInstance"); ArgumentAssert.IsGenericNotNull <PropertyInfo>(pv_objPropertyInfo, "pv_objPropertyInfo"); ParameterValidationError objResult = ParameterValidationError.CreateValid(); object objValue = null; ProcessParameterAttribute objAttribute = null; try { List <ProcessParameterAttribute> objAttributes = new List <ProcessParameterAttribute>( (ProcessParameterAttribute[]) pv_objPropertyInfo.GetCustomAttributes( typeof(ProcessParameterAttribute), false)); if (objAttributes.Count > 0) { objAttribute = objAttributes[0]; objValue = pv_objPropertyInfo.GetValue(pv_objInstance, new object[0]); if (objValue == null && objAttribute.m_blnParameterRequired) { return(ParameterValidationError.CreateNotValid(string.Format( Helpers.ResourceHelper.GetResource(CANNOT_BE_NULL_RESOURCE_ID), pv_objPropertyInfo.Name))); } if (objAttribute.m_strValidationExpression != ".*") { System.Text.RegularExpressions.Regex objRegex = new System.Text.RegularExpressions.Regex(objAttribute.m_strValidationExpression); if (!objRegex.IsMatch(objValue.ToString())) { return(ParameterValidationError.CreateNotValid(string.Format( Helpers.ResourceHelper.GetResource(DOES_NOT_MATCH_EXPRESSION_RESOURCE_ID), pv_objPropertyInfo.Name))); } } } } catch (Exception objException) { ParameterValidationError.CreateNotValid(objException.ToString()); } return(objResult); }
public void ConstructorTest_InvalidNullParameterName() { string pv_strParameterName = null; string pv_strParameterAbbreviation = null; bool pv_blnParameterRequired = false; string pv_strValidationExpression = null; string pv_strParameterHelpResource = null; Attribute target = new PaytonByrd.ProcessConfiguration.ProcessParameterAttribute( pv_strParameterName, pv_strParameterAbbreviation, pv_blnParameterRequired, pv_strValidationExpression, pv_strParameterHelpResource); Assert.Fail("Did not throw ArgumentNullException."); }
public void ConstructorTest_InvalidNullParameterName() { string pv_strParameterName = null; string pv_strParameterAbbreviation = null; bool pv_blnParameterRequired = false; string pv_strValidationExpression = null; string pv_strParameterHelpResource = null; Attribute target = new PaytonByrd.ProcessConfiguration.ProcessParameterAttribute( pv_strParameterName, pv_strParameterAbbreviation, pv_blnParameterRequired, pv_strValidationExpression, pv_strParameterHelpResource); Assert.Fail("Did not throw ArgumentNullException."); }
public void ConstructorTest_SunnyDay() { string pv_strParameterName = "--help"; string pv_strParameterAbbreviation = "-?"; bool pv_blnParameterRequired = false; string pv_strValidationExpression = null; string pv_strParameterHelpResource = null; PaytonByrd.ProcessConfiguration.ProcessParameterAttribute target = new PaytonByrd.ProcessConfiguration.ProcessParameterAttribute( pv_strParameterName, pv_strParameterAbbreviation, pv_blnParameterRequired, pv_strValidationExpression, pv_strParameterHelpResource); Assert.IsNotNull(target); Assert.Equals(target.ParameterName, pv_strParameterName); Assert.Equals(target.ParameterAbbreviation, pv_strParameterAbbreviation); Assert.Equals(target.ValidationExpression, pv_strValidationExpression); Assert.Equals(target.ParameterHelpResource, pv_strParameterHelpResource); }