/ 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.

Aaron Job

Aaron Job

It all started at age 10 with an Amstrad 80386SX and a book. That book Computer Space-games made no sense to that 10-year-old but it kicked started an obsession with programming.

Read More
Mocking an Umbraco Node
Share this

Subscribe to public abstract Gravy : Power