Category Archives: Ergo

Web.Config Transformations when Debugging

I am a big fan of the Web.Config Transformations that got introduced with a while back. Prior to them being inherently supported one could accomplish the same thing with part of the Enterprise Library, and prior to that one could leverage a custom MSBuild Task or the XMLPoke Task to get your web.config updated based on the environment it was targeting.

Having your configuration elements managed with a transform file makes it a bit easier to manage and keep track of your settings that could change based on environment or settings. Without this each developer on your team might need to create host entries and keep their folder structure the same to ensure the settings work for each of their machines. Another option is each team member just has their own configuration files with their specific settings that they need but when source control is introduced this can get tricky because one developer might be overwriting another’s settings.

Unfortunately, VS.Net doesn’t do any transforming when you are developing and just debugging your local environment. But there are some steps you can do to make this happen if you want.

  • First, create the configurations you want in VS.Net, assuming the default debug and release are not enough for what you are trying to accomplish.
  • Right click on you web.config and select Add Config Transforms – this will create a dependant transformation config for each of your configurations defined.
  • Now you can rename your web.config to web.base.config.
  • Add a web.config to your project. It doesn’t matter what is in it because it will get overwritten every time we do a build but we want it part of the project so VS.Net doesn’t give us the “Your Project isn’t configured for Debugging” pop-up.
  • Edit your .csproj Project File and add the following TransformXml task to the AfterBuild target. Here you can see I will be transforming the web.base.config file using the web.[configuration].config and it will save it as web.config.

For aesthetics, I renamed my transformation files to just web.[configuration].config instead of web.base.[configuration].config and updated the project file like below:


So the transformation files are nested under the web.base.config and the web.config doesn’t have any transformation files because it is the output not the input. Below you can see the setup I have so far for the Ergo project where my web.config would look quite different depending on if I am using Ektron or NHibernate as my data repository.



Unit Testing with an InMemory Database and NBuilder

I am throwing a lot of cycles to my Ergo project lately. I will go into more detail of the Ergo project later when it starts to take more shape and get some legs but one thing it is allowing me to do is get back to a true TDD project. A couple of cool things I have introduced to my unit tests are NBuilder and leveraging Fluent NHibernate and SQLite InMemory to make testing the NHibernate layer a bit easier.

When using NHibernate you generally only need to test 3 things:

  • The Properties are being persisted
  • Cascading works as expected
  • Queries return the correct results

By using an in memory SQLite database we can do this testing while keeping our unit tests nice and speedy. Below is my InMemoryDatabaseTest class that my unit tests can inherit from to test our NHibernate layer.

unit testing1

Now that we have our InMemoryDatabaseTest class setup, we can structure our unit tests like below. One nifty class I found today that you will see in the screenshot is the Builder class. This is from and So instead of having to create a new Page instance and populate it with a bunch of dummy data I can just use 1 line of code to new up a Page which I can then persist to the InMemory database and then use it to Assert against when I query.

unit testing2

Ektron Content Types and AutoMapper

If you are working with Ektron you are probably already aware of Ektron SmartForms and the ability to turn them into strongly typed Content Types. If you are not familiar and want to get up to speed I recommend taking a gander at Bill Cava’s webinar on the subject located here. This is a great step in making it a bit easier to do some CRUD operations on SmartForm content but depending on what your SmartForm looks like, you might get a weird looking Content Type class when just relying on the class creation from using the xsd.exe tool.

Taking the transformation a step farther and turning the Content Type class into a true Domain Object can make your code a bit cleaner and further separate your business layer from your data layer which is always nice. Jimmy Bogard has a nice AutoMapper project located over at CodePlex that you can leverage to move between your domain objects and your SmartForm content types.
Automapper does a nice job of figuring out which field should be mapped to which field and it has the flexibility for you to take control of the mapping at a field or type level. If you have a Rich Text field in your SmartForm you will probably want to do something similar to the sample code below which introduces a custom resolver that makes it easier to map from a string field on the domain object to the corresponding rich text field on the SmartForm.


Ergo: Playing with Ektron and ASP.NET MVC 3

er·go·nom·ics [ur-guh-nom-iks] –noun: human engineering

When I think of Ergonomics I think of being comfortable, it just feels right. I used to think my office chair was fine and I got a really nice Herman Miller Aeron chair and I realized what I was missing. When I think of building a website there is some comfort and things are fine, but I know there is this missing “Ergonomic” comfort to it.

As a side project when I have some free time I will be working on putting together a framework that leverages MVC3, Ninject and Fluent-NHibernate. I want it to be easier to build websites for clients independent of what Content Management System they are using or even if they are not using a CMS.

I am going to call the project “Ergo” and will be posting any hurdles or interesting development approaches along the way. If it ever gets to the point where it might be beneficial for others than I will move the code base to CodePlex, but let’s cross that bridge when we come to it.