本文整理汇总了C#中System.Db.Add方法的典型用法代码示例。如果您正苦于以下问题:C# Db.Add方法的具体用法?C# Db.Add怎么用?C# Db.Add使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Db
的用法示例。
在下文中一共展示了Db.Add方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: 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");
}
}
示例2: ShouldThrowIfTemplateIdIsInUseByOtherTemplate
public void ShouldThrowIfTemplateIdIsInUseByOtherTemplate()
{
// arrange
var id = new ID("{825697FD-5EED-47ED-8404-E9A47D7D6BDF}");
using (var db = new Db { new DbTemplate("old product", id) })
{
// act
Action action = () => db.Add(new DbTemplate("new product", id));
// assert
action.ShouldThrow<InvalidOperationException>()
.WithMessage("A template with the same id has already been added ('{825697FD-5EED-47ED-8404-E9A47D7D6BDF}', 'new product').");
}
}
示例3: ShouldThrowIfTemplateIdIsInUseByOtherItem
public void ShouldThrowIfTemplateIdIsInUseByOtherItem()
{
// arrange
var existingItemId = new ID("{61A9DB3D-8929-4472-A952-543F5304E341}");
var newItemTemplateId = existingItemId;
using (var db = new Db { new DbItem("existing item", existingItemId) })
{
// act
Action action = () => db.Add(new DbItem("new item", ID.NewID, newItemTemplateId));
// assert
action.ShouldThrow<InvalidOperationException>()
.WithMessage("Unable to create the item based on the template '{61A9DB3D-8929-4472-A952-543F5304E341}'. An item with the same id has already been added ('/sitecore/content/existing item').");
}
}
示例4: ShouldSetChildItemFullIfParentIdIsSet
public void ShouldSetChildItemFullIfParentIdIsSet()
{
// arrange
var parent = new DbItem("parent");
var child = new DbItem("child");
// act
using (var db = new Db { parent })
{
child.ParentID = parent.ID;
db.Add(child);
// assert
child.FullPath.Should().Be("/sitecore/content/parent/child");
}
}
示例5: ShouldThrowIfItemIdIsInUse
public void ShouldThrowIfItemIdIsInUse()
{
// arrange
var id = new ID("{57289DB1-1C33-46DF-A7BA-C214B7F4C54C}");
using (var db = new Db { new DbItem("old home", id) })
{
// act
Action action = () => db.Add(new DbItem("new home", id));
// assert
action.ShouldThrow<InvalidOperationException>()
.WithMessage("An item with the same id has already been added ('{57289DB1-1C33-46DF-A7BA-C214B7F4C54C}', '/sitecore/content/new home').");
}
}
示例6: ShouldThrowIfNoParentFoundById
public void ShouldThrowIfNoParentFoundById(Db db)
{
// arrange
const string ParentId = "{483AE2C1-3494-4248-B591-030F2E2C9843}";
var homessItem = new DbItem("homeless") { ParentID = new ID(ParentId) };
// act
Action action = () => db.Add(homessItem);
// assert
action.ShouldThrow<ItemNotFoundException>()
.WithMessage("The parent item \"{483AE2C1-3494-4248-B591-030F2E2C9843}\" was not found.");
}
示例7: ShouldAddTemplateAndResetTemplatesCache
public void ShouldAddTemplateAndResetTemplatesCache()
{
// arrange
using (var db = new Db())
{
// cache the existing templates
TemplateManager.GetTemplates(db.Database);
// act
db.Add(new DbTemplate("My Template", this.templateId));
// assert
TemplateManager.GetTemplate(this.templateId, db.Database).Should().NotBeNull();
}
}
示例8: ShouldSetItemAccessRules
public void ShouldSetItemAccessRules(string propertyName, string accessRight, bool actualPermission, SecurityPermission expectedPermission, string expectedSecurity)
{
// arrange
var user = User.FromName(@"extranet\John", false);
using (new UserSwitcher(user))
using (new SecurityDisabler())
using (var db = new Db())
{
var dbitem = new DbItem("home");
ReflectionUtil.SetProperty(dbitem.Access, propertyName, actualPermission);
// act
db.Add(dbitem);
var item = db.GetItem("/sitecore/content/home");
// assert
item["__Security"].Should().Be(expectedSecurity);
}
}
示例9: ShouldThrowExceptionIfTemplateIdIsAlreadyExists
public void ShouldThrowExceptionIfTemplateIdIsAlreadyExists()
{
// arrange
var id = ID.NewID;
using (var db = new Db { new DbTemplate("products", id) })
{
// act
Action action = () => db.Add(new DbTemplate("products", id));
// assert
action.ShouldThrow<ArgumentException>().WithMessage("A tamplete with the same id has already been added.*");
}
}
示例10: ShouldCreateAndAddDbItem
public void ShouldCreateAndAddDbItem(Db db, DbItem item)
{
Action action = () => db.Add(item);
action.ShouldNotThrow();
}