/ Umbraco

Mocking an Umbraco Node

UPDATE:
Fluently Mocking an Umbraco Node


For the last few months, I have been working on an example showing that it is possible to produce sites on top of a CMS in a TDD manner. The aim is to get more people using TDD by giving a starting point.

Currently, I am implementing this in Umbraco and have built this method that others might find useful.

public class MockNodeFactory
{
    public static INode BuildNode(IDictionary<string, object> properties)
    {
        var node = Substitute.For<INode>();
        foreach (var pair in properties)
        {
            var property = Substitute.For<IProperty>();
            property.Alias.Returns(pair.Key);
            property.Value.Returns(pair.Value);
            node.GetProperty(pair.Key).Returns(property);   
        }

        return node;
    }
}

It has a dependency on NSubstitute however you should be able to swap that out for your favourite mocking framework.