Skip to content
Kam Figy edited this page Oct 2, 2013 · 1 revision

In Blade itself, the SitecorePresenter has been modified to allow injection of a custom Item as the data source of the presenter (via the SetDataSource() method), enabling you to decouple it from data source resolution logic. However, you probably should not be testing with Item instances, as those require a lot of Sitecore API presence. To get around this issue, Synthesis.Blade's SynthesisPresenter enables injection of a custom Synthesis item interface directly into its GetItem method for completely Sitecore-independent tests! Check out this trivial example of testing a SynthesisPresenter, using Moq:

var item = new Mock<ITestTemplateItem>();
var view = new Mock<IView>();

// todo: setup mocks appropriately

var presenter = new TestPresenter();

var model = presenter.GetModel(view.Object, item.Object);

// todo: assert something about the resultant model

Testing limitations

Views are not particularly testable due to them using the MVC Razor engine, which requires a web context to execute. Hypothetically you could write tests against them using a web-based test runner, but it seems that most people do not recommend testing the view due to the relative fragility of the tests involved.

Clone this wiki locally