How to unit test with the new .Url() extension method? Throws exception and can't mock it
The old .Url property on IPublishedContent is marked as obsolete and will dissapear. It has been replaced by an extension method in Umbraco.Web namespace.
The old .Url property was easy to mock:
content.Setup(x => x.Url).Returns(url);
Now it doesn't work to mock the Setup of the property because it is an extension method and they can't be mocked. Using a wrapper around the extension method doesn't work either.
If I skip setting up the extension method then my unit tests will throw a null reference exception because the UmbracoMapper lib from Andy Butland requires the Url() to be set.
.Url() extension is not testable since it uses a static service locator without a setter so it can´t be mocked (Current.Factory).
.Url has been deprecated so you can still use it but be aware in the netcore version it’s going away. It will not go away in v8 but you would have to change it if you updgrade/rebuild to v9.
In Netcore version .Url() will be testable since dotnetcore has the option of passing in its dependencies which makes it easier to test.
How to unit test with the new .Url() extension method? Throws exception and can't mock it
The old .Url property on IPublishedContent is marked as obsolete and will dissapear. It has been replaced by an extension method in Umbraco.Web namespace.
The old .Url property was easy to mock: content.Setup(x => x.Url).Returns(url);
Now it doesn't work to mock the Setup of the property because it is an extension method and they can't be mocked. Using a wrapper around the extension method doesn't work either.
If I skip setting up the extension method then my unit tests will throw a null reference exception because the UmbracoMapper lib from Andy Butland requires the Url() to be set.
Any advice?
Hi Rasmus.
See conversation on twitter: https://twitter.com/dadolfi/status/1355120357301231618
To summarize:
is working on a reply...
This forum is in read-only mode while we transition to the new forum.
You can continue this topic on the new forum by tapping the "Continue discussion" link below.