/// <summary> /// 驗證欄位資料型態 /// </summary> /// <typeparam name="T">資料型態</typeparam> /// <param name="value">資料</param> /// <param name="ignoreEmpty">是否忽略驗證空白資料</param> /// <param name="field">顯示欄位</param> /// <param name="messageFormat">錯誤訊息字串格式, {0} 為顯示欄位</param> public void DataTypeValidate <T>(string value, bool ignoreEmpty, string field, string messageFormat) { if (!ignoreEmpty || !String.IsNullOrWhiteSpace(value)) { if (ConvertUtility.IsType <T>(value) == false) { this.errorMessageList.Add(String.Format(messageFormat, field)); } } }
public void TestIsInt32() { //Arrange var test = "123"; var expected = true;; //Act var result = ConvertUtility.IsType <Int32>(test); //Assert Assert.AreEqual(expected, result); }
public void TestGetString() { //Arrange int number = 5; //Act string result = RandomUtility.GetString(number); //Assert Trace.WriteLine("產生結果:" + result); Assert.IsFalse(ConvertUtility.IsType <Int32>(result)); }