I have the below scenario to implement unit testing on a Sitecore MVC
(with glassmapper) integration.
We are using a wrapper class to make calls to Glassmapper Sitecore Context methods. Below is one of the example.
public interface IMappingProvider { T GetItem<T>(Guid id, bool isLazy = false, bool inferType = false) where T : class; ... } public class GlassMappingProvider : IMappingProvider { public T GetItem<T>(Guid id, bool isLazy = false, bool inferType = false) where T : class { var context = new SitecoreContext(); return context.GetItem<T>(id, isLazy, inferType); } ... }
All the controllers are being initialized with the wrapper
GlassMappingProvider
public class SitecoreTestController : Controller { private readonly IMappingProvider _mappingProvider; public SitecoreTestController (IMappingProvider mappingProvider) { _mappingProvider = mappingProvider; } ... }
I have followed multiple articles where in to create Mock Sitecore Context, create Sitecore Fake DB, create the Item and set in the fake context. The challenge I have are bwlow
- Could not pass the Sitecore Context to controllers
- Could not Mock the GetItem of the Glass Wrapper - GlassMappingProvider.
Any one had the similar implementation or any suggestions on what to be done to write a test cases for such a implementation?