U4-5853 - Create interfaces for umbracohelper parts

Created by Anthony 20 Nov 2014, 16:44:43 Updated by Shannon Deminick 05 Jun 2015, 16:30:56

Sometimes it is necessary to do something like UmbracoHelper.TypedContent(id) inside some business logic.

However, instantiation or passing the UmbracoHelper into the method both make methods not unit testable. To be able to unit test, we need to mock the UmbracoHelper. It would be preferable if we could just pass around an IUmbracoHelper.


Anthony 20 Nov 2014, 17:06:02

Created a pull request:


Shannon Deminick 20 Nov 2014, 22:51:32

There's a discussion here:


This requires a little more thought than just chucking in an interface.

Shannon Deminick 20 Nov 2014, 22:55:29

There's plenty of methods on there that don't belong there, or need to be moved into separate/sub classes. I don't think the UmbracoHelper needs to be interfaced, it just needs to be created with sub classes/interfaces.

For example, the Truncate methods, are just string methods, they don't need to be mocked, they just do what they are supposed to. However, if we did want to go that route, we'd create an interface like IHtmlStringHelper that can be used to create an UmbracoHelper which the UmbracoHelper wraps.

Same goes for things like TagQuery - we could interface that and UmbracoHelper wraps it, same goes for all of the other methods in there like all of the content query methods - these are already wrapped by ContentQuery which itself could be interfaced.

I agree this work needs to be done, but it's not just about interfacing a big helper class that has just become too big for it's own good, it needs to be broken down in to it's correct parts.

Shannon Deminick 04 Feb 2015, 07:26:39

New PR is here: https://github.com/umbraco/Umbraco-CMS/pull/632

Priority: Normal

Type: Feature (request)

State: Fixed

Assignee: Shannon Deminick

Difficulty: Normal

Category: UI

Backwards Compatible: True

Fix Submitted: Pull request

Affected versions: 7.1.8

Due in version: 7.3.0


Story Points: