Tag Archives: unit testing

Unit Testing while using Entity Framework

I have been recommended to use Entity Framework (EF) instead of LINQ to SQL while building .NET applications. So I pulled out some reference materials, learned the beginning concepts of EF, and started to build an application.

Then I started trying to figure out how to do Unit Testing and Test Driven Development (TDD) while using EF.  What I had read about EF showed me how to build a SQL Server database and then have Visual Studio build the entities for me. I had to design the entire database first and then leave all the classes tied to the database, both of which are incompatible with TDD and Unit Testing.

So I started my Google search, and these are the documents I found really helpful. In the end, Unit Testing and TDD are compatible with EF!  Here is where my journey took me:

TDD and ADO.NET Entity Framework
This late 2008 posting has several people sharing their concerns about using TDD with EF, which is where I was yesterday morning.

Walkthrough: POCO Template for the Entity Framework
Feature CTP Walkthrough: POCO Templates for the Entity Framework
These articles shows how to use the  ADO.NET C# POCO Entity Generator and the Microsoft ADO.NET Entity Framework Feature Community Technology Preview 3 assembly to separate a .edmx Entity Framework file into two groups of classes: the persistence ignorant entity classes (not connected to the database), and the data context class which talks with the database.

Feature CTP Walkthrough: Code Only for the Entity Framework (Updated)

This posting illustrates how to build an EF from code only, without using Visual Studio’s automated generators.  In this process, they were able to keep the persistence ignorant entity classes separate from the database context classes.  This technique required the Microsoft ADO.NET Entity Framework Feature Community Technology Preview 3 assembly.
These articles illustrate how to practically use TDD and EF together!
Now I feel prepared to move forward using Entity Framework together with Test Driven Development methodologies!

Current Reading Materials

My library is steadily growing. Here are some summaries of what I have been reading recently, in no particular order:

Pro C# 2010 and the .NET 4 Platform by Andrew Troelsen
I realized C# is my language of choice now, so I am giving myself a more formal education on the subject.  This book is amazingly written for me.  The author gives great explanations of the programming concepts, uses code in a very informative manner, and keeps moving.  For a book that contains 1700 pages, I am very much enjoying the read.

Integrating Agile Development in the Real World by Peter Schuh
I very much appreciate this introduction to agile development.  The book is very pragmatic, and there is plenty of realism shared about how to get started with agile methodologies, what are the likely pitfalls for businesses, and how/when to partially implement different practices.  I am now sold on the concept of agile development!  I realized while reading the book that I had started trying to use certain practices, and this book helped me understand how to actually make these plans work!

The Art of Unit Testing by Roy Osherove
Unit testing is the next major concept I want to learn and incorporate.  So far, this book seems to be pretty light reading, peppered with very useful concepts for me, the beginning unit tester.  I appreciate his simplicity and useful tips/wisdom.

Agile Principles, Patterns, and Practices in C# by Robert C Martin and Micah Martin
This is a phenomenal book.  Right now I am amazed by chapter 6: A Programming Episode!  This chapter is the dialog reenactment between two programmers while building a simple bowling scorecard program.  I got to actually see how they implemented Test Driven Development, what their thought processes were, how they handled refactoring, and why they approached decisions as they did.  I am excited to keep reading more!

Fire Someone Today by Bob Pritchett
This book has many great insights about running a business.  After building his own computer software business and learning from his mistakes, the author has shared much wisdom that he has learned and been taught.  The book is an easy and fun read, his writing style is very entertaining, and I have seen many great nuggets of wisdom to learn from as I grow my own technology business.

Here are a couple other resource books that I have also been using lately:

Pro ASP.NET 3.5 in C# 2008 by Matthew MacDonald
I LOVE this book!  This book has helped me understand ASP.NET in amazing ways!  I appreciate his ability to reach deep into concepts and bring a clear explanation of what is going on, why, and how to practically implement this technology.  I refer to this book often.

Programming Microsoft LINQ by Paolo Pialorsi and Marco Russo
This is an OK book.  I do not always find what I am looking for, but I do have it, and it at least gives me a good start on what I want to know about using LINQ.