public void Returns_an_error_for_each_failed_requirement() { var reqA = new Mock <AbstractRequirement <string> >() { CallBase = true }; reqA.Setup(t => t.Check(It.IsAny <string>())).Returns(new[] { new ValidationError { Message = "A" } }); var reqB = new Mock <AbstractRequirement <string> >() { CallBase = true }; reqB.Setup(t => t.Check(It.IsAny <string>())).Returns(new ValidationError[0]); var reqC = new Mock <AbstractRequirement <string> >() { CallBase = true }; reqC.Setup(t => t.Check(It.IsAny <string>())).Returns(new[] { new ValidationError { Message = "C" } }); var val = new _Validator <object>(); var reqs = val._Require(t => t.ToString()); reqs.ContinueOnError = true; reqs.Add(reqA.Object); reqs.Add(reqB.Object); reqs.Add(reqC.Object); var list = val.Check("").ToList(); Assert.Equal(2, list.Count); }
public void Returns_an_empty_enumeration_when_no_requirements() { var val = new _Validator <object>(); val._Require(t => t.ToString()); Assert.Empty(val.Check("")); }
private string Validator(string Column, _Validator validator, DataTable dataTable, int StartRowNumberForValidationError) { StringBuilder stringBuilder = new StringBuilder(); for (int i = 0; i < dataTable.Rows.Count; i++) { if (! (validator.additionalColumn != null ? validator.validator(dataTable.Rows[i][Column].ToString(), dataTable.Rows[i][validator.additionalColumn].ToString()) : validator.validator(dataTable.Rows[i][Column].ToString(), null)) ) { stringBuilder.Append(stringBuilder.Length > 0 ? "," + (i + StartRowNumberForValidationError).ToString() : (i + StartRowNumberForValidationError).ToString()); } } return(stringBuilder.ToString()); }
public void Returns_a_Requirement_list_of_the_given_type() { var val = new _Validator <object>(); Assert.IsAssignableFrom <RequirementList <object, string> >(val._Require(t => t.ToString())); }