we have a static Sitecore method which is called when we fire the test we need to mock the method result, means when its called it should return our mocked result and shouldn't enter into that method.
public class UnitTest1 {
[Theory, DefaultAutoData]
public void CreateDatabase(Database database)
{
Assert.NotNull(database);
}
[Theory, DefaultAutoData]
public void GetItem(Database db, Item item)
{
item["Phrase"].Returns("Welcome!");
db.GetItem("/sitecore/content/Error Codes/500 Error").Returns(item);
var i = new ItemRepository(); //error here
Assert.Equal("Welcome!", item["Phrase"]);
Assert.NotNull(i);
}
}
Because in item repository the SitecoreContext.Dictionary() method is Static and somehow calling a method which has a parameter of SitecoreContext which gets null. How do we mock this method so if it fires it shouldn't go inside the static method its should return what we've defined?