Mapper mocking .Url() in IPublishedContent
# help-with-umbraco
a
I have a UmbracoMapper that maps a few properties of a NewsItem (IPublishedContent with extra fields ) to a other type. I want to build a test for this. When Mocking my NewsItem, so I can Map it ,i'm having troubles mocking the URL of this item... Curious to how others have fixed it:
Copy code
csharp
content.Setup(x => x.Url("en-GB", UrlMode.Auto)).Returns("https://someurl.com");
Using something like this always fails because of the FriendlyPublishedContentExtension cannot be null..
d
I mocked this call once in the url tracker. It's not pretty though, best I could do was create a wrapper class that makes the call for me. Then I mocked the wrapper.
I can't find this exact example, but it's similar to this: https://github.com/Infocaster/UrlTracker/blob/v10/develop/src/UrlTracker.Web/Abstraction/RequestAbstraction.cs Because HttpContext is also one of those things that you couldn't properly mock at some point
a
Thanks @D_Inventor ! Atleast it wont break anymore on the mapping when I wrapped the class, but can't assert it though, the object is always null.. Atleast I can proceed to do the same with other mappings so I got 95% coverage in my tests 😛