Skip to content

Creating an Item Based on a Template

sergeyshushlyapin edited this page Nov 18, 2014 · 2 revisions

You can create a template first and then create an item based on the template:

[Fact]
public void HowToCreateItemOnSpecificTemplate()
{
  Sitecore.Data.ID templateId = Sitecore.Data.ID.NewID;

  using (Sitecore.FakeDb.Db db = new Sitecore.FakeDb.Db
    {
      new Sitecore.FakeDb.DbTemplate("products", templateId) { "Name" },
      new Sitecore.FakeDb.DbItem("Apple") { TemplateID = templateId }
    })
  {
    Sitecore.Data.Items.Item item =
      db.GetItem("/sitecore/content/apple");

    Xunit.Assert.Equal(templateId, item.TemplateID);
    Xunit.Assert.NotNull(item.Fields["Name"]);
  }
}
Clone this wiki locally