SMTP Unit was written to help facilitate the testing of code that sends email without needing to use a real SMTP server to validate what was sent.
Now of course in your own code you have well defined interfaces and your test code has mocks (of those interfaces) and you don’t need a real SMTP server. Sometime though you need to use a library that doesn’t provide you the ability to do that, or maybe some legacy code, or maybe you just want to integration test your system with something as close to a production configuration as possible. This is meant to help out in all those cases.
It is written as additional constraints to NUnit and as such the idea is to allow you to write test code such as the following:
Assert.That(smtpServer, Received.Mail(1).From("[email protected]"));
Assert.That(smtpServer, Received.Mail(1).Subject("Welcome to SMTPUnit"));
Assert.That(smtpServer, Received.Mail(1).BodyContains("Aren't automated test so great!"));
See documentation for further details but it is as simple as:
// Setup
var mockServer = new DummySmtpServer();
mockServer.Start();
// Act – call your code to send email here
// Assert
Assert.That(mockServer, Received.Mail(1).From("[email protected]"));
Since it is written as an NUnit constraint, there is a dependency on NUnit. There are no other dependencies if you wish to use SMTPUnit.
The test code for SMTPUnit however also has an additional dependency on HMX Core. This is not needed unless you wish to develop/contribute to SMTPUnit.
Much of the code is documented inline and the XML documentation files are included as part of the downloads. We are looking into hosting MSDN style documentation online but this is not yet available.
An example project is included in the source code also.
All versions are available either packaged as a NuGet package from NuGet or as a zip artefact from the HMx Labs website
HMx Labs Core is Open Source software and is licensed under an MIT style license. This allows use in both free and commercial applications without restriction. The complete licence text is available on the HMx Labs website or here
If you’ve found a bug or thought of a new feature that would be useful feel free to either implement it and raise a pull request for us or if you’d like us to take a look then just get in touch.
Support is provided very much on a best effort only basis and by electronic means (emails, pull requests, bug reports etc) only.
Unless you’re a client of HMx Labs of course, in which case just give us a call!