As the title, the code itself as following
internal static class ThumbnailPresentationLogic
{
public static string GetThumbnailUrl(List<Image> images)
{
if (images == null || images.FirstOrDefault() == null)
{
return ImageRetrievalConfiguration.MiniDefaultImageFullUrl;
}
Image latestImage = (from image in images
orderby image.CreatedDate descending
select image).First();
Uri fullUrl;
return
Uri.TryCreate(new Uri(ImageRetrievalConfiguration.GetConfig().ImageRepositoryName), latestImage.FileName,
out fullUrl)
? fullUrl.AbsoluteUri
: ImageRetrievalConfiguration.MiniDefaultImageFullUrl;
}
}
I don’t want the unit test go through any methods in ImageRetrievalConfiguration class, so how can I mock ImageRetrievalConfiguration and pass it into ThumbnailPresentationLogic class ??
How about you split the method into two – one of which takes a “base URI” and “default Url” and one of which doesn’t:
Then you can test the logic in the “three-parameter” overload, but the public method doesn’t really contain any logic. You won’t get 100% coverage, but you’ll be able to test the real logic involved.