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); }
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); } }