Recent posts

Book Review: Art of Unit Testing

image Somehow this year has been one where I spend a lot time reading. Last week I finished Roy Osherove's The Art of Unit Testing, and I've almost finished reading Kent Beck's TDD by Example. After that, I'll jump right into Robert (Uncle Bob) Martin's Clean Code; A Handbook of Agile Software Craftsmanship.

I met Roy about two years ago when I, Don Smith and Olaf Conijn attended a late-night dinner during the 2007 TechED Europe in Barcelona. The funny thing is that I don't even remember what his sessions were about, but I won't forget the fact that he finished them with some hilarious guitar playing. I do remember though some guys from the company behind TypeMock stalking him. And apparently that worked; he is now one of the company's most visible employees. Since then he has blogged a lot of about Test Driven Development and Unit Testing, so I was really eager to read his recent book, The Art of Unit Testing.

Let me start by making it very clear that this book is not about Test Driven Development. One of my colleagues recommended it when somebody else asked about a good book about TDD. If you're looking for that, refer to Kent Beck's TDD by Example, Jimmy Nilsson's Applying Domain Driven Design or the many blog posts written by Jeremy D. Miller. At least, those are the ones that helped me get started.

The book does a great job in explaining the advantages of mocking frameworks in comparison to hand-written stubs and fakes. And since Roy is working for TypeMock these days, I was really expecting him to plug their product TypeMock Isolater throughout the entire book. But I'm not sure whether he was already working for that company at the time he had written the book, I never found him suggesting one product was better than the other.

One thing I didn't like were some his examples in chapter 6. From my point of view, he was demonstrating how to end up with obscure tests. Especially his suggestion to refactor all kinds of shared logic to a general setup method or a test base-class causes the stuff you need to know to understand a test to end up on lots of different places. xUnit Patterns has some much better solutions for solving such problems. And as in many test-related books and articles, it seems that almost nobody is mentioning the patterns of all patterns, the Test Data Builder. That one has proved to really help keep my unit tests readable.

Also, if Roy is ever going to publish another edition, it would be nice to add an intro on Behavior Driven Development (BDD) as well. BDD really helps to ease the thinking process of writing proper specifications.

All in all, I think this book deserves a score of 3.5 (on a scale from 1 to 5). In essence it is a great introduction to everything you need to know to get started with unit testing. Especially chapters 7 and later provide very useful guidance on how to get started and how to deal with the more difficult challenges, both technical as organizational. He shares a lot of his own experiences, and I particularly liked the ones where he failed because he's not afraid to share the lessons he learned himself. Granted, Gerard Meszaros' xUnit Patterns contains a lot more in-depth coverage of proper test automation, but Roy's book manages to cover all aspects in a very readable form.


Published: 29-09-2009 by Dennis Doomen | 0 Comments | 0 Links to this post
 

Communities are so awesome!

Tonight I had the pleasure of attending an awesome session by Greg Young about Domain Driven Design used in enterprise systems. Thank to Jonne for reminding me and pointing towards Devnology a great new community for software developers from different technology backgrounds.

For all who like to extend their knowledge and meet their peers, communities event are the place to be!

Check out:

Devnology

.NET gebruikersgroep Nederland

Software development network


Published: 17-09-2009 by Hans ter Wal | 0 Comments | 0 Links to this post
 

Rhino security with Unity

If you are using NHibernate and need an integrated authorization framework, then have a look at Rhino Security. Rhino Security is a security framework developed by Ayende, creator of Rhino Mocks and the Nhibernate Profiler, among other things. 

Rhino Security automatically adds entities and services to your application for managing security. It provides the ability to decorate your own User entity with an IUser interface, making it suitable for use in authorization. There is the notion of user groups (Roles), operations, entities, entity groups and permissions. Authorization is done based on both operation and entity level. So you can define permissions for users and usergroups on operations, entities and even groups of entities.

It is amazingly flexible and even adds the ability to filter queries based on permissions. So for example, as a marketing manager, you only get to see the products you have permissions for.

For more information on how to use Rhino Security checkout:

- Ayendes blog: http://ayende.com/Blog/category/548.aspx

- Bart Reyserhove’s blog: http://bartreyserhove.blogspot.com/search/label/rhino%20security

Rhino security used to have dependencies on Castle Windsor and Rhino Tools, making it quite hard to use if you had already chosen another IOC container, like Unity for example. Luckily, in the latest version, Ayende has eliminated those dependencies and swapped them out for the Common Service Locator.

Common Service Locator

For those of you who are unfamiliar with the Common Service Locator, the Common Service Locator is a shared interface for IOC containers available on codeplex, which abstracts the specifics of IOC containers. The goal of this generic interface is to have frameworks only rely on this generic interface, making it possible for the users of the framework to plug in the IOC container they are using. So, because Rhino Security is now making use of this Common Service Locator, it is now possible to have it use our own Unity container, this way having better integration.

So, how do you use Rhino Security with Unity?

Using Rhino Security with Unity

First, get the latest version of Rhino Security from Github:

http://github.com/ayende/rhino-security

Next, get the latest version of the Unity adapter for the Common Service Locator from codeplex:

http://www.codeplex.com/CommonServiceLocator

