本文整理汇总了C#中ValidationResults类的典型用法代码示例。如果您正苦于以下问题:C# ValidationResults类的具体用法?C# ValidationResults怎么用?C# ValidationResults使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
ValidationResults类属于命名空间,在下文中一共展示了ValidationResults类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: DoValidateSubmit
public void DoValidateSubmit(ValidationResults results)
{
if (this.Modes.Count == 0)
results.AddResult(new ValidationResult("At least one ground transportation mode is required.",
typeof(Ground),
"", "", null));
}
示例2: DoValidateCollectionItemSucceedsForUniqueNamedElements
public void DoValidateCollectionItemSucceedsForUniqueNamedElements()
{
Store store = new Store(typeof(CoreDesignSurfaceDomainModel), typeof(ServiceContractDslDomainModel));
ServiceContractModel model;
using (Transaction transaction = store.TransactionManager.BeginTransaction())
{
model = store.ElementFactory.CreateElement(ServiceContractModel.DomainClassId) as ServiceContractModel;
ServiceContract contract = store.ElementFactory.CreateElement(ServiceContract.DomainClassId) as ServiceContract;
contract.Name = "Contract Name";
Operation part = store.ElementFactory.CreateElement(Operation.DomainClassId) as Operation;
part.Name = "Part Name";
contract.Operations.Add(part);
TestableOperationElementCollectionValidator target = new TestableOperationElementCollectionValidator();
ValidationResults results = new ValidationResults();
target.TestDoValidateCollectionItem(part, contract, String.Empty, results);
Assert.IsTrue(results.IsValid);
transaction.Commit();
}
}
示例3: DoValidate
/// <summary>
/// Implements the validation logic for the receiver.
/// </summary>
/// <param name="objectToValidate">The object to validate.</param>
/// <param name="currentTarget">The object on the behalf of which the validation is performed.</param>
/// <param name="key">The key that identifies the source of <paramref name="objectToValidate"/>.</param>
/// <param name="validationResults">The validation results to which the outcome of the validation should be stored.</param>
public override void DoValidate(object objectToValidate, object currentTarget, string key, ValidationResults validationResults)
{
if (objectToValidate != null)
{
this.wrappedValidator.DoValidate(objectToValidate, currentTarget, key, validationResults);
}
}
示例4: DoValidate
/// <summary>
/// Validates by invoking the self validation method configured for the validator.
/// </summary>
/// <param name="objectToValidate">The object to validate.</param>
/// <param name="currentTarget">The object on the behalf of which the validation is performed.</param>
/// <param name="key">The key that identifies the source of <paramref name="objectToValidate"/>.</param>
/// <param name="validationResults">The validation results to which the outcome of the validation should be stored.</param>
/// <remarks>
/// A validation failure will be logged by the validator when the following conditions are met without
/// invoking the self validation method:
/// <list type="bullet">
/// <item><term><paramref name="objectToValidate"/> is <see langword="null"/>.</term></item>
/// <item><term><paramref name="objectToValidate"/> is an instance of a type not compatible with the declaring type for the
/// self validation method.</term></item>
/// </list>
/// <para/>
/// A validation failure will also be logged if the validation method throws an exception.
/// </remarks>
public override void DoValidate(object objectToValidate,
object currentTarget,
string key,
ValidationResults validationResults)
{
if (null == objectToValidate)
{
this.LogValidationResult(validationResults, Resources.SelfValidationValidatorMessage, currentTarget, key);
}
else if (!this.methodInfo.DeclaringType.IsAssignableFrom(objectToValidate.GetType()))
{
this.LogValidationResult(validationResults, Resources.SelfValidationValidatorMessage, currentTarget, key);
}
else
{
try
{
this.methodInfo.Invoke(objectToValidate, new object[] { validationResults });
}
catch (Exception)
{
this.LogValidationResult(validationResults, Resources.SelfValidationMethodThrownMessage, currentTarget, key);
}
}
}
示例5: Validate
/// <summary>
/// Applies the validation logic represented by the receiver on an object,
/// adding the validation results to <paramref name="validationResults"/>.
/// </summary>
/// <param name="target">The object to validate.</param>
/// <param name="validationResults">The validation results to which the outcome of the validation should be stored.</param>
public void Validate(object target, ValidationResults validationResults)
{
if (null == validationResults)
throw new ArgumentNullException("validationResults");
DoValidate(target, target, null, validationResults);
}
示例6: ControlValidationMappingsFailureTest
public void ControlValidationMappingsFailureTest()
{
IBugzillaPageView viewMock = MockRepository.StrictMock<IBugzillaPageView>();
Expect.Call(viewMock.Model).PropertyBehavior();
viewMock.ValidationRequested += null;
LastCall.IgnoreArguments();
viewMock.ControlValidationTriggered += null;
LastCall.IgnoreArguments();
IEventRaiser raiser = LastCall.GetEventRaiser();
Expect.Call(FacadeMock.GetSourceList()).Return(new string[0]);
Expect.Call(viewMock.SourceList).PropertyBehavior().Return(new string[0]);
Expect.Call(FacadeMock.GetProjectWrapperList()).Return(null);
Expect.Call(viewMock.VersionOneProjects).PropertyBehavior();
Expect.Call(FacadeMock.GetVersionOnePriorities()).Return(null);
Expect.Call(viewMock.VersionOnePriorities).PropertyBehavior();
viewMock.DataBind();
ValidationResults results = new ValidationResults();
ValidationResult generalResult = new ValidationResult(string.Empty, new BugzillaProjectMapping(), null, null, null);
results.AddResult(generalResult);
Expect.Call(FacadeMock.ValidateEntity(viewMock.Model)).IgnoreArguments().Return(results);
viewMock.SetGeneralTabValid(true);
viewMock.SetMappingTabValid(false);
MockRepository.ReplayAll();
BugzillaController controller = CreateController();
controller.RegisterView(viewMock);
controller.PrepareView();
raiser.Raise(viewMock, EventArgs.Empty);
MockRepository.VerifyAll();
}
示例7: DoValidate
/// <summary>
/// Implements the validation logic for the receiver, invoking validation on the composed validators.
/// </summary>
/// <param name="objectToValidate">The object to validate.</param>
/// <param name="currentTarget">The object on the behalf of which the validation is performed.</param>
/// <param name="key">The key that identifies the source of <paramref name="objectToValidate"/>.</param>
/// <param name="validationResults">The validation results to which the outcome of the validation should be stored.</param>
/// <remarks>
/// The results the generated by the composed validators are logged to <paramref name="validationResults"/>
/// only if all the validators generate results.
/// </remarks>
public override void DoValidate(object objectToValidate,
object currentTarget,
string key,
ValidationResults validationResults)
{
List<ValidationResult> childrenValidationResults = new List<ValidationResult>();
foreach (Validator validator in this.validators)
{
ValidationResults childValidationResults = new ValidationResults();
validator.DoValidate(objectToValidate, currentTarget, key, childValidationResults);
if (childValidationResults.IsValid)
{
// no need to query the rest of the validators
return;
}
childrenValidationResults.AddRange(childValidationResults);
}
LogValidationResult(validationResults,
GetMessage(objectToValidate, key),
currentTarget,
key,
childrenValidationResults);
}
示例8: EntityValidation
public void EntityValidation(ValidationResults results)
{
//--- Required
if (menu_id == null)
{
ValidationResult result = new ValidationResult(string.Format(ErrorMessage.IsRequired, "Menu"), this, string.Empty, string.Empty, null);
results.AddResult(result);
}
if (bill_of_material_head_id == null)
{
ValidationResult result = new ValidationResult(string.Format(ErrorMessage.IsRequired, "Bill of Material Head"), this, string.Empty, string.Empty, null);
results.AddResult(result);
}
if (quantity == null)
{
ValidationResult result = new ValidationResult(string.Format(ErrorMessage.IsRequired, "Quantity"), this, string.Empty, string.Empty, null);
results.AddResult(result);
}
//---
if (quantity <= 0)
{
ValidationResult result = new ValidationResult(string.Format(ErrorMessage.CompareValueMore, "Quantity", 0), this, string.Empty, string.Empty, null);
results.AddResult(result);
}
}
示例9: SubmitButton_Click
protected void SubmitButton_Click(object sender, EventArgs e)
{
// Get the token for this authentication process (rendered in a hidden input field, see the view)
var token = (string)ViewState["Token"];
// Get an instance of the Authentication class
var auth = Util.GetRestPkiClient().GetAuthentication();
// Call the CompleteWithWebPki() method with the token, which finalizes the authentication process. The call yields a
// ValidationResults which denotes whether the authentication was successful or not.
var validationResults = auth.CompleteWithWebPki(token);
// Check the authentication result
if (!validationResults.IsValid) {
// If the authentication was not successful, we render a page showing what went wrong
this.ValidationResults = validationResults;
Server.Transfer("AuthenticationFail.aspx");
return;
}
// At this point, you have assurance that the certificate is valid according to the TrustArbitrator you
// selected when starting the authentication and that the user is indeed the certificate's subject. Now,
// you'd typically query your database for a user that matches one of the certificate's fields, such as
// userCert.EmailAddress or userCert.PkiBrazil.CPF (the actual field to be used as key depends on your
// application's business logic) and set the user ID on the auth cookie. For demonstration purposes,
// we'll just render a page showing some of the user's certificate information.
this.Certificate = auth.GetCertificate();
Server.Transfer("AuthenticationSuccess.aspx");
}
示例10: ValidatorWillThrowIfProvidedNulValidationResults
public void ValidatorWillThrowIfProvidedNulValidationResults()
{
Validator validator = new MockValidator(true, "template");
ValidationResults validationResults = new ValidationResults();
validator.Validate(this, null);
}
示例11: ArgumentValidationException
/// <summary>
/// Initializes a new instance of the <see cref="ArgumentValidationException"/> class, storing the validation
/// results and the name of the parameter that failed.
/// </summary>
/// <param name="validationResults">The <see cref="ValidationResults"/> returned from the Validation Application Block.</param>
/// <param name="paramName">The parameter that failed validation.</param>
public ArgumentValidationException(ValidationResults validationResults, string paramName)
: base(Resources.ValidationFailedMessage, paramName)
{
this.validationResults = validationResults;
SerializeObjectState += (s, e) => e.AddSerializedState(new ValidationResultsSerializationData(this.validationResults));
}
示例12: DoValidate
protected internal override void DoValidate(object objectToValidate, object currentTarget, string key, ValidationResults validationResults)
{
foreach (Validator validator in this.validators)
{
validator.DoValidate(objectToValidate, currentTarget, key, validationResults);
}
}
示例13: EntityValidation
public void EntityValidation(ValidationResults results)
{
//--- Required
if (bill_of_material_head_id == null)
{
ValidationResult result = new ValidationResult(string.Format(ErrorMessage.IsRequired, "Bill Of Material Head"), this, string.Empty, string.Empty, null);
results.AddResult(result);
}
if (IsCheckedMaterial && material_id == null)
{
ValidationResult result = new ValidationResult(string.Format(ErrorMessage.IsRequired, "Material"), this, string.Empty, string.Empty, null);
results.AddResult(result);
}
else if (!IsCheckedMaterial && bill_of_material_head_id_sub == null)
{
ValidationResult result = new ValidationResult(string.Format(ErrorMessage.IsRequired, "BOM"), this, string.Empty, string.Empty, null);
results.AddResult(result);
}
if (amount == null)
{
ValidationResult result = new ValidationResult(string.Format(ErrorMessage.IsRequired, "Amount"), this, string.Empty, string.Empty, null);
results.AddResult(result);
}
if (lost_factor == null)
{
ValidationResult result = new ValidationResult(string.Format(ErrorMessage.IsRequired, "Lost Factor"), this, string.Empty, string.Empty, null);
results.AddResult(result);
}
}
示例14: EntityValidation
public void EntityValidation(ValidationResults results)
{
//--- Required
if (string.IsNullOrEmpty(employee_no))
{
ValidationResult result = new ValidationResult(string.Format(ErrorMessage.IsRequired, "Employee No"), this, string.Empty, string.Empty, null);
results.AddResult(result);
}
if (string.IsNullOrEmpty(first_name))
{
ValidationResult result = new ValidationResult(string.Format(ErrorMessage.IsRequired, "First Name"), this, string.Empty, string.Empty, null);
results.AddResult(result);
}
if (string.IsNullOrEmpty(last_name))
{
ValidationResult result = new ValidationResult(string.Format(ErrorMessage.IsRequired, "Last Name"), this, string.Empty, string.Empty, null);
results.AddResult(result);
}
if (string.IsNullOrEmpty(user_name))
{
ValidationResult result = new ValidationResult(string.Format(ErrorMessage.IsRequired, "User Name"), this, string.Empty, string.Empty, null);
results.AddResult(result);
}
if (string.IsNullOrEmpty(user_password))
{
ValidationResult result = new ValidationResult(string.Format(ErrorMessage.IsRequired, "Password"), this, string.Empty, string.Empty, null);
results.AddResult(result);
}
}
示例15: CanValidateGravatar
public void CanValidateGravatar()
{
var results = new ValidationResults();
var widget = new Gravatar();
// Confirm errors.
widget.FullName = "123456789012345678901234567890123456789012345678901234567890";
widget.Rating = "too_long";
bool success = widget.Validate(results);
Assert.IsFalse(success);
Assert.AreEqual(results.Count, 6);
// Confirm correct
widget.Header = "about";
widget.Zone = "right";
widget.FullName = "kishore reddy";
widget.Rating = "r";
widget.Email = "[email protected]";
widget.Size = 80;
results.Clear();
success = widget.Validate(results);
Assert.IsTrue(success);
Assert.AreEqual(results.Count, 0);
}