Hi Jakob,
In the link you posted, the read me says in its limitations section that this lacks the concept of "Current". That it won't be available in that execution context.
Are you trying to find a workaround? Like to hack one together? Looks like this is directly querying the Db, so it doesn't read from umbraco.config at all. Hope that helps.
Thanks for answering!
I am aware of the limitations of the above approach.
My question is still valid: Can you help me to get access to the UmbracoHelper service from a unit test?
I prefer to experiment my data read out in unit tests to understand the data models retrieved. I understand UmbracoHelper is now the preferred method to retrieve data. Right now I need to use the TypedContent and TypedMedia methods of the UmbracoHelper class.
there are special nuget packages to help do exactly that. Mock the (entire) stuff for you. Try a quick search for umbraco context mock. There are articles in the 24days website and some blog posts.
Thanks for your answer!
It looks like a clean way to mock context and helper objects.
But in my current project I was actually looking for a way to retrieve real data with the UmbracoHelper class. In that sense my "unit tests" are not really unit tests, but only a convenient way to experiment with data in debug mode to understand what data is actually returned :)
For this scenario I have decided to use the service classes. I just need to make sure I use another approach for data retrieval in the real code, with UmbracoHelper to ensure I use the provided caching.
For real unit tests I will look into your suggested approach.
How to get hold of UmbracoHelper in unit test
Is there any way I could get hold of the UmbracoHelper in unit test?
I have managed to set up an ApplicationBase that can be used in unit tests by following this example: https://github.com/thenerdery/UmbracoVault/wiki/Accessing-Umbraco-data-outside-the-Umbraco-Request-Pipeline
I tried to use the explicit instantiation of UmbracoHelper:
But ApplicationBase.Context is not available so I can not use it to feed the constructor.
Hi Jakob, In the link you posted, the read me says in its limitations section that this lacks the concept of "Current". That it won't be available in that execution context.
See Limitations
Are you trying to find a workaround? Like to hack one together? Looks like this is directly querying the Db, so it doesn't read from umbraco.config at all. Hope that helps.
Thanks for answering! I am aware of the limitations of the above approach.
My question is still valid: Can you help me to get access to the UmbracoHelper service from a unit test?
I prefer to experiment my data read out in unit tests to understand the data models retrieved. I understand UmbracoHelper is now the preferred method to retrieve data. Right now I need to use the TypedContent and TypedMedia methods of the UmbracoHelper class.
Hi Jakob,
Have you seen this article?
https://glcheetham.name/2017/01/29/mocking-umbracohelper-using-dependency-injection-the-right-way/
Heck yeah, way to be Steve. I'm bookmarking this!
Hi Jakob,
there are special nuget packages to help do exactly that. Mock the (entire) stuff for you. Try a quick search for umbraco context mock. There are articles in the 24days website and some blog posts.
Thanks for your answer! It looks like a clean way to mock context and helper objects.
But in my current project I was actually looking for a way to retrieve real data with the UmbracoHelper class. In that sense my "unit tests" are not really unit tests, but only a convenient way to experiment with data in debug mode to understand what data is actually returned :)
For this scenario I have decided to use the service classes. I just need to make sure I use another approach for data retrieval in the real code, with UmbracoHelper to ensure I use the provided caching.
For real unit tests I will look into your suggested approach.
is working on a reply...