-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
6199eb6
commit 80c1310
Showing
1 changed file
with
6 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -27,7 +27,8 @@ using FluentValidation; | |
public record Attendee( | ||
string Name, | ||
int Age, | ||
Option<string> EmailAddress); | ||
Option<string> Email, | ||
Option<string> AlternateEmail); | ||
|
||
public class AttendeeValidator | ||
: AbstractValidator<Attendee> | ||
|
@@ -36,14 +37,16 @@ public class AttendeeValidator | |
{ | ||
RuleFor(x => x.Name).NotEmpty(); | ||
RuleFor(x => x.Age).GreaterThan(0); | ||
RuleFor(x => x.EmailAddress).WhenSome(x => x.EmailAddress()); | ||
RuleFor(x => x.Email).Required(x => x.EmailAddress()); | ||
RuleFor(x => x.AlternateEmail).Optional(x => x.EmailAddress()); | ||
} | ||
} | ||
var input = | ||
new Attendee( | ||
Name: "John Doe", | ||
Age: 30, | ||
EmailAddress: Option<string>.None()); | ||
Email: Option<string>.Some("[email protected]"), | ||
AlternateEmail: Option<string>.None()); | ||
|
||
var result = | ||
ValidationResult<Attendee> | ||
|