当前位置: 首页>>代码示例>>C#>>正文


C# Db.GetItem方法代码示例

本文整理汇总了C#中System.Db.GetItem方法的典型用法代码示例。如果您正苦于以下问题:C# Db.GetItem方法的具体用法?C# Db.GetItem怎么用?C# Db.GetItem使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在System.Db的用法示例。


在下文中一共展示了Db.GetItem方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: ShouldBeThreadLocalStandardValuesProvider

    public void ShouldBeThreadLocalStandardValuesProvider()
    {
      var templateId = ID.NewID;
      var itemId = ID.NewID;
      var fieldId = ID.NewID;

      var t1 = Task.Factory.StartNew(() =>
      {
        using (var db = new Db
                          {
                            new DbTemplate(templateId) { { fieldId, "$name" } },
                            new DbItem("Home", itemId, templateId)
                          })
        {
          Thread.Sleep(1000);
          db.GetItem(itemId)[fieldId].Should().Be("Home");
        }
      });

      var t2 = Task.Factory.StartNew(() =>
      {
        using (var db = new Db
                          {
                            new DbTemplate(templateId) { fieldId },
                            new DbItem("Home", itemId, templateId)
                          })
        {
          db.GetItem(itemId)[fieldId].Should().BeEmpty();
        }
      });

      t1.Wait();
      t2.Wait();
    }
开发者ID:sergeyshushlyapin,项目名称:Sitecore.FakeDb,代码行数:34,代码来源:DbConcurrencyTest.cs

示例2: ShouldPropagateFieldsFromTheBaseTemplate

    public void ShouldPropagateFieldsFromTheBaseTemplate()
    {
      // arrange
      ID templateId = ID.NewID;

      using (var db = new Db
      {
        this.baseTemplateOne,
        new DbTemplate("My Template", templateId) {BaseIDs = new[] {this.baseTemplateOne.ID}},
        new DbItem("home", ID.NewID, templateId)
      })
      {
        // act
        Item home = db.GetItem("/sitecore/content/home");
        Template template = TemplateManager.GetTemplate(templateId, db.Database);
        Template baseTemplate = TemplateManager.GetTemplate(this.baseTemplateOne.ID, db.Database);

        TemplateField titleField = baseTemplate.GetField("Title");

        // assert 

        // note: it should "just" work as Sitecore wil do all the looking up the templates chain
        template.GetFields(false).Should().NotContain(f => f.Name == "Title" || f.ID == titleField.ID);
        template.GetFields(true).Should().Contain(f => f.Name == "Title" && f.ID == titleField.ID);

        template.GetField("Title").Should().NotBeNull("template.GetField(\"Title\")");
        template.GetField(titleField.ID).Should().NotBeNull("template.GetField(titleField.ID)");

        home.Fields["Title"].Should().NotBeNull("home.Fields[\"Title\"]");
        home.Fields[titleField.ID].Should().NotBeNull("home.Fields[titleField.ID]");
      }
    }
开发者ID:dharnitski,项目名称:Sitecore.FakeDb,代码行数:32,代码来源:DbTemplateInheritanceTest.cs

示例3: ShouldPropagateFieldsFromAllBaseTemplates

    public void ShouldPropagateFieldsFromAllBaseTemplates()
    {
      // arrange
      ID myTemplateId = ID.NewID;

      using (var db = new Db
      {
        this.baseTemplateOne,
        this.baseTemplateTwo,
        this.baseTemplateThree,
        new DbTemplate("Main Template", myTemplateId) {BaseIDs = new[] {this.baseTemplateOne.ID, this.baseTemplateThree.ID}},
        new DbItem("home", ID.NewID, myTemplateId)
      })
      {
        // act
        Item home = db.GetItem("/sitecore/content/home");
        Template template = TemplateManager.GetTemplate(myTemplateId, db.Database);

        // assert

        // note: as noted above, fields propagation should "just" work
        home.Fields["Title"].Should().NotBeNull("home.Fields[\"Title\"]");
        home.Fields["Description"].Should().NotBeNull("home.Fields[\"Description\"]");

        template.GetField("Title").Should().NotBeNull("template.GetField(\"Title\")");
        template.GetField("Description").Should().NotBeNull("template.GetField(\"Description\")");
      }
    }
