I am working on upgrading a project from Sitecore 8.2 to 9.3. Few tests are failing and throwing NullReferenceException at Sitecore.XA.Foundation.Mvc.Repositories.Base.FillBaseProperties(model).
While debugging, I saw that IsEdit and IsEditable properties are throwing exception. Can anybody please let me know the Unit Test code to assign values to these two parameters? Please see current test code below -
public void GetModel_ReturnsModel(IServiceProvider serviceProvider, IPageContext pageContext, IRendering rendering, IContentRepository contentRepository, IControlEditability controlEditability, IControlEditabilityService controlEditabilityService, IMultisiteContext multisiteContext, IPageMode pageMode)
{
// Arrange
serviceProvider.GetService(typeof(IPageMode)).Returns(pageMode);
SnackbarNotificationRepository sut = new SnackbarNotificationRepository();
sut.SetFieldValue("_rendering", rendering);
sut.SetFieldValue("_pageContext", pageContext);
sut.SetFieldValue("_contentRepository", contentRepository);
sut.SetFieldValue("_controlEditability", controlEditability);
sut.SetFieldValue("_controlEditabilityService", controlEditabilityService);
sut.SetFieldValue("_multisiteContext", multisiteContext);
FakeSiteContext fakeSite = new FakeSiteContext(
new StringDictionary
{
{ "name", "TestSite" },
{ "rootPath", "/sitecore/content/test" },
{ "startItem", "/Home" }
});
IRenderingModelBase result = null;
// Act
using (new SiteContextSwitcher(fakeSite))
{
result = sut.GetModel();
}
// Assert
result.Should().BeOfType<SnackbarNotificationModel>();
}