Are you using email in your application but are not sure how to test the email functionality? Simply add the following section to your configuration file and any usages of the .NET framework email will “deliver” your messages as text files in the specified directory. Now your unit tests can read the file contents an assert the email was formed correctly. Note that your application needs permissions to write to the pickupDirectoryLocation specified. I simply granted full access to that directory for all users on my development machine.
1: <?xml version="1.0"?>
2: <configuration>
3: ...
4: <system.net>
5: <mailSettings>
6: <smtp deliveryMethod="SpecifiedPickupDirectory" from="test@codalicio.us">
7: <specifiedPickupDirectory pickupDirectoryLocation="c:\smtp\"/>
8: </smtp>
9: </mailSettings>
10: </system.net>
11: ...
12: </configuration>
Enjoy!
Wouldn't wouldn't sending emails be a dependency anyway, so it should be mocked out. These aren't "real" integration tests anyway since it doesn't talk to an SMTP server, so fake it out all together.
ReplyDelete