开发者ID:dharnitski,项目名称:Sitecore.FakeDb,代码行数:28,代码来源:DbTemplateInheritanceTest.cs

示例4: ShouldCreateItemHierarchyAndReadChildByPath

 public void ShouldCreateItemHierarchyAndReadChildByPath()
 {
   // arrange & act
   using (var db = new Db { new DbItem("parent") { new DbItem("child") } })
   {
     // assert
     db.GetItem("/sitecore/content/parent/child").Should().NotBeNull();
   }
 }
开发者ID:udalovas,项目名称:Sitecore.FakeDb,代码行数:9,代码来源:DbTest.cs

示例5: ShouldGetLayoutField

    public void ShouldGetLayoutField()
    {
      using (var db = new Db { new DbItem("home") })
      {
        var home = db.GetItem("/sitecore/content/home");

        FieldTypeManager.GetField(home.Fields[FieldIDs.LayoutField]).Should().BeOfType<LayoutField>();
        FieldTypeManager.GetFieldType("Layout").Type.Should().Be<LayoutField>();
      }
    }
开发者ID:sergeyshushlyapin,项目名称:Sitecore.FakeDb,代码行数:10,代码来源:FieldTypeManagerTest.cs

示例6: ShouldDeserializeNullBaseTemplateItem

    public void ShouldDeserializeNullBaseTemplateItem()
    {
      var item = new DsDbItem("/sitecore/content/New Item Without BaseTemplates");

      using (var db = new Db { item })
      {
        var linkedTemplate = db.GetItem(item.TemplateID);
        linkedTemplate.Should().NotBeNull();
        linkedTemplate.Template.Name.ShouldBeEquivalentTo("Template");
      }
    }
开发者ID:dharnitski,项目名称:Sitecore.FakeDb,代码行数:11,代码来源:DsDbItemTest.cs

示例7: ShouldGetField

    public void ShouldGetField(string name, Type type)
    {
      using (var db = new Db
                        {
                          new DbItem("home") { new DbField("field") { Type = name } }
                        })
      {
        var home = db.GetItem("/sitecore/content/home");

        FieldTypeManager.GetField(home.Fields["field"]).Should().BeOfType(type);
        FieldTypeManager.GetFieldType(name).Type.Should().Be(type);
      }
    }
开发者ID:sergeyshushlyapin,项目名称:Sitecore.FakeDb,代码行数:13,代码来源:FieldTypeManagerTest.cs

示例8: ShouldNotTimeOutOnFailingFluentAssertion

    public void ShouldNotTimeOutOnFailingFluentAssertion()
    {
      // arrange
      using (var db = new Db
      {
        new DbItem("home")
      })
      {
        var home = db.GetItem("/sitecore/content/home");

        Action assertion = () =>
        {
          try { home.Should().BeNull(); } catch { }
        };

        // act && assert
        assertion.ExecutionTime().ShouldNotExceed(1.Seconds());
      }
    }
开发者ID:sergeyshushlyapin,项目名称:Sitecore.FakeDb,代码行数:19,代码来源:FluentAssertionsTest.cs

示例9: ShouldBeThreadLocalDb

    public void ShouldBeThreadLocalDb()
    {
      var t1 = Task.Factory.StartNew(() =>
        {
          using (var db = new Db { new DbItem("Home") })
          {
            Thread.Sleep(1000);
            db.GetItem("/sitecore/content/home").Should().NotBeNull("the Home item is expected");
          }
        });

      var t2 = Task.Factory.StartNew(() =>
        {
          using (var db = new Db())
          {
            db.GetItem("/sitecore/content/home").Should().BeNull("the Home item is not expected");
          }
        });

      t1.Wait();
      t2.Wait();
    }
开发者ID:sergeyshushlyapin,项目名称:Sitecore.FakeDb,代码行数:22,代码来源:DbConcurrencyTest.cs

