Unit testing umbraco with wrapper abstractions? Is there a better other way?
I have been thinking: How do I start using TDD with umbraco. Well, I couldn't find a way to test a controller while using an umbraco API inside my action.
E.g. I had something like the following code inside of an action in a RenderMvcController:
IContent content = contentService.GetById(id);
content.SetValue("name", name);
contentService.SaveAndPublish(content);
I was thinking of using a layer that would work like a facade that would allow me to abstract umbraco stuff by mocking that layer. It seems I wasn't the only one thinking in these terms.
But I just wasn't sure if everyone would go with this or have other opinions because most umbraco developers who used V4 were certainly used to query the umbraco APIs inside macroScripts and this approach requires that the developer creates a new class for each set of related functionality - which keeps making sense to me because for all I care, in the front-end, umbraco is just a database.
Am I right to think that from now on, we should always query umbraco from a facade??
Hi, If you get a copy of the Umbraco Source and complie you will get a Test.dll. This has methods that will allow you to a mocked Umbrco and Application context. Dont know if this is what you are after but might help :)
Thanks for your response. I am aware of that. I was more kind of asking (or trying to) about the umbraco service interface that the guy in the video suggested.
His approach seems reasonably good to me (except that his Save method implementation actually saves on every property change). And if we use an umbraco service to get that, that means that in the code written in the controllers, we can't actually call anything like contentService.GetBy(id).Descendants.. etc etc.
Is this is how you have been doing? Using a new layer to abstract umbraco access layer?
Unit testing umbraco with wrapper abstractions? Is there a better other way?
I have been thinking: How do I start using TDD with umbraco. Well, I couldn't find a way to test a controller while using an umbraco API inside my action.
E.g. I had something like the following code inside of an action in a RenderMvcController:
IContent content = contentService.GetById(id);
content.SetValue("name", name);
contentService.SaveAndPublish(content);
I was thinking of using a layer that would work like a facade that would allow me to abstract umbraco stuff by mocking that layer. It seems I wasn't the only one thinking in these terms.
See here: https://www.youtube.com/watch?v=1xS002NyGnc
But I just wasn't sure if everyone would go with this or have other opinions because most umbraco developers who used V4 were certainly used to query the umbraco APIs inside macroScripts and this approach requires that the developer creates a new class for each set of related functionality - which keeps making sense to me because for all I care, in the front-end, umbraco is just a database.
Am I right to think that from now on, we should always query umbraco from a facade??
Hi, If you get a copy of the Umbraco Source and complie you will get a Test.dll. This has methods that will allow you to a mocked Umbrco and Application context. Dont know if this is what you are after but might help :)
Hi Charles,
Thanks for your response. I am aware of that. I was more kind of asking (or trying to) about the umbraco service interface that the guy in the video suggested.
His approach seems reasonably good to me (except that his Save method implementation actually saves on every property change). And if we use an umbraco service to get that, that means that in the code written in the controllers, we can't actually call anything like contentService.GetBy(id).Descendants.. etc etc.
Is this is how you have been doing? Using a new layer to abstract umbraco access layer?
Thanks!
Hi Fabio,
No problem.
What are you trying to acheive?
Charlie.
is working on a reply...