Does anyone know how I can go about mocking the SiteSettingsProvider in Habitat?

Item sitecoreItem= mvcContext.GetContextItem<Item>();

Item settingsItem= settingsProvider.GetSetting(sitecoreItem, "Settings", "General");

return  mvcContext.SitecoreService.GetItem<ISettings>(settingsItem.ID.Guid);

1 Answer 1


Assuming you are talking about mocking SiteSettingsProvider - then you should code against ISiteSettingsProvider abstraction over concrete impl.

Similar with MvcContext -> should use IMvcContext abstraction instead.

That way your code would operate with logical contracts (instead of concrete impl) and become unit-testable.

Here is an example with AutoFixture attribute to power abstract members generation (with NSubsitute)

The test may look like:

    [AutoNSubsituteData, Theory]
    public void TestName(Item item, Item settingsItem, IMvcContext context, ISiteSettingsProvider settings)

      settingsProvider.GetSetting(sitecoreItem, "Settings", "General")

      var sut = ...            

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.