示例10: ShouldNotThrowOnGetTemplateFieldItem

    public void ShouldNotThrowOnGetTemplateFieldItem()
    {
      // arrange
      using (var db = new Db
                        {
                          new DbItem("home") { new DbField("field") }
                        })
      {
        var home = db.GetItem("/sitecore/content/home");

        // act
        FieldTypeManager.GetTemplateFieldItem(home.Fields["field"]);
      }
    }
开发者ID:maxshell,项目名称:Sitecore.FakeDb,代码行数:14,代码来源:FieldTypeManagerTest.cs

示例11: ShouldCreateItemOfFolderTemplate

 public void ShouldCreateItemOfFolderTemplate()
 {
   // arrange & act
   using (var db = new Db
                     {
                       new DbItem("Sample") { TemplateID = TemplateIDs.Folder }
                     })
   {
     // assert
     db.GetItem("/sitecore/content/sample").TemplateID.Should().Be(TemplateIDs.Folder);
   }
 }
开发者ID:maxshell,项目名称:Sitecore.FakeDb,代码行数:12,代码来源:DbTest.cs

示例12: ShouldCreateAndFulfilCompositeFieldsStructure

    public void ShouldCreateAndFulfilCompositeFieldsStructure()
    {
      // arrange
      using (var db = new Db())
      {
        // act
        db.Add(new DbItem("item1") { { "field1", "item1-field1-value" }, { "field2", "item1-field2-value" } });
        db.Add(new DbItem("item2") { { "field1", "item2-field1-value" }, { "field2", "item2-field2-value" } });

        // assert
        db.GetItem("/sitecore/content/item1")["field1"].Should().Be("item1-field1-value");
        db.GetItem("/sitecore/content/item1")["field2"].Should().Be("item1-field2-value");
        db.GetItem("/sitecore/content/item2")["field1"].Should().Be("item2-field1-value");
        db.GetItem("/sitecore/content/item2")["field2"].Should().Be("item2-field2-value");
      }
    }
开发者ID:maxshell,项目名称:Sitecore.FakeDb,代码行数:16,代码来源:DbTest.cs

示例13: ShouldCreateItemOfAnyVersion

    public void ShouldCreateItemOfAnyVersion()
    {
      // arrange
      using (var db = new Db
                        {
                          new DbItem("home") { { "Title", "title v1" } }
                        })
      {
        var version2 = db.GetItem("/sitecore/content/home", "en", 2);

        // act
        using (new EditContext(version2))
        {
          version2["Title"] = "title v2";
        }

        // assert
        db.GetItem("/sitecore/content/home", "en", 1)["Title"].Should().Be("title v1");
        db.GetItem("/sitecore/content/home", "en", 2)["Title"].Should().Be("title v2");
      }
    }
开发者ID:maxshell,项目名称:Sitecore.FakeDb,代码行数:21,代码来源:DbTest.cs

示例14: ShouldGetItemParent

    public void ShouldGetItemParent()
    {
      // arrange
      using (var db = new Db { new DbItem("item") })
      {
        // act
        var parent = db.GetItem("/sitecore/content/item").Parent;

        // assert
        parent.Paths.FullPath.Should().Be("/sitecore/content");
      }
    }
开发者ID:maxshell,项目名称:Sitecore.FakeDb,代码行数:12,代码来源:DbTest.cs

示例15: ShouldDeserializeItemBasedOnTwoTemplates

    public void ShouldDeserializeItemBasedOnTwoTemplates()
    {
      // arrange
      using (var db = new Db
                        {
                          new DsDbItem("/sitecore/content/New Composite Sample Item")
                        })
      {
        // act
        var item = db.GetItem("/sitecore/content/New Composite Sample Item");

        // assert
        item["Sample Field One"].Should().Be("Value One");
        item["Sample Field Two"].Should().Be("Value Two");
      }
    }
开发者ID:dharnitski,项目名称:Sitecore.FakeDb,代码行数:16,代码来源:DsDbItemTest.cs


注:本文中的System.Db.GetItem方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。