本文整理汇总了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");
}
}
示例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!");
}
}
示例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));
}
}
示例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("Домівка");
}
}
示例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]));
}
}
示例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);
}
}
示例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);
}
}
示例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);
}
}
示例9: ShouldCreateTemplateFieldItemBasedOnDbField
public void ShouldCreateTemplateFieldItemBasedOnDbField(ID templateId, DbField field)
{
using (var db = new Db { new DbTemplate(templateId) { field } })
{
db.GetItem(field.ID).Should().NotBeNull();
}
}
示例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();
}
示例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]));
}
}
示例12: ShouldGetItemNameAsDisplayName
public void ShouldGetItemNameAsDisplayName()
{
// arrange
using (var db = new Db { new DbItem("home") })
{
db.GetItem("/sitecore/content/home").DisplayName.Should().Be("home");
}
}
示例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");
}
示例14: ShouldCreateDb
public void ShouldCreateDb(Db db)
{
// arrange
db.Add(new DbItem("home"));
// act & assert
db.GetItem("/sitecore/content/home").Should().NotBeNull();
}
示例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);
}