avr. 18
You usually use Moles & Stubs to define mocks in your tests ?
So you may have already coped with a bothering bug in the latest version of Moles & Stubs : all your code relying on your configuration file do not work any longer. Indeed Moles & Stubs is "loosing" you config file.
This is very bothering.

Anyway, there is a simple workaround to this problem, using both the capability of Moles & Stubs, and the code weaving capabilities of an AOP framework. For the example, we are using PostSharp. [Plus]
nov. 19
In many scenario, you will want to generate fields in an existing class of an existing assembly. Let's imagine for example that you want to do some lazy loading in your classes. As a consequence, in all of your properties you will have some code checking if your private backing field has already been loaded or not. For that, you will have two solutions : look the nullity of your backing field, or look a boolean variable "hasBeenLoaded". This second solution is the best. Indeed the nullity can be a valid value and retreiving a "null" from your database shall prevent you from doing another get in your database.

Of course, this solution will result in a lots of cumbersome code that you will need to propagate in all of your classes. So you will probably think "aspect" and so use an AOP framework like PostSharp to do all of this plumbing code. You will find many posts on Internet speaking of dealing with LazyLoading functionality in PostSharp, but they usually deal with the nullity of the backing field.

So how can we use PostSharp (I will use the 1.5 version for this example. The version 2.0 of PostSharp will probably simplify this solution) to generate a boolean field ?

This example (that should be seen more like a proof of concept) will probably make you think of many other cases where you will need to generate some code in an existing class. Here we will generate a simple variable in a class, but the code can be easily adapted to generate a field per existing property. [Plus]
Tags: |
oct. 20
"Recently", thanks to Didier Danse, I discovered PostSharp by Gael Fraiteur : an AOP framework for .NET.
Until that I was doing some AOP emulation using ContextBoundObject, based on what I had read in the book "Applied .NET Attributes" by Jason Bock.

I will not explain here how to use PostSharp - I will do that in further posts - but more explain my love story with PostSharp. Why I started to use it in a testing context to simplify my tests and have clearer (and shorter) ones. [Plus]
Tags: |