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"); } }
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')."); } }
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')."); } }
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"); } }
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')."); } }
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."); }
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(); } }
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); } }
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.*"); } }
public void ShouldCreateAndAddDbItem(Db db, DbItem item) { Action action = () => db.Add(item); action.ShouldNotThrow(); }