EPiServer  /  CMS June 29, 2010

Please make PageData.LinkURL virtual – Or why Joe can't sleep

Joe is building a website using EPiServer CMS. As he’s a curious fellow he’s decided to give test driven development a try.

Let's say Joe creates an abstraction of DataFactory.

Also, let's assume that Joe creates a really nice fluent API for creating PageData objects for using when testing.

Further, let's also say that Joe uses the MVP pattern.

Finally, Joe writes a unit test that simply checks that a presenter displays links to children of the start page.

Joe writes the test and it fails as expected. Joe goes on to implement code that satisfies the test. Joe is excited.

Only the test doesn't pass. All that adrenaline that has been built up in Joe. That rush. It's all gone in an instant. Joe stares at the screen. There he reads:

System.TypeInitializationException: The type initializer for 'EPiServer.DataFactory' threw an exception. ---> System.ArgumentException: The application relative virtual path '~/' is not allowed here.

Finally Joe realizes that PageData.LinkURL must be calling DataFactory. Hopeful, Joe goes on to stub out that behavior.

Alas, his screen still reads:

System.TypeInitializationException: The type initializer for 'EPiServer.DataFactory' threw an exception. ---> System.ArgumentException: The application relative virtual path '~/' is not allowed here.

It turns out PageData.LinkURL isn't virtual.

On the outside, Joe's colleagues watches when Joe bravely creates a public virtual method on his presenter that returns the link URL for a PageData object and then goes on to create a partial mock of his presenter.

On the inside he's crying.

Later that night, as he's trying to fall asleep he just can't help but think about the days' events. He remembers Anders Hejlsberg saying "The pragmatic school of thought, which comes from building real applications that run in the real world, says, 'We've got to be real careful about what we make virtual'".

Doesn't Joe live in the real world? Is that's what Anders is saying? Is there something wrong with Joe? Perhaps he wasn't meant to write well designed code. Code that he can be proud of.

Then he thinks back to reading Michael Feathers words. At least he's not alone.

Exhausted Joe finally falls asleep. Tomorrow a brave new day awaits.

As usual the name of the boy in the story isn't his real name.

Also, Joe isn’t really creating any fluent API’s for creating PageData objects, but it might be a good idea for him to keep an eye on what happens in the trunk for EPiAbstractions :)

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