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


C# Db.GetItem方法代码示例

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


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

示例1: ShouldDeepCopyItem

    public void ShouldDeepCopyItem()
    {
      // arrange
      using (var db = new Db
                        {
                          new DbItem("original") { new DbItem("child") { { "Title", "Child" } } }
                        })
      {
        var original = db.GetItem("/sitecore/content/original");
        var root = db.GetItem("/sitecore/content");

        // act
        var copy = original.CopyTo(root, "copy"); // deep is the default

        // assert
        copy.Should().NotBeNull();
        copy.Children.Should().HaveCount(1);

        var child = copy.Children.First();
        child.Fields["Title"].Should().NotBeNull("'child.Fields[\"Title\"]' should not be null");
        child.Fields["Title"].Value.Should().Be("Child");
        child.ParentID.Should().Be(copy.ID);
        child.Name.Should().Be("child");
        child.Paths.FullPath.Should().Be("/sitecore/content/copy/child");
      }
    }
开发者ID:dharnitski,项目名称:Sitecore.FakeDb,代码行数:26,代码来源:DbItemCopyingTest.cs

示例2: ShouldNotUpdateOriginalItemOnEditing

    public void ShouldNotUpdateOriginalItemOnEditing()
    {
      // arrange
      using (var db = new Db
                        {
                          new DbItem("old root")
                            {
                              new DbItem("item") { new DbField("Title") { { "en", 1, "Hi!" } }, }
                            },
                          new DbItem("new root")
                        })
      {
        var item = db.GetItem("/sitecore/content/old root/item");
        var newRoot = db.GetItem("/sitecore/content/new root");
        var copy = item.CopyTo(newRoot, "new item");

        // act
        using (new EditContext(copy))
        {
          copy["Title"] = "Welcome!";
        }

        // assert
        db.GetItem(copy.ID)["Title"].Should().Be("Welcome!");
        db.GetItem(item.ID)["Title"].Should().Be("Hi!");
      }
    }
开发者ID:sergeyshushlyapin,项目名称:Sitecore.FakeDb,代码行数:27,代码来源:DbItemEditingTest.cs

示例3: ShouldGetTargetById

    public void ShouldGetTargetById()
    {
      // arrange
      var targetId = ID.NewID;

      using (var db = new Db
                        { 
                           new DbItem("source") { { "Reference", targetId.ToString() } },
                           new DbItem("target",  targetId)
                        })
      {
        var item = db.GetItem("/sitecore/content/source");
        item.Should().NotBeNull("the 'source' item should not be null");

        // act
        var referenceField = (ReferenceField)item.Fields["Reference"];

        // assert
        referenceField.Should().NotBeNull("'item.Fields[\"Reference\"]' should not be null");
        referenceField.Database.Should().Be(db.Database);
        referenceField.Path.Should().Be(targetId.ToString());
        referenceField.TargetID.Should().Be(targetId);
        referenceField.TargetItem.Should().Be(db.GetItem(targetId));
      }
    }
开发者ID:maxshell,项目名称:Sitecore.FakeDb,代码行数:25,代码来源:ReferenceFieldTest.cs

示例4: ShouldSetDisplayNameInDifferencCulture1s

 public void ShouldSetDisplayNameInDifferencCulture1s()
 {
   // arrange
   using (var db = new Db
                     {
                       new DbItem("home") { new DbField(FieldIDs.DisplayName) { { "en", "Home!" }, { "uk-UA", "Домівка" } } }
                     })
   {
     db.GetItem("/sitecore/content/home", "en")[FieldIDs.DisplayName].Should().Be("Home!");
     db.GetItem("/sitecore/content/home", "uk-UA")[FieldIDs.DisplayName].Should().Be("Домівка");
   }
 }
开发者ID:sergeyshushlyapin,项目名称:Sitecore.FakeDb,代码行数:12,代码来源:ItemAppearanceTest.cs

