Skip to main content

Posts

Showing posts from February, 2011

Improving “Boiler Plate” Data-Reader Code – Part 2

In Part 1 of this series we started with a basic Data-Reader / SQL Connection/Command pattern and illustrated how it is possible to abstract the parsing of the Data Reader into a standalone object that can be fully unit tested in isolation of the calling code.   In Part two of the series we will highlight a very simple optimisation that can be made to the “DataReader” convertor and the required update to the tests to capture/verify the changes.  In this revision the original “CustomerDRConvertor” has been updated to include extremely basic caching, which for the duration of the object’s existence should ensure that only the first call needs to reference the “GetOrdinal(…)” method to find the element index of each desired column.  Subsequent calls can then use this “cached” index to reference the column by position rather than name.namespace DataAccess.Example { using System.Data; using System.Data.BoilerPlater;
public classCustomerDRConvertorPart2 : IConvertDataReader<Customer> { priv…

Improving “Boiler Plate” Data-Reader Code – Part 1

Recently we’ve been looking at improving our unit test code coverage and reducing the amount of duplicated code around our bespoke data access layer.  Where possible we have moved over to NHibernate but certain parts of the data access must still be written using the standard ADO.NET connection/command pattern.  Typically hidden right in the middle of this bespoke code is a while loop that is pivoting a data reader into a POCO that is impossible to repeat-ably unit test in a stable environment unless you set up a dedicated data repository for testing or try to wrap up / mock the connection / command objects.   Neither of these options are really desirable as we aren’t really interested in testing / mocking the .NET provider data access objects.To get around this issue we looked into how we could generate some boiler-plate code that we could roll out across our code base.  This code base will be introduced step by step during this series with the first step covering the abstraction of …

MVC3.0 Installation Hangs

I've just installed MVC3.0 on a fresh PC using the new web installer application and was surprised at how long it seemed to be taking.  Digging around a bit deeper I remembered that in the options I'd selected to use IIS rather than IIS Express and taking a quick look at the service panel highlighted that IIS was currently stopped.  I restarted IIS and the MVC3.0 installation finished in seconds!So if you're having problems installing MVC3.0 then just take a moment to check that IIS is started.

VS2010: How to change a "Class Library" project into a "Test Project"

Whilst working with VS2010 projects it can be really frustrating if you accidently create your unit testing projects as class libraries (or migrate an existing class library into a unit testing library mainly because the context sensitive "Add New" menu no longer contains the "New Test" option.  This can be easily fixed by directly amending the project file, adding the following key to main tag:<ProjectTypeGuids>{3AC096D0-A1C2-E12C-1390-A8335801FDAB};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}</ProjectTypeGuids> Reload the project in VS2010 and now your class library has become a testing library and you have "Add New Test" option(s) back again.