woensdag 11 juli 2012

NCrunch: completing the TDD experience

This Saturday, while attending the legacy code retreat of agileminds,  a colleague told me about a tool he’s using called NCrunch.  While I’m a very skeptical person regarding productivity tools, seeing that there is no valid competition for Resharper,  NCrunch rather seems to complete the experience rather than copy it.  The tool is free at the moment but that might change when the beta is over.

Basically what it does is build and run your tests in a separate process.  This alone made me want to back away from it because: how stressful will this be for my processor? Actually I barely notice any performance loss on my PC while developing.  My development laptop is an i5 quadcore with 8 GB ram, rather good but not a power beast.  The very first time you launch NCrunch you get the option to choose how many processor cores you want to use.  I used the typical 2 core setup with the engine mode option set to ‘run all tests automatically’.

It seems ridicules when I say that this tool boosted my performance allot.  Just by running the tests in the background?  Yes! You get a constant feedback of what code is covered, if your tests are green, a build that is not working, ...  Sure you can do this with Resharper and Dotcover.  But with NCrunch the feedback is in real time.  No need to build and no need to use alt + r + u + n (shortcut in resharper for running tests).  Actually since I’ve been using NCrunch, I’ve barely build and run my tests manually.  This saves me a bunch of time.

Instead of boring you with more fan ramblings, try it out yourself!  It’s free at the moment so no harm in trying.  Until next post!

maandag 9 juli 2012

Extensions for Entity Framework Code First

A couple of months ago I blogged about an extension I wrote to execute a stored procedure more easily with Entity Framework CodeFirst.  It certainly bumped up the number of visitors I got on my blog, which I of course love to see, but it also made me think of so many things that are missing in EF CF.

During my time spend on a project that uses EF CF, I’ve bundled some extensions I wrote to facility my needs and to make developing a whole lot easier.  It surprises me that the Entity Framework team didn’t ship these features in their release. 

Below you’ll find an explanation for every extension I wrote.  The code is on github, so feel free to make any additions as you like.

1.  Executing Stored Procedures

I already wrote an extensive blog post about this one so feel free to read it here.

To  summarize, the extension allows you to execute a stored procedure as so:

var testProcedureStoredProcedure = new TestProcedureStoredProcedure() { Iets = 5, NogIets = true };
var result = DbContext.Database.ExecuteStoredProcedure(testProcedureStoredProcedure);

I’ve made a small addition that now you can decide which class will be used to resolve the stored procedure name: the result class or the stored procedure class.

2.  Map to custom dto’s with ESQL

By default you can only map to entities when using ESQL. If you write your select statement explicitly then you get a DbDataRecord.   This is a PIA when customizing you selects to minimize data transfer.  The extension I wrote can map all selected fields to your dto.

var query = _unitOfWork.CreateQuery<DbDataRecord>(queryString);var dtos  = query.Map<YourDTO>();
3. Retrieve the DbSet with a generic

The datacontext object of EF CF exposes a number of DbSet’s.  I found it quit useful to be able to generically address these DbSet’s.  So I’ve come up with the following solution.  With this extension you can select a DbSet by supplying the type of the entity as a generic.


4. Include with lamda

Why on earth they didn’t include this in version 1.0 I have no idea but unless you’ve already wrote your own extension for it (probably!), I’ve included a way to do this in the extensions project also.  Basically it enables you to write:

EntitySet.Include(x => x.NavigationProperty)

So that’s about it.  You can find the code on github.  As I’ve said, I’m happy to accept any useful additions to the code base.
Have fun coding, till next time!

woensdag 4 juli 2012

Stateless service

Taken from the BelFirst service specifications:

3. General Principles

3.1 Stateless service

While using the web service a state is maintained on the server. This allows the interface to use more atomic operation and hence richer functionality. Using the web service is done with a short session consisting of different calls$

Good job guys... /s