3
votes
Accepted
How to mock an ImageField in Sitecore using nSubstitute and xUnit
If you go into ImageField.MediaItem getter, you'll notice that the MediaDatabase.GetItem() method uses 3 parameters including language and version:
this.mediaItem = this.MediaDatabase.GetItem(mediaId, ...
3
votes
Unit testing a Sitecore component controller throws exception in mocked service
By mocking a proper return type(GetPreviousProductsResponse) value for the injected service(_productService) instead of a model property(PreviousProducts) solved this issue.
_productService....
2
votes
Accepted
Unit Testing with GlassMapper and GetItemByIdOptions
From what I can see, the reason why it fails for you is because you're using different instances of GetItemByIdOptions class.
First you "record" that when service.GetItem will be called with ...
1
vote
Accepted
How to mock MediaManager in Sitecore using nSubstitute and xUnit
Change
mediaManager.GetMediaUrl(mediaItem).Returns("/a/path/to/an/image.jpg");
to
mediaManager.GetMediaUrl(Arg.Is<MediaItem>(mi => mi.ID == mediaItem.ID)).Returns("/a/path/to/...
Only top scored, non community-wiki answers of a minimum length are eligible
Related Tags
unit-testing × 4nsubstitute × 4
sitecore-api × 2
glass-mapper × 1
components × 1
fakedb × 1