Having some difficulty mocking a content type onto a mocked IPublishedContent. Seems there's no interface to PublishedContentType, and the constructor is protected/not accessible.
Ignoring the last line, that works fine to mock out the content.
Is it possible to mock the type as well? Should I just live with 99% test coverage because I can't hit the statement that needs to check the content type ID?
I've taken an alternate path and actually scaffolded out a content tree, populated with real content, but that then has it's own issues where the IPublishedContent versions aren't available due to the cache resolver not being initialized (or something like that).
Nice. Thought I'd read every blog post ever written about testing Umbraco.
I'm in a strange purgatory where I'm wanting to do integration and unit testing, probably more of the former than the latter. So I need a functioning database (which I have), but also need a full Umbraco context, which I kind of have.
Mocking ContentType on IPublishedContent
Having some difficulty mocking a content type onto a mocked IPublishedContent. Seems there's no interface to PublishedContentType, and the constructor is protected/not accessible.
Ignoring the last line, that works fine to mock out the content.
Is it possible to mock the type as well? Should I just live with 99% test coverage because I can't hit the statement that needs to check the content type ID?
I've taken an alternate path and actually scaffolded out a content tree, populated with real content, but that then has it's own issues where the IPublishedContent versions aren't available due to the cache resolver not being initialized (or something like that).
Any suggestions would be awesome.
P.S. testing is fun.
Hi Nathan,
I think directly mocking is not possible because the ContentType is a concrete class.
I use Unit testing adapter from Lars-Erik and that has method to "mock" it
https://github.com/lars-erik/umbraco-unit-testing-samples/blob/master/Umbraco.UnitTesting.Adapter/Support/UmbracoSupport.cs#L200
Dave
Nice. Thought I'd read every blog post ever written about testing Umbraco.
I'm in a strange purgatory where I'm wanting to do integration and unit testing, probably more of the former than the latter. So I need a functioning database (which I have), but also need a full Umbraco context, which I kind of have.
Will keep plugging away...
is working on a reply...