I am using Fluent API to validate the payload in my API. Street Address/MailingAddress/Lockbox Address are three different properties in the domain model. I want to make sure in my validation that Street address and mailing address is only passed once.
Correct Payload
{
"id" :123,
"name":"test",
"streetAddress": {
"city":"London",
"address":"q23"
},
"MailingAddress": {
"city":"NewYork",
"address":"q2453"
},
"LockBoxAddress": {
"city":"Miami",
"address":"q23888"
}
}
Domain Model
public string id{get;set;}
public string name{get;set;}
public Address streetAddress{get;set;}
public Address MailingAddress{get;set;}
public Address LockboxAddress{get;set;}
Incorrect Payload
{
"id" :123,
"name":"test",
"streetAddress": {
"city":"London",
"address":"q23"
},
"streetAddress": {
"city":"NewYork",
"address":"q2453"
}
}
I would like the above payload to error out by saying you cannot pass multiple street addresses and I am using Fluent API
Fluent API
RuleFor(x => x.streetAddress).Count(x =>x < 2).When(x => x.streetAddress!= null);
There is no property to get the count for the model. Any Ideas?