c# - Roll your own assertion (and do something fun with the methods)? -


i couldn't think of way describe i'm trying question title--which may why couldn't google it. either titling or googling hot.

here's code i'm looking for:

assert.that(true == false); 

...or...

assert.that(true == false).else<argumentexception>(); 

at point, can make second 1 work or can make first 1 work. (the first 1 throws general "assertionfailedexception", keep default in event .else() part isn't supplied.

is there way can make these both work?

the problem is, time that has been evaluated runtime, doesn't know there additional method call (else) make. frameworks nunit use different syntax avoids problem:

assert.that(somevalue, is.not.equalto(someothervalue))

you construct constraint, pass assert.that, nunit actual validation , exception throwing.

you introduce syntax (using nunit again example):

assert.that(somevalue, is.not.equalto(someothervalue).else<argumentexception>());

that way, configuring exception throw if assertion fails part of constraint configuration.


Comments

Popular posts from this blog

android - Get AccessToken using signpost OAuth without opening a browser (Two legged Oauth) -

org.mockito.exceptions.misusing.InvalidUseOfMatchersException: mockito -

google shop client API returns 400 bad request error while adding an item -