Now what I did is write a Unity container extensions to provide the Rhino Security integration:

    /// <summary>
    /// Custom extension that sets up the dependencies needed to use Rhino Security.
    /// </summary>
    public class UnityRhinoSecurityExtension : UnityContainerExtension
    {
        protected override void Initialize()
        {
            // Setup dependencies needed by Rhino Security.
            Container.RegisterType<IAuthorizationService, AuthorizationService>();
            Container.RegisterType<IAuthorizationRepository, AuthorizationRepository>();
            Container.RegisterType<IPermissionsBuilderService, PermissionsBuilderService>();
            Container.RegisterType<IPermissionsService, PermissionsService>();

            // Make our Nhibernate Session available to Rhino Security.
            Container.AddNewExtension<StaticFactoryExtension>();

            Container.Configure<IStaticFactoryConfiguration>()
                .RegisterFactory<ISession>(GetSession);

            // Indicate that Rhino Security should use our Unity container for looking up dependencies.
            ServiceLocator.SetLocatorProvider(() => new UnityServiceLocator(Container));
        }

        private static ISession GetSession(IUnityContainer container)
        {
            return container.Resolve<ISessionManager>().Session;
        }
    }

In the GetSession method you have to return the instance of the Nhibernate Session you are using. After this, add the extension to your container:

container.AddNewExtension<UnityRhinoSecurityExtension>();

The following line in the extension configures the Common Service Locator to use the Unity adapter and passes the instance of the container we are using:

ServiceLocator.SetLocatorProvider(() => new UnityServiceLocator(Container));

Now the only thing left to do, is to give Rhino Security access to our Nhibernate configuration, so It can add the mappings for its own entities. We are using Fluent Nhibernate, which makes our configuration look like the following:

return Fluently.Configure()
    .Database(MsSqlConfiguration.MsSql2005.
                  ConnectionString(
                  x => x.FromConnectionStringWithKey(ConnectionStringConfigKey))
                  .ProxyFactoryFactory(typeof (ProxyFactoryFactory).AssemblyQualifiedName))
    .Mappings(m => m.AutoMappings.Add(AutoPersistenceModel.MapEntitiesFromAssemblyOf<User>()))
    .ExposeConfiguration(cfg => Security.Configure<User>(cfg, SecurityTableStructure.Prefix))
    .BuildSessionFactory();

The following line exposes our configuration to Rhino Security:

.ExposeConfiguration(cfg => Security.Configure<User>(cfg, SecurityTableStructure.Prefix))

Now when you generate the database schema from you Nhibernate configuration, you are able to use the Rhino Security services to implement authorization in you application.


Published: 15-09-2009 by Jonne Kats | 0 Comments | 0 Links to this post
 

A day and night at the NRW09 Conference in Germany

About 1,5 year ago I first met Daniel Fisher when he and two colleagues from NewTelligence, a German consultancy firm, hosted a full-day session on advanced .NET 3.0. During the breaks, we ended up talking about software factories and stayed in contact through MSN and email.

Since then, he started DevCoach, his own company, and became very active in the German .NET community through the Just Community initiative. In 2008, he and Stephan Oetzel organized their first full-day event, the NRW Conference, roughly comparable to our SDN events. Last year he invited me to do a talk in Wuppertal, but due to holiday conflicts I had to drop the opportunity. But this year, I did make it, and it was fun.

The event started on Thursday evening with a speakers dinner in Pöschkes, a local restaurant. Since I wanted to avoid the traffic, I left Rijswijk at around 14:00 and arrived at Wuppertal at around 17:00. I forgot how fun it was to drive the German autobahn where most of it still does not have any speed limit. Diner started not until 20:30, so that gave me some time to take a walk in the vicinity of the Ibis hotel, which by the way, was a simple but descent hotel. Unfortunately, it had no Wi-Fi and my phone's GPRS connection did not work either. I then went to the event location to meet the rest of the speakers, which appeared to be a rather unusual place. Instead of the typical conference center this event was held in a kind of cultural center/club named "Die Börse". Definitely an interesting place to hold an event for developers.

Dinner was excellent, but lasted a bit long and other than Daniel and Stephan it appeared to me that most Germans are a bit too reluctant to speaking English. Fortunately, I was sitting next to Sergey, who accompanied Daniel in the Netherlands, Lars Corneliussen, a very funny but loud German speaker, and Phil Winstanley, the only other non-German speaker. Although very young, he appeared to be a seasoned speaker and has been MVP for many years. The three of us enjoyed some interesting discussions throughout the entire evening and finished the night at around 01:00 with a final drink at the hotel's bar.

The next morning at 8:00 we all met at the venue to receive some drinking coupons and our speakers shirt. The first session started at 9:00 with a rather spectacular recap of last years edition and some encouraging words from the organization. Luckily I do understand German (although I don't speak it that well).

My session started at 11:10 and appeared to last only one hour instead of the usual 75 minutes. The session was held in the main room where the keynote was held, so it looked rather empty, even though there were about 35 people in it (of the 102 attendees in all four tracks). The talk ran fast and reasonable smooth, but at the end, nobody asked questions. However, I got a score of 1.7 on a scale between 1 (excellent) and 6 (aweful) so it is probably the language. Most Germans are not accustomed to speaking English even though I did not expect that from a developer community. Phil, who gave an excellent interactive talk on ASP.NET MVC versus WebFoms did not get any questions either.

I also attended Sergey's session on Orthogonal Architecture where he explained how you could apply the S.O.L.I.D. principles on an architectural level. I found that idea very interesting, so I just might ask Sergey whether I could use his slides to do this talk in the Netherlands. Since I had plenty of time to spare I also went to a talk on JQuery delivered by a German speaker I forgot his name off. I have not used JQuery yet, but I see why Microsoft decided to include it in the next version of ASP.NET. At around 18:30, after attending Phil's session and having dropped him off at the Dusseldorf airport, I finally drove back home.

You can view (or download) the slides below and download the source code of my demos from here.


Published: 01-09-2009 by Dennis Doomen | 0 Comments | 0 Links to this post