Example #1
0
 public void TestValidateInvalidHour()
 {
     TimeField tf = new TimeField("243456");
     string err = string.Empty;
     string modStr = string.Empty;
     Assert.IsFalse(tf.Validate(out err, out modStr));
     Assert.AreEqual("\tInvalid time.", err);
     Assert.IsNull(modStr);
 }
Example #2
0
 public void TestValidateInvalidHHMMS()
 {
     TimeField tf = new TimeField("12345");
     string err = string.Empty;
     string modStr = string.Empty;
     Assert.IsFalse(tf.Validate(out err,out modStr));
     Assert.AreEqual("\tTime must be in HHMM or HHMMSS format.", err);
     Assert.IsNull(modStr);
 }
Example #3
0
 /// <summary>
 /// Helper method that validates start time
 /// </summary>
 /// <returns>Validation string (error string, or null if no error)</returns>
 private string ValidateStartTime()
 {
     TimeField time = new TimeField(StartTime);
     string err = string.Empty;
     string mod = string.Empty;
     if(!time.Validate(out err, out mod))
     {
         return err;
     }
     return null;
 }
 /// <summary>
 /// Validate the field values:
 /// 1. Field name must be of format APP_{PROGRAMNAME}_{FIELDNAME}. PROGRAMNAME and
 /// FIELDNAME are not checked.
 /// 2. Datatype must be in the enumeration of data types defined in 
 /// </summary>
 /// <param name="err">Error message if values are not valid</param>
 /// <param name="modStr">Message if value has been modified</param>
 /// <returns>true if values are valid, false otherwise</returns>
 public override bool Validate(out string err, out string modStr)
 {
     err = null;
     modStr = null;
     string[] appParts = Name.Split('_');
     if(appParts.Length < 3 || appParts[1].Equals(string.Empty) ||
        appParts[2].Equals(string.Empty) ||
        !appParts[0].ToUpper().Equals("APP"))
     {
         err = "\tInvalid Application Defined Fieldname.";
         return false;
     }
     if(!DataType.Validate(out err, out modStr))
     {
         err = "\tInvalid Data Type.";
         return false;
     }
     switch(DataType.Value)
     {
         case "A":			// AwardList type
             string[] awards = Value.Split(',');
             string[] awardsList = Value.Split(',');
             for(int i = 0; i < awards.Length; i++)
             {
                 if(!DataType.aEnums.IsInEnumeration("Award", awards[i]))
                 {
                     modStr = "\tInvalid AwardList item: '" + awards[i] + "'. Item removed.";
                     awardsList[i] = null;
                 }
             }
             Value = string.Empty;
             foreach(string award in awardsList)
             {
                 if(award != null)
                 {
                     Value += award + ",";
                 }
             }
             if(Value != string.Empty)
             {
                 Value = Value.Substring(0, Value.Length - 1);
             }
             break;
         case "B":			// Boolean type
             BooleanField bf = new BooleanField(Value);
             if(!bf.Validate(out err, out modStr))
             {
                 err = "\tInvalid Boolean Value: '" + Value + "'.";
                 return false;
             }
             break;
         case "C":			// CreditList type
             string[] credits = Value.Split(',');
             string[] creditList = Value.Split(',');
             for(int i = 0; i < credits.Length; i++)
             {
                 if(!DataType.aEnums.IsInEnumeration("Credit", credits[i]))
                 {
                     modStr = "\tInvalid CreditList item: '" + credits[i] + "'.";
                     creditList[i] = null;
                 }
             }
             Value = string.Empty;
             foreach(string credit in creditList)
             {
                 if(credit != null)
                 {
                     Value += credit + ",";
                 }
             }
             if(Value != string.Empty)
             {
                 Value = Value.Substring(0, Value.Length - 1);
             }
             break;
         case "D":		// Date type
             DateField df = new DateField(Value);
             if(!df.Validate(out err, out modStr))
             {
                 return false;
             }
             break;
         case "L":		// Location type
             Location loc = new Location(Value);
             if(!loc.Validate(out err, out modStr))
             {
                 err = "\tInvalid location: '" + Value + "'.";
                 return false;
             }
             break;
         case "M":		// multiline string type
             MultilineStringField sf = new MultilineStringField(Value);
             if(!sf.Validate(out err, out modStr))
             {
                 err = "\tInvalid multiline string: '" + Value + "'.";
                 return false;
             }
             break;
         case "N":		// number type
             NumberField nf = new NumberField(Value);
             if(!nf.Validate(out err, out modStr))
             {
                 err = "\tInvalid number: '" + Value + "'.";
                 return false;
             }
             break;
         case "P":		// sponsored award list type
             awards = Value.Split(',');
             string[] awardList = Value.Split(',');
             for(int i = 0; i < awardList.Length; i++)
             {
                 string gError = string.Empty;
                 string gMod = string.Empty;
                 Award_Granted granted = new Award_Granted(awards[i], DataType.aEnums);
                 if(!granted.Validate(out gError, out gMod))
                 {
                     err += gError + Environment.NewLine;
                 }
                 if(gMod != null)
                 {
                     modStr += gMod + Environment.NewLine;
                 }
             }
             return err == null;
         case "S":		// string type
             StringField str = new StringField(Value);
             if(!str.Validate(out err, out modStr))
             {
                 return false;
             }
             break;
         case "T":		// time type
             TimeField tf = new TimeField(Value);
             if(!tf.Validate(out err, out modStr))
             {
                 return false;
             }
             break;
         default:
             err = "\tInvalid data type: '" + DataType.Value + "'.";
             return false;
     }
     return true;
 }
Example #5
0
 public void TestToAdifString()
 {
     TimeField tf = new TimeField("123456");
     Assert.AreEqual("<TimeField:6>123456", tf.ToAdifString());
 }
Example #6
0
 public void TestValidateValidHHMMSS()
 {
     TimeField tf = new TimeField("123456");
     string err = string.Empty;
     string modStr = string.Empty;
     Assert.IsTrue(tf.Validate(out err, out modStr));
     Assert.IsNull(err);
     Assert.IsNull(modStr);
 }