本文整理汇总了C#中SitecoreService.Create方法的典型用法代码示例。如果您正苦于以下问题:C# SitecoreService.Create方法的具体用法?C# SitecoreService.Create怎么用?C# SitecoreService.Create使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类SitecoreService
的用法示例。
在下文中一共展示了SitecoreService.Create方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: CreatesItem
public void CreatesItem()
{
//Arrange
var context = Context.Create(Utilities.CreateStandardResolver());
var db = Sitecore.Configuration.Factory.GetDatabase("master");
var scContext = new SitecoreService(db);
var parentItem = db.GetItem("/sitecore/content/Tests/Issues/AlexGriciucCreateItemIssue");
var parent = scContext.GetItem<CommentPage>("/sitecore/content/Tests/Issues/AlexGriciucCreateItemIssue");
using (new SecurityDisabler())
{
parentItem.DeleteChildren();
}
var newItem = db.GetItem("/sitecore/content/Tests/Issues/AlexGriciucCreateItemIssue/TestName");
Assert.IsNull(newItem);
//Act
// scContext.GlassContext.Load(new OnDemandLoader<SitecoreTypeConfiguration>(typeof(Comment)));
var newClass = new Comment();
newClass.Name = "TestName";
using (new SecurityDisabler())
{
scContext.Create(parent, newClass);
}
//Asset
newItem = db.GetItem("/sitecore/content/Tests/Issues/AlexGriciucCreateItemIssue/TestName");
Assert.IsNotNull(newItem);
}
示例2: CreatesItem
public void CreatesItem()
{
//Arrange
var templateId = ID.NewID;
using (Db database = new Db
{
new Sitecore.FakeDb.DbItem("Target", ID.NewID, templateId)
{
new Sitecore.FakeDb.DbItem("Child1")
}
})
{
var context = Context.Create(Utilities.CreateStandardResolver());
var scContext = new SitecoreService(database.Database);
var parentItem = database.GetItem("/sitecore/content/Target");
var parent = scContext.GetItem<CommentPage>("/sitecore/content/Target");
using (new SecurityDisabler())
{
parentItem.DeleteChildren();
}
var newItem = database.GetItem("/sitecore/content/Target/Child1");
Assert.IsNull(newItem);
//Act
// scContext.GlassContext.Load(new OnDemandLoader<SitecoreTypeConfiguration>(typeof(Comment)));
var newClass = new Comment();
newClass.Name = "Child1";
using (new SecurityDisabler())
{
scContext.Create(parent, newClass);
}
//Asset
newItem = database.GetItem("/sitecore/content/Target/Child1");
Assert.IsNotNull(newItem);
}
}
示例3: Create_AutoMappedClass_CreatesANewItem
public void Create_AutoMappedClass_CreatesANewItem()
{
//Assign
string parentPath = "/sitecore/content/Tests/SitecoreService/Create";
string childPath = "/sitecore/content/Tests/SitecoreService/Create/newChildAutoMapped";
var db = Sitecore.Configuration.Factory.GetDatabase("master");
var context = Context.Create(Utilities.CreateStandardResolver());
context.Load(new SitecoreAttributeConfigurationLoader("Glass.Mapper.Sc.Integration"));
var service = new SitecoreService(db);
using (new SecurityDisabler())
{
var parentItem = db.GetItem(parentPath);
parentItem.DeleteChildren();
}
var parent = service.GetItem<StubClassAutoMapped>(parentPath);
var child = new StubClassAutoMapped();
child.Name = "newChildAutoMapped";
//Act
using (new SecurityDisabler())
{
service.Create(parent, child);
}
//Assert
var newItem = db.GetItem(childPath);
using (new SecurityDisabler())
{
newItem.Delete();
}
Assert.AreEqual(child.Name, newItem.Name);
Assert.AreEqual(child.Id, newItem.ID.Guid);
}
示例4: Create_UsingInterfaceAndNameAndLanguage_CreatesANewItem
public void Create_UsingInterfaceAndNameAndLanguage_CreatesANewItem()
{
//Assign
string parentPath = "/sitecore/content/Tests/SitecoreService/Create";
string childPath = "/sitecore/content/Tests/SitecoreService/Create/newChild";
string name = "newChild";
Language lang = LanguageManager.GetLanguage("af-ZA");
var db = Sitecore.Configuration.Factory.GetDatabase("master");
var context = Context.Create(Utilities.CreateStandardResolver());
context.Load(new SitecoreAttributeConfigurationLoader("Glass.Mapper.Sc.Integration"));
var service = new SitecoreService(db);
using (new SecurityDisabler())
{
var parentItem = db.GetItem(parentPath);
parentItem.DeleteChildren();
}
var parent = service.GetItem<StubClass>(parentPath);
//Act
StubClass child = null;
using (new SecurityDisabler())
{
child = service.Create<StubClass, StubClass>(parent, name, lang);
}
//Assert
var newItem = db.GetItem(childPath, lang);
Assert.AreEqual(name, child.Name);
Assert.AreEqual(child.Name, newItem.Name);
Assert.AreEqual(child.Id, newItem.ID.Guid);
Assert.AreEqual(lang, child.Language);
Assert.AreEqual(1, newItem.Versions.Count);
Assert.AreEqual(1, newItem.Versions.Count);
using (new SecurityDisabler())
{
newItem.Delete();
}
}
示例5: Create_TypeNotPreloaded_CreatesANewItem
public void Create_TypeNotPreloaded_CreatesANewItem()
{
//Assign
string parentPath = "/sitecore/content/Tests/SitecoreService/Create";
string childPath = "/sitecore/content/Tests/SitecoreService/Create/newChild";
var db = Sitecore.Configuration.Factory.GetDatabase("master");
var context = Context.Create(Utilities.CreateStandardResolver());
var service = new SitecoreService(db);
using (new SecurityDisabler())
{
var parentItem = db.GetItem(parentPath);
parentItem.DeleteChildren();
}
Assert.AreEqual(0, context.TypeConfigurations.Count);
var parent = service.GetItem<StubClass>(parentPath);
var child = new StubClassNotPreloaded();
child.Name = "newChild";
//Act
using (new SecurityDisabler())
{
service.Create(parent, child);
}
//Assert
var newItem = db.GetItem(childPath);
using (new SecurityDisabler())
{
newItem.Delete();
}
Assert.AreEqual(child.Name, newItem.Name);
Assert.AreEqual(child.Id, newItem.ID.Guid);
}
示例6: Create_AutoMappedClass_CreatesANewItem
public void Create_AutoMappedClass_CreatesANewItem()
{
//Assign
using (Db database = new Db
{
new Sitecore.FakeDb.DbItem("Target"),
})
{
var context = Context.Create(Utilities.CreateStandardResolver());
context.Load(new OnDemandLoader<SitecoreTypeConfiguration>(typeof(StubClassAutoMapped)));
var service = new SitecoreService(database.Database);
string parentPath = "/sitecore/content/Target";
string childPath = "/sitecore/content/Target/newChildAutoMapped";
using (new SecurityDisabler())
{
var parentItem = database.GetItem(parentPath);
parentItem.DeleteChildren();
}
var parent = service.GetItem<StubClassAutoMapped>(parentPath);
var child = new StubClassAutoMapped();
child.Name = "newChildAutoMapped";
//Act
using (new SecurityDisabler())
{
service.Create(parent, child);
}
//Assert
var newItem = database.GetItem(childPath);
using (new SecurityDisabler())
{
newItem.Delete();
}
Assert.AreEqual(child.Name, newItem.Name);
Assert.AreEqual(child.Id, newItem.ID.Guid);
}
}
示例7: Create_UsingInterfaceAndNameAndLanguage_CreatesANewItem
//TODO: fix, waiting on fix https://github.com/sergeyshushlyapin/Sitecore.FakeDb/issues/138
public void Create_UsingInterfaceAndNameAndLanguage_CreatesANewItem()
{
//Assign
Language lang = LanguageManager.GetLanguage("af-ZA");
ID templateId = ID.NewID;
using (Db database = new Db
{
new Sitecore.FakeDb.DbItem("Target", ID.NewID),
})
{
var context = Context.Create(Utilities.CreateStandardResolver());
context.Load(new OnDemandLoader<SitecoreTypeConfiguration>(typeof(StubClass)));
var service = new SitecoreService(database.Database);
string parentPath = "/sitecore/content/Target";
string childPath = "/sitecore/content/Target/newChild";
string name = "newChild";
using (new SecurityDisabler())
{
var parentItem = database.GetItem(parentPath);
parentItem.DeleteChildren();
}
var parent = service.GetItem<StubClass>(parentPath);
//Act
StubClass child = null;
using (new SecurityDisabler())
{
child = service.Create<StubClass, StubClass>(parent, name, lang);
}
//Assert
var newItem = database.Database.GetItem(childPath, lang);
Assert.AreEqual(name, child.Name);
Assert.AreEqual(child.Name, newItem.Name);
Assert.AreEqual(child.Id, newItem.ID.Guid);
Assert.AreEqual(1, newItem.Versions.Count);
Assert.AreEqual(1, newItem.Versions.Count);
Assert.AreEqual(lang, child.Language);
using (new SecurityDisabler())
{
newItem.Delete();
}
}
}
示例8: Create_UsingInterface_CreatesANewItem
public void Create_UsingInterface_CreatesANewItem()
{
//Assign
string fieldValue = Guid.NewGuid().ToString();
using (Db database = new Db
{
new Sitecore.FakeDb.DbItem("Target"),
new DbTemplate(new ID(StubInterfaceAutoMappedConst.TemplateId))
{
{"StringField",""}
}
})
{
var context = Context.Create(Utilities.CreateStandardResolver());
context.Load(new OnDemandLoader<SitecoreTypeConfiguration>(typeof(StubClass)));
context.Load(new OnDemandLoader<SitecoreTypeConfiguration>(typeof(StubInterfaceAutoMapped)));
var service = new SitecoreService(database.Database);
string parentPath = "/sitecore/content/Target";
string childPath = "/sitecore/content/Target/newChild";
using (new SecurityDisabler())
{
var parentItem = database.GetItem(parentPath);
parentItem.DeleteChildren();
}
var parent = service.GetItem<StubClass>(parentPath);
var child = Substitute.For<StubInterfaceAutoMapped>();
child.Name = "newChild";
child.StringField = fieldValue;
//Act
using (new SecurityDisabler())
{
service.Create(parent, child);
}
//Assert
var newItem = database.GetItem(childPath);
Assert.AreEqual(fieldValue, newItem["StringField"]);
using (new SecurityDisabler())
{
newItem.Delete();
}
Assert.AreEqual(child.Name, newItem.Name);
Assert.AreEqual(child.Id, newItem.ID.Guid);
}
}
示例9: Create_TypeNotPreloaded_CreatesANewItem
public void Create_TypeNotPreloaded_CreatesANewItem()
{
//Assign
using (Db database = new Db
{
new Sitecore.FakeDb.DbItem("Target")
})
{
var context = Context.Create(Utilities.CreateStandardResolver());
var service = new SitecoreService(database.Database);
string parentPath = "/sitecore/content/Target";
string childPath = "/sitecore/content/Target/newChild";
using (new SecurityDisabler())
{
var parentItem = database.GetItem(parentPath);
parentItem.DeleteChildren();
}
Assert.AreEqual(0, context.TypeConfigurations.Count);
var parent = service.GetItem<StubClass>(parentPath);
var child = new StubClassNotPreloaded();
child.Name = "newChild";
//Act
using (new SecurityDisabler())
{
service.Create(parent, child);
}
//Assert
var newItem = database.GetItem(childPath);
using (new SecurityDisabler())
{
newItem.Delete();
}
Assert.AreEqual(child.Name, newItem.Name);
Assert.AreEqual(child.Id, newItem.ID.Guid);
}
}
示例10: Create_UsingInterface_CreatesANewItem
public void Create_UsingInterface_CreatesANewItem()
{
//Assign
string parentPath = "/sitecore/content/Tests/SitecoreService/Create";
string childPath = "/sitecore/content/Tests/SitecoreService/Create/newChild";
string fieldValue = Guid.NewGuid().ToString();
var db = Factory.GetDatabase("master");
var context = Context.Create(Utilities.CreateStandardResolver());
context.Load(new SitecoreAttributeConfigurationLoader("Glass.Mapper.Sc.Integration"));
var service = new SitecoreService(db);
using (new SecurityDisabler())
{
var parentItem = db.GetItem(parentPath);
parentItem.DeleteChildren();
}
var parent = service.GetItem<StubClass>(parentPath);
var child = Substitute.For<StubInterfaceAutoMapped>();
child.Name = "newChild";
child.StringField = fieldValue;
//Act
using (new SecurityDisabler())
{
service.Create(parent, child);
}
//Assert
var newItem = db.GetItem(childPath);
Assert.AreEqual(fieldValue, newItem["StringField"]);
using (new SecurityDisabler())
{
newItem.Delete();
}
Assert.AreEqual(child.Name, newItem.Name);
Assert.AreEqual(child.Id, newItem.ID.Guid);
}