I am facing a weird problem with Sitecore 9.2.0 and FakeDb 2.0.1. Some of the unit tests fails randomly with the following error.
System.NullReferenceException
Object reference not set to an instance of an object.
at Sitecore.Data.Fields.DefaultFieldTypeManager.GetFieldType(String name)
at Sitecore.Data.Templates.TemplateField.Builder.SetType(String type)
at Sitecore.FakeDb.Data.DataProviders.FakeDataProvider.BuildTemplate(DbTemplate ft, TemplateCollection templates)
at Sitecore.FakeDb.Data.DataProviders.FakeDataProvider.GetTemplates(CallContext context)
at Sitecore.Data.DataProviders.DataProvider.GetTemplates(CallContext context, DataProviderCollection providers)
at Sitecore.Data.DataSource.GetTemplates()
at Sitecore.Data.Engines.TemplateEngine.AddStaticTemplates(TemplateDictionary result)
at Sitecore.Data.Engines.TemplateEngine.InternalGetTemplates()
at Sitecore.Data.Engines.TemplateEngine.GetTemplate(ID templateId)
at Sitecore.Data.Managers.TemplateProvider.GetFieldId(String fieldName, ID templateId, Database database)
at Sitecore.Collections.FieldCollection.get_Item(String fieldName)
at Sitecore.Data.Items.BaseItem.get_Item(String fieldName)
When I run the test individually they succeed but some of them fail when executed in parallel with other test. All the tests are using Db items and they are created using AutoData fixture
[Theory]
[AutoData]
public void GetField_Should_Return_Something(Db db, string name, ID itemId)
{
//arrange
db.Add(new DbItem(name, itemId));
var item = db.GetItem(itemId);
var myClass = new MyClass();
//act
myClass.Act(item)
}
Has anyone faced this issue or any idea how to fix it? I have tried it with FakeDB 1.7.0, using different way of creating Db (NSubstitute, using new Db, etc) no luck.