示例5: ShouldWorkWithLayoutDeltas

    public void ShouldWorkWithLayoutDeltas()
    {
      ID templateId = ID.NewID;

      string templateLayout =
        @"<r xmlns:xsd=""http://www.w3.org/2001/XMLSchema"">
            <d id=""{FE5D7FDF-89C0-4D99-9AA3-B5FBD009C9F3}"" l=""{4CA7478E-6184-4890-9072-1156DB468A1B}"" />
            <d id=""{EF7176AE-2502-401A-96C0-1E9918A982F7}"" l=""{4CA7478E-6184-4890-9072-1156DB468A1B}"" /> 
            <d id=""{5A6E7DC3-987F-4E74-AF78-AC0E544975F2}"" l=""{4CA7478E-6184-4890-9072-1156DB468A1B}"" />
          </r>";

      string itemDelta =
        @"<r xmlns:p=""p"" xmlns:s=""s"" p:p=""1"">
              <d id=""{FE5D7FDF-89C0-4D99-9AA3-B5FBD009C9F3}"">
                  <r uid=""{BC2FDEAE-A971-420B-A874-BA5C767C42FE}"" s:id=""{B5BFA387-74C8-416B-98AF-01C9230C24B2}"" s:ph=""Score Content Main"" />
              </d>
          </r>";

      string merged = XmlDeltas.ApplyDelta(templateLayout, itemDelta);

      using (var db = new Db()
      {
        new DbTemplate("main", templateId)
        {
            { FieldIDs.LayoutField, templateLayout }
        },
        new DbItem("page", ID.NewID, templateId),
        new DbItem("page2", ID.NewID, templateId)
        {
          new DbField(FieldIDs.LayoutField) { Value = itemDelta }
        }
      })
      {
        Item item = db.GetItem("/sitecore/content/page");

        Assert.Equal(templateLayout, StandardValuesManager.Provider.GetStandardValue(item.Fields[FieldIDs.LayoutField]));

        Assert.Equal(templateLayout, LayoutField.GetFieldValue(item.Fields[FieldIDs.LayoutField]));
        // standard values
        Assert.Equal(templateLayout, item[FieldIDs.LayoutField]);

        var item2 = db.GetItem("/sitecore/content/page2");
        Assert.Equal(templateLayout, item2.Fields[FieldIDs.LayoutField].GetStandardValue());

        // just checking
        Assert.True(XmlPatchUtils.IsXmlPatch(itemDelta));

        Assert.Equal(merged, LayoutField.GetFieldValue(item2.Fields[FieldIDs.LayoutField]));
      }
    }
开发者ID:sergeyshushlyapin,项目名称:Sitecore.FakeDb,代码行数:50,代码来源:LayoutFieldTest.cs

示例6: ShouldRemoveItemVersionAndUpdateCountIfNoVersionedFieldsExist

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

        // act
        item.Versions.AddVersion()
            .Versions.RemoveVersion();

        // assert
        db.GetItem("/sitecore/content/home").Versions.Count.Should().Be(1);
      }
    }
开发者ID:dharnitski,项目名称:Sitecore.FakeDb,代码行数:15,代码来源:ItemVersionsTest.cs

示例7: ShouldSetLinkFieldPropertiesUsingDbLinkField

    public void ShouldSetLinkFieldPropertiesUsingDbLinkField()
    {
      // arrange
      var targetId = ID.NewID;

      using (var db = new Db
                        {
                          new DbItem("home")
                            {
                              new DbLinkField("link")
                                {
                                  LinkType = "internal", 
                                  QueryString = "sc_lang=en",
                                  TargetID = targetId,
                                }
                            }
                        })
      {
        var item = db.GetItem("/sitecore/content/home");

        // act
        var linkField = (LinkField)item.Fields["link"];

        // assert
        linkField.Should().NotBeNull("'item.Fields[\"link\"]' should not be null");
        linkField.LinkType.Should().Be("internal");
        linkField.QueryString.Should().Be("sc_lang=en");
        linkField.TargetID.Should().Be(targetId);
      }
    }
开发者ID:dharnitski,项目名称:Sitecore.FakeDb,代码行数:30,代码来源:LinkFieldTest.cs

示例8: ShouldNotOverrideStatisticsIfSetExplicitly

    public void ShouldNotOverrideStatisticsIfSetExplicitly()
    {
      // arrange
      const string Created = "20080407T135900";
      const string CreatedBy = @"sitecore\admin";
      const string Revision = "17be5e4c-19ac-4a67-b582-d72eaa761b1c";
      const string Updated = "20140613T111309:635382547899455734";
      const string UpdatedBy = @"sitecore\editor";

      // act
      using (var db = new Db
                        {
                          new DbItem("Home")
                            {
                              { "__Created", Created }, { "__Created by", CreatedBy },
                              { "__Revision", Revision },
                              { "__Updated", Updated }, { "__Updated by", UpdatedBy }
                            }
                        })
      {
        var item = db.GetItem("/sitecore/content/home");

        // assert
        item["__Created"].Should().Be(Created);
        item["__Created by"].Should().Be(CreatedBy);
        item["__Revision"].Should().Be(Revision);
        item["__Updated"].Should().Be(Updated);
        item["__Updated by"].Should().Be(UpdatedBy);
      }
    }
