Validating method return values

Nov 14, 2011 at 5:48 PM
Edited Nov 14, 2011 at 5:51 PM

Hi

   Suppose I have an integration test which checks that a file was successfully created. My first attempt to do this with SharpTestEx:

 

File.Exists( testFilePath ).Should().Be.True();

 

   This works, but when it fails (file doesn't exist), in NUnit and Resharper, the message I see is:

"False should be True"

This is not very informative. Is there a way to perform this assertion so that the error message displays the name of the method (File.Exists), and possibly parameters and values? I'd like to see something like this:

File.Exists( "C:\Temp\foo.txt" ) should return True

In any case, it would also be nice to write something like this:

 

File.Exists( testFilePath ).Should().Return( true );

 

I am willing to help implement this

 


 

Best Regards

Coordinator
Nov 15, 2011 at 10:53 AM

@"c:\yourfile.txt".Satisfies(x=> File.Exists(x));

Nov 15, 2011 at 11:44 AM

Thanks, I just tried that and it worked great. Just one detail: the method is called "Satisfy", not "Satisfies", in my version. I'm using 1.1.1.0, NoSpecificFramework (I know I could be using the NUnit version, but I ran into some issues when I tried to run this in the Continuous Integration server -Team City-)

Coordinator
Nov 15, 2011 at 4:06 PM

In the new version you will have "Satisfy", for backdraw compatibility, and Satisfies (as the correct verb).

"Satisfy" is there because originally I was thinking in actual.Should().Satisfy(...) but then I removed the "Should" without fix the verb.