Skip to content

CertificatePreferenceValidator

FluentValidation validator for CertificatePreferenceEdit, the model that captures how a policyholder wants certificate renewal notifications delivered (mail, email, or fax). It requires a delivery method, requires a renewal notification type whenever a delivery method other than None is selected, validates email address format and length, requires an email address when the delivery method is Email, requires a fax number when the delivery method is Fax, and independently validates fax number formatting via BeAvalidFaxNumber.

Purpose

  • Requires DeliveryMethod to be set on every submission.
  • Requires a valid (non-NotSet) RenewalNotificationType whenever DeliveryMethod is not None.
  • Enforces email address format/length rules and requires an email address when DeliveryMethod is Email.
  • Requires a fax number when DeliveryMethod is Fax, and validates the fax number's format regardless of delivery method.

Context

  • Namespace: SAIF.Services.Policies.Certificates.Validators
  • Assembly/package: SAIF.Services (packaged inside the SAIF.SAIFCode.Core NuGet package).

Public members

Member Signature Purpose
CertificatePreferenceValidator (constructor) public CertificatePreferenceValidator() Registers all validation rules for CertificatePreferenceEdit: required delivery method, conditional renewal-notification requirement, email format/length rules, conditional email/fax requirements based on delivery method, and fax-format validation.

Behavioral notes

  • The renewal-notification rule uses Must with a lambda that ignores the bound testString parameter and instead re-reads n.RenewalNotificationType, so the rule effectively re-validates the same property it is attached to (DeliveryMethod) via a side-channel check on RenewalNotificationType.*
  • The email-required and fax-required rules are likewise implemented as Must predicates on the DeliveryMethod property that inspect EmailAddress/Fax rather than validating those properties directly, so validation failures surface against the DeliveryMethod field.*
  • BeAvalidFaxNumber treats a null fax value or an empty formatted value as valid, and only rejects a fax whose NumericValue is positive but whose FormattedValue is empty, or accepts any formatted value that is exactly 12 characters long; any other non-empty formatted value falls through to return true as well, so the practical rejection case is narrow.*
  • Several alternative/experimental rule blocks for delivery-method-conditioned messaging are commented out in source, indicating earlier iterations of this validator were replaced.*

Constraints and usage notes

  • Callers must populate DeliveryMethod before validation, since several rules key off its value to decide whether email or fax fields are mandatory.
  • The email length rule caps EmailAddress at 60 characters to match backing storage.

Note: Statements marked with * were inferred from code structure, naming conventions, or contextual evidence where direct confirmation was not available in source artifacts. Statements marked with ** could not be confirmed; treat as unknown until verified.

Sources

  • Services/SAIF.Services/Policies/Certificates/Validators/CertificatePreferenceValidator.cs