public void Submit(Form form) { _validator.Validate(form); Console.WriteLine("Submitting form..."); Thread.Sleep(500); Console.WriteLine($"Successfully submitted form for {form.Username}."); }
public void DateTime_Message_AreEqual() { const string column = "DateTime"; const string message = "測試{0}"; IFormValidator validator = provider.DateTime(message)(column, "NotDateTime"); validator.Validate(); Assert.AreEqual(validator.ErrorMessage, string.Format(message, column)); }
public void Integer_Message_AreEqual() { const string column = "Integer"; const string message = "測試{0}"; IFormValidator validator = provider.Integer(message)(column, "N/A"); validator.Validate(); Assert.AreEqual(validator.ErrorMessage, string.Format(message, column)); }
public void IdCard_Message_AreEqual() { const string column = "IdCard"; const string message = "測試{0}"; IFormValidator validator = provider.IdCard(IdCardTypes.All, message)(column, "NotIdCard"); validator.Validate(); Assert.AreEqual(validator.ErrorMessage, string.Format(message, column)); }
public void Email_Message_AreEqual() { const string column = "Email"; const string message = "測試{0}"; IFormValidator validator = provider.Email(message)(column, "NotEmail"); validator.Validate(); Assert.AreEqual(validator.ErrorMessage, string.Format(message, column)); }
public void Regex_Message_AreEqual() { const string column = "Regex"; const string message = "測試{0}"; IFormValidator validator = provider.Regex(@"\d", message)(column, "a"); validator.Validate(); Assert.AreEqual(validator.ErrorMessage, string.Format(message, column)); }
public void Required_Message_AreEqual() { const string column = "Required"; const string message = "測試{0}"; IFormValidator validator = provider.Required(message)(column, null); validator.Validate(); Assert.AreEqual(validator.ErrorMessage, string.Format(message, column)); }
public void MinDateTime_Message_AreEqual() { const string column = "MinDateTime"; const string message = "測試{0}{1}"; DateTime min = DateTime.Today; IFormValidator validator = provider.MinDateTime(min, message)(column, min.AddDays(-1).ToString("yyyy/MM/dd")); validator.Validate(); Assert.AreEqual(validator.ErrorMessage, string.Format(message, column, min)); }
public void MaxInt_Message_AreEqual() { const string column = "MaxInt"; const string message = "測試{0}{1}"; const int max = 3; IFormValidator validator = provider.MaxInt(max, message)(column, "4"); validator.Validate(); Assert.AreEqual(validator.ErrorMessage, string.Format(message, column, max)); }
public void DateTimeLessThan_Message_AreEqual() { const string column = "Column"; const string comparisonColumn = "Comparison Column"; const string message = "測試{0}必須小於{1}"; IFormValidator validator = provider.DateTimeLessThan(comparisonColumn, "2020/01/01", false, message)(column, "2020/01/01"); validator.Validate(); Assert.AreEqual(validator.ErrorMessage, string.Format(message, column, comparisonColumn)); }
public void Compare_Message_AreEqual() { const string column = "Compare"; const string comparisonColumn = "ComparisonColumn"; const string message = "測試{0}"; IFormValidator validator = provider.Compare(comparisonColumn, "123", message)(column, "321"); validator.Validate(); Assert.AreEqual(validator.ErrorMessage, string.Format(message, column, comparisonColumn)); }
public void MinLength_Message_AreEqual() { const string column = "MinLength"; const string message = "測試{0}{1}"; int min = 3; IFormValidator validator = provider.MinLength(min, message)(column, "12"); validator.Validate(); Assert.AreEqual(validator.ErrorMessage, string.Format(message, column, min)); }
public void IntRange_Message_AreEqual() { const string column = "IntRange"; const string message = "測試{0}{1}{2}"; const int min = 2; const int max = 4; IFormValidator validator = provider.IntRange(min, max, message)(column, "1"); validator.Validate(); Assert.AreEqual(validator.ErrorMessage, string.Format(message, column, min, max)); }
public void DateTimeRange_Message_AreEqual() { const string column = "DateTimeRange"; const string message = "測試{0}{1}{2}"; DateTime min = DateTime.Today.AddDays(-1); DateTime max = DateTime.Today.AddDays(1); IFormValidator validator = provider.DateTimeRange(min, max, message)(column, max.AddDays(1).ToString("yyyy/MM/dd")); validator.Validate(); Assert.AreEqual(validator.ErrorMessage, string.Format(message, column, min, max)); }
public OperationResult Add(DataForm formObject) { OperationResult result = new OperationResult(true, formObject); //formValidator = Factory.Create<IFormValidator>(this.Key, ClassType.clsTypeFormValidator); ValidationResult validationResult = formValidator.Validate(formObject); if (validationResult.Result) { formDataConverter = Factory.Create <IFormDataConverter>(this.Key, ClassType.clsTypeFormProcessor); Object o = Factory.Create <Object>(this.Key, ClassType.clsTypeDataModel); formDataConverter.PopulateData(formObject, o); businessService = Factory.Create <IBusinessService>(this.Key, ClassType.clsTypeBusinessService); result = businessService.Add(o); } else { result.Result = false; result.Message = "Validation Error"; result.Data = validationResult; } return(result); }
public Notification ValidateForm(FormData formData, EmailData emailData) { return(formValidator.Validate(formData, emailData)); }