0

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

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)
    {
      mvcContext.GetContextItem().Returns(item);

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

      var sut = ...            
    }

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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