jwaliszko / ExpressiveAnnotations

Annotation-based conditional validation library.
MIT License
351 stars 123 forks source link

Assert That depending on another condition #140

Closed kevinXYX closed 7 years ago

kevinXYX commented 7 years ago

I want to Assert That depending on another condition for example

if Nationality is Filipino then txtValue1 must be equal to txtValue2 how do i do that?

[AssertThat("nationality == 'FILIPINO' && (txtValue1 == txtValue2)", ErrorMessage = "The selected nationality is Filipino the textValue1 must be equal to textValue2")]

doesn't work.

jwaliszko commented 7 years ago

Your assertion doesn't do what you'd like it to do, because there is no implication there. What you want is:

[AssertThat(@"nationality == 'FILIPINO' ? txtValue1 == txtValue2 : true")]
public string txtValue1 { get; set; }

If you'd like to choose the other way around, without conditional operator, make your statement more complete, i.e.:

[AssertThat(@"(nationality == 'FILIPINO' && (txtValue1 == txtValue2)) 
              || (nationality != 'FILIPINO')")]
public string txtValue1 { get; set; }
kevinXYX commented 7 years ago

Thank you! and thank you for the awesome library.