public void Remove_DeletesItem_WhenItemIsRoot() { using (var testTree = new TestSfsTree()) { testTree.CreateTestTree("/sitecore"); testTree.Remove(testTree.GetRootItem()); Assert.Empty(Directory.GetFileSystemEntries(testTree.PhysicalRootPath)); var root = testTree.GetRootItem(); Assert.Null(root); } }
public void Save_WritesExpectedItems_WhenItemsWithSameNamePrefixExist() { using (var testTree = new TestSfsTree()) { // longer name first CreateTestTree("/sitecore/Html Editor Drop Down Button", testTree); // shorter name second - name is unique, but has same prefix as longer testTree.Save(CreateTestItem("/sitecore/Html Editor Drop Down", testTree.GetRootItem().Id)); var children = testTree.GetChildren(testTree.GetRootItem()).OrderBy(i => i.SerializedItemId).ToArray(); Assert.Equal(2, children.Length); Assert.Equal("/sitecore/Html Editor Drop Down Button", children[0].Path); Assert.EndsWith("Html Editor Drop Down Button.yml", children[0].SerializedItemId); Assert.Equal(children[1].Path, "/sitecore/Html Editor Drop Down"); Assert.EndsWith("Html Editor Drop Down.yml", children[1].SerializedItemId); } }
public void Save_WritesExpectedItems_WhenItemNameIsTooLong_AndItemsWithSameShortenedNameExist() { using (var testTree = new TestSfsTree()) { // force the tree to shorten after 10 char names testTree.MaxFileNameLengthForTests = 10; CreateTestTree("/sitecore/hello hello", testTree); testTree.Save(CreateTestItem("/sitecore/hello hello hello", testTree.GetRootItem().Id)); var overlengthItems = testTree.GetChildren(testTree.GetRootItem()).OrderBy(i => i.SerializedItemId).ToArray(); Assert.Equal(2, overlengthItems.Length); Assert.Equal("/sitecore/hello hello", overlengthItems[0].Path); Assert.EndsWith("hello hell.yml", overlengthItems[0].SerializedItemId); Assert.Equal("/sitecore/hello hello hello", overlengthItems[1].Path); Assert.EndsWith("hello hell_" + overlengthItems[1].Id + ".yml", overlengthItems[1].SerializedItemId); } }
public void GetRootItem_ReturnsExpectedItem_WhenTreeIsAtRoot() { using (var testTree = new TestSfsTree()) { testTree.CreateTestTree("/sitecore"); var root = testTree.GetRootItem(); Assert.NotNull(root); Assert.Equal(root.Name, "sitecore"); } }
public void GetRootItem_ReturnsExpectedItem_WhenNameHasInvalidChars() { using (var testTree = new TestSfsTree("/<h\\tml>")) { testTree.CreateTestTree("/<h\\tml>"); var root = testTree.GetRootItem(); Assert.NotNull(root); Assert.Equal(root.Name, "<h\\tml>"); } }
public void GetRootItem_ReturnsExpectedItem_WhenTreeIsNested() { using (var testTree = new TestSfsTree("/sitecore/templates/User Defined")) { testTree.CreateTestTree("/sitecore/templates/User Defined"); var root = testTree.GetRootItem(); Assert.NotNull(root); Assert.Equal(root.Name, "User Defined"); } }
public void GetRootItem_ReturnsExpectedItem_WhenTreeIsAtRoot() { using (var testTree = new TestSfsTree()) { CreateTestTree("/sitecore", testTree); var root = testTree.GetRootItem(); Assert.NotNull(root); Assert.Equal(root.Name, "sitecore"); } }
public void GetRootItem_ReturnsExpectedItem_WhenTreeIsNested() { using (var testTree = new TestSfsTree("/sitecore/templates/User Defined")) { CreateTestTree("/sitecore/templates/User Defined", testTree); var root = testTree.GetRootItem(); Assert.NotNull(root); Assert.Equal(root.Name, "User Defined"); } }
public void GetRootItem_ReturnsExpectedItem_WhenNameHasInvalidChars() { using (var testTree = new TestSfsTree("/<h\\tml>")) { CreateTestTree("/<h\\tml>", testTree); var root = testTree.GetRootItem(); Assert.NotNull(root); Assert.Equal(root.Name, "<h\\tml>"); } }
public void GetChildren_ReturnsEmptyEnumerable_WhenNoChildrenExist() { using (var testTree = new TestSfsTree()) { CreateTestTree("/sitecore", testTree); // get the children of the root, which be empty var results = testTree.GetChildren(testTree.GetRootItem()); Assert.NotNull(results); Assert.Empty(results); } }
public void GetChildren_ReturnsEmptyEnumerable_WhenNoChildrenExist() { using (var testTree = new TestSfsTree()) { testTree.CreateTestTree("/sitecore"); // get the children of the root, which be empty var results = testTree.GetChildren(testTree.GetRootItem()); Assert.NotNull(results); Assert.Empty(results); } }
public void GetItemById_ResolvesItem_WhenItemIsRoot() { using (var testTree = new TestSfsTree()) { testTree.CreateTestTree("/sitecore"); var root = testTree.GetRootItem(); var byId = testTree.GetItemById(root.Id); Assert.NotNull(byId); Assert.Equal(root.Id, byId.Id); } }
public void GetChildren_ReturnsExpectedItem_WhenNamesContainInvalidPathChars() { using (var testTree = new TestSfsTree("/<html>")) { testTree.CreateTestTree("/<html>/$head"); var root = testTree.GetRootItem(); var children = testTree.GetChildren(root).ToArray(); Assert.NotNull(children); Assert.Equal(1, children.Length); Assert.Equal(children[0].Name, "$head"); } }
public void GetChildren_ReturnsExpectedItem_WhenRootPathIsParent_AndTreeIsAtRoot() { using (var testTree = new TestSfsTree()) { testTree.CreateTestTree("/sitecore/templates"); var root = testTree.GetRootItem(); var children = testTree.GetChildren(root).ToArray(); Assert.NotNull(children); Assert.Equal(1, children.Length); Assert.Equal(children[0].Name, "templates"); } }
public void GetItemByPath_GetsExpectedItem_WhenItemNameIsTooLong_AndItemsWithSameShortenedNameExist() { using (var testTree = new TestSfsTree()) { // force the tree to shorten after 10 char names testTree.MaxFileNameLengthForTests = 10; CreateTestTree("/sitecore/hello hello", testTree); testTree.Save(CreateTestItem("/sitecore/hello hello hello", testTree.GetRootItem().Id)); var overlengthItem = testTree.GetItemsByPath("/sitecore/hello hello").ToArray(); Assert.Equal(1, overlengthItem.Count()); Assert.Equal("/sitecore/hello hello", overlengthItem.First().Path); } }
public void GetItemById_ResolvesItem_WhenItemIsRoot_AndCacheIsEmpty() { using (var testTree = new TestSfsTree()) { CreateTestTree("/sitecore", testTree); var root = testTree.GetRootItem(); testTree.ClearAllCaches(); var byId = testTree.GetItemById(root.Id); Assert.NotNull(byId); Assert.Equal(root.Id, byId.Id); } }
public void GetItemByPath_GetsExpectedItem_WhenItemNameIsTooLong_AndItemsWithSameShortenedNameExist() { using (var testTree = new TestSfsTree()) { // force the tree to shorten after 10 char names testTree.MaxFileNameLengthForTests = 10; testTree.CreateTestTree("/sitecore/hello hello"); testTree.Save("/sitecore/hello hello hello".AsTestItem(testTree.GetRootItem().Id)); var overlengthItem = testTree.GetItemsByPath("/sitecore/hello hello").ToArray(); Assert.Equal(1, overlengthItem.Length); Assert.Equal("/sitecore/hello hello", overlengthItem.First().Path); } }
public void Save_WritesItem_WhenPathRequiresLoopbackFolder() { using (var testTree = new TestSfsTree()) { // force the tree to loopback after only 10 chars after the root path testTree.MaxPathLengthForTests = 10; testTree.CreateTestTree("/sitecore/content"); var rootItem = testTree.GetRootItem(); var loopedItem = testTree.GetChildren(rootItem).First(); Assert.Equal("/sitecore/content", loopedItem.Path); // loopback path will have root item ID in it Assert.True(loopedItem.SerializedItemId.Contains(rootItem.Id.ToString())); } }
public void GetChildren_ReturnsExpectedItems_WhenMultipleSameNamedMatchesExist() { using (var testTree = new TestSfsTree()) { const string treePath = "/sitecore/templates"; testTree.CreateTestTree(treePath); var testItem = testTree.GetItemsByPath(treePath); // add a second templates item testTree.Save(treePath.AsTestItem(testItem.First().ParentId)); // get the children of the root, which should include the two same named items var results = testTree.GetChildren(testTree.GetRootItem()).ToArray(); Assert.Equal(2, results.Length); Assert.NotEqual(results[0].Id, results[1].Id); Assert.NotEqual(results[0].SerializedItemId, results[1].SerializedItemId); } }
public void GetChildren_ReturnsExpectedItems_WhenMultipleMatchesExist() { using (var testTree = new TestSfsTree()) { const string treePath = "/sitecore/templates"; testTree.CreateTestTree(treePath); var testItem = testTree.GetItemsByPath(treePath); // add a second child item testTree.Save("/sitecore/system".AsTestItem(testItem.First().ParentId)); // get the children of the root, which should include the two items var results = testTree.GetChildren(testTree.GetRootItem()).ToArray(); Assert.Equal(2, results.Length); Assert.NotEqual(results[0].Id, results[1].Id); Assert.NotEqual(results[0].SerializedItemId, results[1].SerializedItemId); Assert.True(results.Any(result => result.Name == "templates")); Assert.True(results.Any(result => result.Name == "system")); } }
public void Save_WritesItem_WhenItemNameIsFullOfInvalidChars() { using (var testTree = new TestSfsTree()) { testTree.CreateTestTree("/sitecore/%<html>?*"); var rootItem = testTree.GetRootItem(); var charsItem = testTree.GetChildren(rootItem).First(); Assert.Equal("/sitecore/%<html>?*", charsItem.Path); } }
public void Save_WritesItem_WhenPathRequiresDoubleLoopbackFolder() { using (var testTree = new TestSfsTree()) { // force the tree to loopback after only 10 chars after the root path // this also means that double loopback occurs each time because the loopback ID is 35 chars testTree.MaxPathLengthForTests = 10; testTree.CreateTestTree("/sitecore/content/hello"); var rootItem = testTree.GetRootItem(); var loopedItem = testTree.GetChildren(rootItem).First(); var secondLoopedItem = testTree.GetChildren(loopedItem).First(); Assert.Equal("/sitecore/content", loopedItem.Path); // loopback path will have root item ID in it Assert.True(loopedItem.SerializedItemId.Contains(rootItem.Id.ToString())); Assert.Equal("/sitecore/content/hello", secondLoopedItem.Path); // loopback path will have root item ID in it Assert.True(secondLoopedItem.SerializedItemId.Contains(loopedItem.Id.ToString())); } }
public void Save_WritesItem_WhenItemNameIsTooLong() { using (var testTree = new TestSfsTree()) { // force the tree to shorten after 10 char names testTree.MaxFileNameLengthForTests = 10; testTree.CreateTestTree("/sitecore/hello hello"); var rootItem = testTree.GetRootItem(); var overlengthItem = testTree.GetChildren(rootItem).First(); Assert.Equal("/sitecore/hello hello", overlengthItem.Path); // name should be truncated Assert.True(overlengthItem.SerializedItemId.EndsWith("hello hell.yml")); } }