开发者ID:dharnitski,项目名称:Sitecore.FakeDb,代码行数:30,代码来源:StatisticsFieldsTest.cs

示例9: ShouldCreateTemplateFieldItemBasedOnDbField

 public void ShouldCreateTemplateFieldItemBasedOnDbField(ID templateId, DbField field)
 {
   using (var db = new Db { new DbTemplate(templateId) { field } })
   {
     db.GetItem(field.ID).Should().NotBeNull();
   }
 }
开发者ID:JRondeau16,项目名称:Sitecore.FakeDb,代码行数:7,代码来源:TemplatesTest.cs

示例10: 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:maxshell,项目名称:Sitecore.FakeDb,代码行数:34,代码来源:DbConcurrencyTest.cs

示例11: ShouldBeAbleToSetLayoutFieldValue

    public void ShouldBeAbleToSetLayoutFieldValue()
    {
      ID itemId = ID.NewID;

      using (var db = new Db
      {
        new DbItem("page", itemId)
        {
          new DbField(FieldIDs.LayoutField)
          {
            Value = "<r/>"
          }
        }
      })
      {
        DbItem fakeItem = db.DataStorage.GetFakeItem(itemId);
        Assert.Equal("<r/>", fakeItem.Fields[FieldIDs.LayoutField].Value);

        var item = db.GetItem("/sitecore/content/page");

        var layoutField = item.Fields[FieldIDs.LayoutField];
        Assert.Equal("<r/>", layoutField.Value);

        Assert.Equal("<r/>", item[FieldIDs.LayoutField]);
        Assert.Equal("<r/>", item["__Renderings"]);

        Assert.Equal("<r/>", LayoutField.GetFieldValue(item.Fields[FieldIDs.LayoutField]));
      }
    }
开发者ID:sergeyshushlyapin,项目名称:Sitecore.FakeDb,代码行数:29,代码来源:LayoutFieldTest.cs

示例12: ShouldGetItemNameAsDisplayName

 public void ShouldGetItemNameAsDisplayName()
 {
   // arrange
   using (var db = new Db { new DbItem("home") })
   {
     db.GetItem("/sitecore/content/home").DisplayName.Should().Be("home");
   }
 }
开发者ID:sergeyshushlyapin,项目名称:Sitecore.FakeDb,代码行数:8,代码来源:ItemAppearanceTest.cs

示例13: GetAll_PointItemPassed_ShouldReturnSinglePoint

 public void GetAll_PointItemPassed_ShouldReturnSinglePoint(Db db)
 {
   var itemid = ID.NewID;
   db.Add(new DbItem("point", itemid, Templates.MapPoint.ID) { { Templates.MapPoint.Fields.Name, "nameField" } });
   var repository = new MapPointRepository();
   var actual = repository.GetAll(db.GetItem(itemid));
   actual.Single().Name.Should().Be("nameField");
 }
开发者ID:chiragp,项目名称:Habitat,代码行数:8,代码来源:MapsPointsRepositoryTests.cs

示例14: ShouldCreateDb

    public void ShouldCreateDb(Db db)
    {
      // arrange
      db.Add(new DbItem("home"));

      // act & assert
      db.GetItem("/sitecore/content/home").Should().NotBeNull();
    }
开发者ID:sergeyshushlyapin,项目名称:Sitecore.FakeDb,代码行数:8,代码来源:AutoFixtrureTest.cs

示例15: ShouldReadStandardFieldValues

    public void ShouldReadStandardFieldValues(string fieldName, string fieldValue, Db db)
    {
      // arrange
      db.Add(new DbItem("home") { { fieldName, fieldValue } });

      // act & assert
      db.GetItem("/sitecore/content/home")[fieldName].Should().Be(fieldValue);
    }
开发者ID:maxshell,项目名称:Sitecore.FakeDb,代码行数:8,代码来源:StandardFieldsTest.cs


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