Book Image

Testing with F#

By : Mikael Lundin
Book Image

Testing with F#

By: Mikael Lundin

Overview of this book

Table of Contents (17 chapters)
Testing with F#
About the Author
About the Reviewers

Dealing with databases

The most common question when it comes to unit testing is how to remove the dependency to the database. I have already touched upon a set of techniques on how to use test doubles in order to get around dependencies, but I wanted to use this section of the chapter to take a concrete example of a database and show how to get around it.

When writing code for connecting with a database, I use the convention of isolating all database code within a module and providing that module with a signature file in order to hide its internals.

This will be demonstrated by writing an e-mail queue that is used for storing e-mails in an SQL database before sending them. This is done because the page load of a web application should not have direct dependency on a Simple Mail Transfer Protocol (SMTP) server. Instead, e-mails are stored in a table and picked up by a Windows service that will do the sending.

First, you need to add references to the System.Data, Sytem.Data.Linq, and FSharp...