I'm creating a unit test for a code that has an Item.Add method used and trying to use Sitecore Fake DB for this and I'm getting an error that it's not being populated.
A sample code below:
public class SampleTest
{
[Fact]
public void SampleTest_GetNewItem()
{
var myHomeID = new ID();
var templateID = new ID();
var template = new TemplateID(templateID);
using (var db = new Db()
{
new DbItem("Home", myHomeID)
}){
Item myHomeItem = db.GetItem(myHomeID);
Item returnItem = myHomeItem.Add("myNewItem", template);
returnItem.Should().NotBeNull(); //Assert fails because returnItem is null
}
}
}
Is this behavior not supported by fake DB? or is there something wrong with the code? and how can the code be unit tested?
Thanks in advance! :)