コード例 #1
0
    public void HowToCreateTemplateWithStandardValues()
    {
      var templateId = new Sitecore.Data.TemplateID(Sitecore.Data.ID.NewID);

      using (Sitecore.FakeDb.Db db = new Sitecore.FakeDb.Db
        {
          // create template with field Title and standard value $name
          new Sitecore.FakeDb.DbTemplate("Sample", templateId) { { "Title", "$name" } }
        })
      {
        // add item based on the template to the content root
        Sitecore.Data.Items.Item contentRoot = db.GetItem(Sitecore.ItemIDs.ContentRoot);
        Sitecore.Data.Items.Item item = contentRoot.Add("Home", templateId);

        // the Title field is set to 'Home'
        Xunit.Assert.Equal("Home", item["Title"]);
      }
    }
コード例 #2
0
    public void HowToCreateTemplateWithStandardValues()
    {
      var templateId = new Sitecore.Data.TemplateID(Sitecore.Data.ID.NewID);

      using (Sitecore.FakeDb.Db db = new Sitecore.FakeDb.Db
        {
          // create template with field Title and standard value $name
          new Sitecore.FakeDb.DbTemplate("Sample", templateId) { { "Title", "$name" } }
        })
      {
        // add item based on the template to the content root
        Sitecore.Data.Items.Item contentRoot = db.GetItem(Sitecore.ItemIDs.ContentRoot);
        Sitecore.Data.Items.Item item = contentRoot.Add("Home", templateId);

        // the Title field is set to 'Home'
        Xunit.Assert.Equal("Home", item["Title"]);
      }
    }