如何在 sitecore fakedb 中创建布局字段?

How to create layout field in sitecorefakedb?

如何使用 sitecore fakedb 创建布局字段?我有下面的代码,但它不起作用。

下面的代码会抛出错误"the item is not a layout/rendering field"

var template = new Sitecore.FakeDb.DbTemplate("themes", Templates.SiteTheme.ID);

                var home = new Sitecore.FakeDb.DbItem("home", new Sitecore.Data.ID());                

                var lookUpField = new Sitecore.FakeDb.DbField("link", Templates.SiteTheme.Fields.SiteTheme) {
                    Type = "Rendering"
                };

                lookUpField.Value = home.ID.ToString();

                var site = new Sitecore.FakeDb.DbItem("site", new Sitecore.Data.ID(), Theming.Templates.SiteTheme.ID) {
                    lookUpField
                };          

                home.Add(site);

                db.Add(home);                

                var themesItem = db.GetItem("/sitecore/content/home/site");

               var layout = new LayoutField(themesItem.Fields["link"]);

                var value = layout.Value;

                Xunit.Assert.NotNull(value);

类似的东西:

[TestCase]
public void FooLayout()
{
    // arrange
    var itemId = ID.NewID;
    using (var db = new Db
    {
        new DbItem("Some Item", itemId)
        {
            new DbField(Sitecore.FieldIDs.LayoutField) { Value = "{presentation-xml}" }
        }
    })
    {
        var item = db.GetItem(itemId);
        // act
        // assert
        item[Sitecore.FieldIDs.LayoutField].Should().Be("{presentation-xml}");
    }
}

注意:Should().Be() 方法来自 https://www.nuget.org/packages/FluentAssertions/