本文整理汇总了C#中SitecoreService.Save方法的典型用法代码示例。如果您正苦于以下问题:C# SitecoreService.Save方法的具体用法?C# SitecoreService.Save怎么用?C# SitecoreService.Save使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类SitecoreService
的用法示例。
在下文中一共展示了SitecoreService.Save方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Save_ItemDisplayNameChangedUsingProxyUsingInterface_SavesDisplayName
public void Save_ItemDisplayNameChangedUsingProxyUsingInterface_SavesDisplayName()
{
//Assign
var itemPath = "/sitecore/content/Tests/SitecoreService/Save/EmptyItem";
string expected = "new name";
var db = Sitecore.Configuration.Factory.GetDatabase("master");
var context = Context.Create(Utilities.CreateStandardResolver());
context.Load(new SitecoreAttributeConfigurationLoader("Glass.Mapper.Sc.Integration"));
var currentItem = db.GetItem(itemPath);
var service = new SitecoreService(db, context);
//setup item
using (new SecurityDisabler())
{
currentItem.Editing.BeginEdit();
currentItem[Global.Fields.DisplayName] = "old name";
currentItem.Editing.EndEdit();
}
var cls = service.GetItem<IStubSaving>(itemPath);
using (new SecurityDisabler())
{
//Act
cls.Name = expected;
service.Save(cls);
//Assert
var newItem = db.GetItem(itemPath);
Assert.AreEqual(expected, newItem[Global.Fields.DisplayName]);
Assert.IsTrue(cls is IStubSaving);
Assert.AreNotEqual(typeof(IStubSaving), cls.GetType());
}
}
示例2: Save_ItemDisplayNameChangedUsingProxyUsingInterface_SavesDisplayName
public void Save_ItemDisplayNameChangedUsingProxyUsingInterface_SavesDisplayName()
{
//Assign
Guid id = Guid.NewGuid();
using (Db database = new Db
{
new Sitecore.FakeDb.DbItem("Target", new ID(id))
})
{
var context = Context.Create(Utilities.CreateStandardResolver());
context.Load(new OnDemandLoader<SitecoreTypeConfiguration>(typeof(StubSaving)));
var service = new SitecoreService(database.Database);
var itemPath = "/sitecore/content/Target";
string expected = "new name";
var currentItem = database.Database.GetItem(itemPath);
//setup item
using (new SecurityDisabler())
{
currentItem.Editing.BeginEdit();
currentItem[Global.Fields.DisplayName] = "old name";
currentItem.Editing.EndEdit();
}
var cls = service.GetItem<IStubSaving>(itemPath);
using (new SecurityDisabler())
{
//Act
cls.Name = expected;
service.Save(cls);
//Assert
var newItem = database.Database.GetItem(itemPath);
Assert.AreEqual(expected, newItem[Global.Fields.DisplayName]);
Assert.IsTrue(cls is IStubSaving);
Assert.AreNotEqual(typeof(IStubSaving), cls.GetType());
}
}
}