Unit-testing System.Net.Mail.SmtpClient
On a recent project I wanted to write unit-tests for a class using a System.Net.Mail.SmtpClient instance. In certain situations, the class should send an email with an attachment. Before I started, I thought I’d simply mock the ISmtpClient interface for this purpose … however, such an interface does not exist.
After doing some research on the web, I came up with the following possible solutions:
- Dumping the mails on disk, by configuring System.Net.Mail.SmtpClient to use a deliveryMethod of type SpecifiedPickupDirectory (example)
- Running a local smtp server to catch my test mails (and then somehow inspect those emails to see if they meet my requirements)
- Writing a mockable wrapper (e.g. implementing “ISmtpClientWrapper”) and pass this wrapper to my consuming class
- Run a simple SMTP server within my unit tests
Of these options, the last one appeared the least intrusive to me. I first used nDumpster (a .NET port of the Java project Dumpster), however it would cause my unit tests to hang. Before figuring out why, I switched to netDumpster, which has (about) the same API. netDumpster ran just fine and enabled me to run my unit tests fast enough.
Installing setuptools on 64-bit Windows 7
I ran into some problems installing setuptools 0.6c11 for Python 2.7 on my Windows 7 (64 bit) machine. When I ran the Windows installer downloaded from the python package index, it gave me the error message “Python version 2.7 required, which was not found in the registry.”. And I’m quite sure Python 2.7 is installed.
Only then I noticed I downloaded a win32 installer - at least it says so in the filename: setuptools-0.6c11.win32-py2.7.exe. I could find no 64-bits installer on pypi.
There appears to be a bug involving setuptools on 64 bits Windows. It is solved according to the tracker, but apparently, nobody has created a 64 bit installer yet.
A quick Google search brought me to a post on hwiecher’s blog where he (?) describes a very simple solution:
- Download ez_setup.py from the PEAK site. (I found it here: http://peak.telecommunity.com/dist/ez_setup.py.)
- Run it! (python [path-to]ez_setup.py
Yep, it’s that simple.
Blogging in reSt on GitHub
I started hosting my blog on GitHub. Why?
There are some requirements that I found hard to meet using a standard blogging engine:
I want to locally edit my blog, using a text editor. (And, by the way, all online blog-editors stink.)
I want to store my blog “source files” in plain(ish) text, with only little markup:
- I can put plain text under source control. (This also gives me an easy backup facility.)
- I like writing in plain text - very little distractions.
- I can easily transform it to multiple output formats.
I’d prefer restructured text (reSt), because I’m familiar with it.
I would like to keep record of my published posts. Which posts were online at what moment in time?
I would like to have some freedom in styling the site. (Even though I’m not very good at it.)
Since I’m already familiar with Sphinx, I decided to write my blog in reSt, run it through Sphinx to produce a static html site and then push the output to my user page on GitHub.
You are looking at the result.
Because the personal page is backed by a git repo, I have full history of my published posts. The source files are stored in reSt and are put under source control [1]. This is a private repository - I have to put my drafts somewhere, right.
There are some thing I’d like to add to this blog:
- An automatically created atom feed.
- Apply categories or labels to blog posts.
- Enable readers to leave comments.
Only the atom feed is a priority to me. I’ll investigate if there’s a Sphinx extension for that.
Footnotes
[1] | In fact I use use a Mercurial repo for the source files, in combination with a private online repository at Bibucket. Mercurial is a nice DVCS too! And I like Bitbucket almost as much as I do GitHub. |