EPiServer  /  CMS August 09, 2010

A toolset for building testable and flexible EPiServer CMS sites

Page Type Builder and EPiMVP or future MVC support in EPiServer CMS provides building blocks for creating well-architected and testable web sites using EPiServer CMS. However, the development experience, especially when it comes to testing isn’t always enjoyable. EPiAbstractions aims to solve that.

The new EPiAbstractions

Almost a year has passed since I first released EPiAbstractions. At that time EPiAbstractions was a project that I primarily created to be able to develop my blog using test driven development (TDD). It provided wrappers around all handler classes in EPiServer Community and for a lot of classes in EPiServer CMS. Since then a few things have changed. With the release of EPiServer Community 4 the Community team at EPiServer has opened up the framework for testing by switching from static methods to virtual instance methods in the handlers. Furthermore the CMS team has begun working on opening up the CMS for testing with the introduction of a IDataFactory interface among other things.

So, the EPiAbstractions project that I released a year ago has been rendered unnecessary for Community and it will hopefully also be rendered unnecessary for CMS with the next release of EPiServer CMS. However, during the last year, and especially the last few months, the project has evolved quite a bit. The abstractions for Community has been removed (though you can certainly use them in an older version) and focus has shifted from just wrapping classes in EPiServer CMS to actually making it easier and more fun to build well-architected applications using TDD with EPiServer CMS.

In this post I’ll provide an overview of what EPiAbstractions is today and in a series of subsequent posts I’ll drill deeper into the different parts.

Source code on GitHub

The source code has been moved to GitHub to make it easier for others to contribute or fork the project. You’ll find the repository here. The CodePlex site is still around though and any releases will be hosted there. At the moment there is a release with version number 1.9 on the CodePlex site I strongly recommend you to grab the source code from GitHub and compile it yourself (just run build.bat).

Modules

EPiAbstractions now consist of four assemblies, three of which are new.

EPiAbstractions

EPiAbstractions.dll provides facades for many classes in EPiServer whose methods are either static or non-virtual. These facades consists of two parts, an interface named I<originalClassName>Facade (such as IDataFactoryFacade) and an implementation named <originalClassName>Facade (such as DataFactoryFacade). The implementation maps directly to the original class in EPiServer CMS.

The implementations also have singleton implementations (such as DataFactoryFacade.Instance), however I strongly recommend you not to depend on these. That is, code that you write should depend on the interfaces and whatever implementation is used should be injected into your components. See my introduction to Inversion of Control for a discussion about dependency injection.

Hopefully this module will become unnecessary with the next version of the CMS.

EPiAbstractions.Opinionated

A while back I wrote about that I wanted to create an “opinionated” abstraction of DataFactory. That is basically a wrapper around EPiServers DataFactory that didn’t have a direct mapping to it’s methods but rather consisted of the methods that I saw was used most often and new methods that was better suited for my needs and how I built sites using EPiServer CMS (using Page Type Builder etc). EPiAbstractions.Opinionated is the result of this. It currently includes two main concepts, PageRepository which is a substitute/complement for DataFactory and EPiServerContext which basically is a convenient way to bundle a PageRepository and PageReference (actually an IPageReferenceFacade).

Even if you aren’t that into testing and flexible architecture but use Page Type Builder you’ll probably find this module interesting.

EPiAbstractions.FixtureSupport

The goal of the FixtureSupport module is to make it easier to create realistic but fake PageData objects (and in the future perhaps other types of objects) by providing a semi-fluent API for doing so. This is something that I’ve seen others do in other projects so I’m hoping to get some feedback and hopefully also some contributions for this part.

EPiAbstractions.Fakes

The fakes project is the final piece of the puzzle to make it enjoyable to build sites using TDD with EPiServer CMS. It provides fake versions of the IPageRepository, IPageReferenceFacade and IEPiServerContext interfaces. These fakes can greatly reduce the need for mocking when creating unit tests for your code. It’s far from finished but my experiences so far has been positive as it has made my own tests much easier to understand and lowered the threshold to get others to write unit tests.

Part of a greater ecosystem

Much of EPiServer CMS’s strengths, both in the past and currently, have been that it enables rapid development of small to medium sized sites. However many of the sites that we are building with it today are quite complex and demands a different type of development in order for them to be maintainable, tested and to ensure good performance.

Much of the new functionality in EPiAbstractions has been developed during the last few months and immediately tested in a real project that I’ve been working on. In that project we have also been using Page Type Builder and EPiMVP. During this time it has become clear to me that, while much work remains to be done, the three projects are starting to form a nice little “ecosystem” for developing web sites in a very object oriented, testable and structured yet flexible way.

In future posts I’ll show you some of what I mean by this with code samples illustrating how you can use the Opinionated, FixtureSupport and Fakes modules.

PS. For updates about new posts, sites I find useful and the occasional rant you can follow me on Twitter. You are also most welcome to subscribe to the RSS-feed.

Joel Abrahamsson

Joel Abrahamsson

I'm a passionate web developer and systems architect living in Stockholm, Sweden. I work as CTO for a large media site and enjoy developing with all technologies, especially .NET, Node.js, and ElasticSearch. Read more

Comments

comments powered by Disqus

My book

Want a structured way to learn EPiServer 7 development? Check out my book on Leanpub!

More about EPiServer CMS