Since the ContentItem class doesn't have an interface and doesn't have a parameterless constructor or virtual methods & properties how can I mock it for unit testing my code that uses it?
See the release notes and a related wiki article.
it's not possible at the moment but we'd like to enable it. We've discussed several approaches with my colleagues and we came to the conclusion that the best (cleanest) solution would be to allow faking HTTP responses.
Basically, this means that we would allow injecting an instance of HttpClient to the DeliveryClient, replacing the standard one. When constructing the HttpClient you could inject your own implementation of HttpMessageHandler which would effectively enable you to mock any response coming from the DeliveryClient based on the data provided by you (no matter whether the response would be a ContentItem, ContentType, or a strongly-typed item model).
There are even some libraries which make it easy to mock the HttpClient.
Would this solution work in your scenario?
That may work in the future. Not being able to write tests for my code as I'm developing is a problem for me though as I'll likely not get time later to come back and write them and I use a build server to run tests on each commit ... how long will it be before your proposed solution is implemented?
Hi @LeeConlin , it've implemented it here. I'll release a new version of the SDK during the weekend.
Will let you know once it's out.
You can download the nuget now: https://www.nuget.org/packages/KenticoCloud.Delivery/4.7.0
Release notes will be ready later today..