Closed stevetemple closed 5 years ago
Hey @stevetemple
Thanks for bringing it here so we can hopefully get it documented for v8!
Quick note: extension methods, being static, have no choice but to use the Current
service locator to resolve their dependencies - here, the IPublishedValueFallback
- which means that setting up a very minimal container is unfortunately required.
The simplest way to do so is:
var factory = Mock.Of<IFactory>();
Mock.Get(factory)
.Setup(x => x.GetInstance(typeof(IPublishedValueFallback)))
.Returns(...);
Current.Factory = container.Object;
Thanks @zpqrtbnk, this is really helpful to know, I'll get some docs together to reflect this once I've tried it out
Hey @stevetemple
We now have a page on unit testing in v8, feel free to add any additional findings to it: https://our.umbraco.com/documentation/Implementation/Unit-Testing/
This issue has been in the up for grabs
state for quite a while now and it seems nobody is ready to pick this one up.
For now we'll close this issue to prevent the list of up for grabs
from becoming very stale. We're happy to re-open it if someone still thinks it's good to work on this.
If anyone is about to pick this issue up to fix it, make sure to test first if you can reproduce the problem in the latest version before you start to work on it.
Thanks! Sebastiaan on behalf of Umbraco HQ.
What type of issue is it? (Choose one - delete the others)
Missing documentation
What article/section is this about?
Following on from Twitter discussion: https://twitter.com/zpqrtbnk/status/1115297266036875265 about unit testing IPublishedContent in v8
Describe the issue:
What is the best way of mocking/faking IPublishedContent Value extension methods fallbacks?
In v7 as long as the IPublishedContent was setup correctly the extension methods would work as they were pretty self contained within the IPublishedContent. With v8 the fallbacks rely on some dependencies having been configured. Is there a way of mocking/faking these that doesn't require creating an entire umbraco instance?
For reference in some of the Umbraco-Ditto tests (https://github.com/umco/umbraco-ditto/blob/6ad7853f9502dbde4736d894f882debf11b67c45/tests/Our.Umbraco.Ditto.Tests/ValueTypesTests.cs#L39) for example we get