public void IsValid_NewGuid_True() { var attr = new MandatoryAttribute(); var act = attr.IsValid(Guid.NewGuid()); Assert.IsTrue(act); }
public void IsValid_EmailAddressEmpty_False() { var attr = new MandatoryAttribute(); var act = attr.IsValid(EmailAddress.Empty); Assert.IsFalse(act); }
public void IsValid_SomeEmailAddress_True() { var attr = new MandatoryAttribute(); var act = attr.IsValid(EmailAddress.Parse("*****@*****.**")); Assert.IsTrue(act); }
public void IsValid_GuidEmpty_False() { var attr = new MandatoryAttribute(); var act = attr.IsValid(Guid.Empty); Assert.IsFalse(act); }
/// <summary> /// Synchronously executes the <see cref="T:Microsoft.AspNetCore.Razor.TagHelpers.TagHelper" /> with the given <paramref name="context" /> and /// <paramref name="output" />. /// </summary> /// <param name="context">Contains information associated with the current HTML tag.</param> /// <param name="output">A stateful HTML element used to generate an HTML tag.</param> public override void Process(TagHelperContext context, TagHelperOutput output) { this.Output = output; if (!this.DisableBootstrap) { CopyToOutputAttribute.CopyPropertiesToOutput(this, output); MandatoryAttribute.CheckProperties(this); this.BasicRenderProcess(output); this.RenderProcess(context, output); this.RemoveMinimizableAttributes(output); } }
private static void CheckRequired(object model, PropertyInfo item, MandatoryAttribute attribute, List <ValidationError> errors) { if (attribute.Required && item.CanRead) { var value = item.GetValue(model); if (value == null || value.ToString().Equals(string.Empty)) { errors.Add(new ValidationError(ValidationType.Required, $"{item.DeclaringType.Name}.{item.Name}", "The field '{0}' is required.", new object[] { item.Name })); } } }
private static void CheckMaxLength(object model, PropertyInfo item, MandatoryAttribute attribute, List <ValidationError> errors) { if (attribute.MaxLength > 0 && item.CanRead) { if (item.PropertyType == typeof(string)) { var value = item.GetValue(model); if (value != null && value.ToString().Length > attribute.MaxLength) { errors.Add(new ValidationError(ValidationType.MaxLength, $"{item.DeclaringType.Name}.{item.Name}", "The field '{0}' must have a min length with {1} characters.", new object[] { item.Name, attribute.MaxLength })); } } } }