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
Sitecore Unit Testing Trouble w/ NSubstitute and Nunit
You're moving in the right direction. You should keep in mind that you can call only mocked methods. The SetItemField method is configured to return field by name:
item.Fields[fieldName].Returns(field)...
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 × 5nsubstitute × 5
sitecore-api × 3
glass-mapper × 1
components × 1
fakedb × 1