public void GetItemsByPath_ReturnsExpectedItems_WhenChildPathIsRequested_AndMultipleMatchesExist_ThroughSeparateParents() { using (var testTree = new TestSfsTree()) { const string treePath = "/sitecore/templates/User Defined"; testTree.CreateTestTree(treePath); var testItem = testTree.GetItemsByPath("/sitecore/templates"); var templates1 = testItem.First(); // add a second Templates item var templates2 = "/sitecore/templates".AsTestItem(templates1.ParentId); testTree.Save(templates2); // add a child under the second templates item, giving us '/sitecore/templates/User Defined' under templates1, and '/sitecore/templates/Evil' under templates2 // P.S. don't actually do this in real life. Please? But I'm testing it, because I'm an effing pedant :) testTree.Save("/sitecore/templates/Evil".AsTestItem(templates2.Id)); var results = testTree.GetItemsByPath("/sitecore/templates").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.Id == templates1.Id)); Assert.True(results.Any(result => result.Id == templates2.Id)); } }
public void Remove_DeletesItem_WhenItemHasChildren() { using (var testTree = new TestSfsTree()) { CreateTestTree("/sitecore/content/foo/bar/baz/boing", testTree); var item = testTree.GetItemsByPath("/sitecore/content").First(); testTree.Remove(item); Assert.Empty(Directory.GetFileSystemEntries(Path.GetDirectoryName(item.SerializedItemId))); Assert.Empty(testTree.GetItemsByPath("/sitecore/content")); } }
public void Remove_DeletesItem_WhenItemHasChildren() { using (var testTree = new TestSfsTree()) { testTree.CreateTestTree("/sitecore/content/foo/bar/baz/boing"); var item = testTree.GetItemsByPath("/sitecore/content").First(); testTree.Remove(item); Assert.Empty(Directory.GetFileSystemEntries(Path.GetDirectoryName(item.SerializedItemId))); Assert.Empty(testTree.GetItemsByPath("/sitecore/content")); } }
public void GetChildren_ReturnsExpectedItems_WhenMultipleMatchesExist_ThroughSeparateParents() { using (var testTree = new TestSfsTree()) { const string treePath = "/sitecore/templates/User Defined"; CreateTestTree(treePath, testTree); var testItem = testTree.GetItemsByPath("/sitecore/templates"); var templates1 = testItem.First(); // add a second Templates item var templates2 = CreateTestItem("/sitecore/templates", templates1.ParentId); testTree.Save(templates2); // add a child under the second templates item, giving us '/sitecore/templates/User Defined' under templates1, and '/sitecore/templates/Evil' under templates2 // P.S. don't actually do this in real life. Please? But I'm testing it, because I'm an effing pedant :) testTree.Save(CreateTestItem("/sitecore/templates/Evil", templates2.Id)); // get the children of templates1, which should NOT include templates2's child var results = testTree.GetChildren(templates1).ToArray(); Assert.Equal(1, results.Length); Assert.Equal("User Defined", results[0].Name); } }
public void GetChildren_ReturnsExpectedItems_WhenMultipleMatchesExist_ThroughSeparateParents() { using (var testTree = new TestSfsTree()) { const string treePath = "/sitecore/templates/User Defined"; testTree.CreateTestTree(treePath); var testItem = testTree.GetItemsByPath("/sitecore/templates"); var templates1 = testItem.First(); // add a second Templates item var templates2 = "/sitecore/templates".AsTestItem(templates1.ParentId); testTree.Save(templates2); // add a child under the second templates item, giving us '/sitecore/templates/User Defined' under templates1, and '/sitecore/templates/Evil' under templates2 // P.S. don't actually do this in real life. Please? But I'm testing it, because I'm an effing pedant :) testTree.Save("/sitecore/templates/Evil".AsTestItem(templates2.Id)); // get the children of templates1, which should NOT include templates2's child var results = testTree.GetChildren(templates1).ToArray(); Assert.Equal(1, results.Length); Assert.Equal("User Defined", results[0].Name); } }
public void GetChildren_ReturnsExpectedItems_WhenNameTruncationCausesSimilarNames() { using (var testTree = new TestSfsTree()) { testTree.MaxFileNameLengthForTests = 10; const string treePath = "/sitecore/templates"; testTree.CreateTestTree(treePath); var testItem = testTree.GetItemsByPath(treePath).First(); var multilist = "/sitecore/templates/Multilist".AsTestItem(testItem.Id); var multilistWithSearch = "/sitecore/templates/Multilist with Search".AsTestItem(testItem.Id); var multilistChild = "/sitecore/templates/Multilist/Menu".AsTestItem(multilist.Id); var multilistWithSearchChild = "/sitecore/templates/Multilist with Search/Menu".AsTestItem(multilistWithSearch.Id); testTree.Save(multilist); testTree.Save(multilistWithSearch); testTree.Save(multilistChild); testTree.Save(multilistWithSearchChild); // now we'll have "Multilist.yml" and "Multilist .yml" - make sure we get the right children from each // get the children of the root, which should include the two same named items var multilistChildren = testTree.GetChildren(multilist).ToArray(); var multilistWithSearchChildren = testTree.GetChildren(multilistWithSearch).ToArray(); Assert.Equal(1, multilistChildren.Length); Assert.Equal(multilistChild.Id, multilistChildren.First().Id); Assert.Equal(1, multilistWithSearchChildren.Length); Assert.Equal(multilistWithSearchChild.Id, multilistWithSearchChildren.First().Id); } }
public void Save_WritesItem_WhenPathRequiresChildOfLoopbackFolder() { using (var testTree = new TestSfsTree()) { // force the tree to loopback after only 50 chars after the root path testTree.MaxPathLengthForTests = 50; // this tree is long enough to loopback, but the 'hello' is short enough to be a child of the first loopback at 'e' testTree.CreateTestTree("/sitecore/content lorem/ipsum dolor/sit amet/e/hello"); var loopParent = testTree.GetItemsByPath("/sitecore/content lorem/ipsum dolor/sit amet").First(); var helloItem = testTree.GetItemsByPath("/sitecore/content lorem/ipsum dolor/sit amet/e/hello").First(); Assert.Equal("/sitecore/content lorem/ipsum dolor/sit amet/e/hello", helloItem.Path); // hello item will have looped id in it Assert.True(helloItem.SerializedItemId.Contains(loopParent.Id.ToString())); } }
public void Save_WritesItem_WhenPathRequiresChildOfDoubleLoopbackFolder() { using (var testTree = new TestSfsTree()) { // force the tree to loopback after only 50 chars after the root path testTree.MaxPathLengthForTests = 50; // this tree is long enough that it will loopback at 'elitr foo bar baz', and that '{id}+/elitr foo bar baz' will make it loopback again on 'h', leaving the final 'hello' a child of the second loopback testTree.CreateTestTree("/sitecore/content lorem/ipsum dolor/sit amet/elitr foo bar baz/h/hello"); var loopParent = testTree.GetItemsByPath("/sitecore/content lorem/ipsum dolor/sit amet/elitr foo bar baz").First(); var helloItem = testTree.GetItemsByPath("/sitecore/content lorem/ipsum dolor/sit amet/elitr foo bar baz/h/hello").First(); Assert.Equal("/sitecore/content lorem/ipsum dolor/sit amet/elitr foo bar baz/h/hello", helloItem.Path); // hello item will have looped id in it Assert.True(helloItem.SerializedItemId.Contains(loopParent.Id.ToString())); } }
public void Save_WritesItem_WhenPathRequiresChildOfLoopbackFolder() { using (var testTree = new TestSfsTree()) { // force the tree to loopback after only 50 chars after the root path testTree.MaxPathLengthForTests = 50; // this tree is long enough to loopback, but the 'hello' is short enough to be a child of the first loopback at 'e' testTree.CreateTestTree("/sitecore/content lorem/ipsum dolor/sit amet/e/hello"); var loopParent = testTree.GetItemsByPath("/sitecore/content lorem/ipsum dolor/sit amet").First(); var helloItem = testTree.GetItemsByPath("/sitecore/content lorem/ipsum dolor/sit amet/e/hello").First(); Assert.Equal("/sitecore/content lorem/ipsum dolor/sit amet/e/hello", helloItem.Path); // hello item will have looped id in it Assert.True(helloItem.SerializedItemId.Contains(loopParent.Id.ToString())); } }
public void GetItemsByPath_ReturnsExpectedItems_WhenChildPathIsRequested_AndMultipleMatchesExist() { using (var testTree = new TestSfsTree()) { const string treePath = "/sitecore/templates/User Defined"; testTree.CreateTestTree(treePath); var testItem = testTree.GetItemsByPath(treePath); // add a second User Defined item testTree.Save(treePath.AsTestItem(testItem.First().ParentId)); var results = testTree.GetItemsByPath(treePath).ToArray(); Assert.Equal(2, results.Length); Assert.NotEqual(results[0].Id, results[1].Id); Assert.NotEqual(results[0].SerializedItemId, results[1].SerializedItemId); } }
public void GetItemsByPath_ReturnsExpectedItems_WhenChildPathIsRequested_AndMultipleMatchesExist() { using (var testTree = new TestSfsTree()) { const string treePath = "/sitecore/templates/User Defined"; CreateTestTree(treePath, testTree); var testItem = testTree.GetItemsByPath(treePath); // add a second User Defined item testTree.Save(CreateTestItem(treePath, testItem.First().ParentId)); var results = testTree.GetItemsByPath(treePath).ToArray(); Assert.Equal(2, results.Length); Assert.NotEqual(results[0].Id, results[1].Id); Assert.NotEqual(results[0].SerializedItemId, results[1].SerializedItemId); } }
public void Remove_DeletesItem_WhenItemHasChildrenInLoopbackDirectory() { using (var testTree = new TestSfsTree()) { // force the tree to loopback after only 50 chars after the root path testTree.MaxPathLengthForTests = testTree.PhysicalRootPathTest.Length + 50; // this tree is long enough to loopback, but the 'hello' is short enough to be a child of the first loopback at 'e' CreateTestTree("/sitecore/content lorem/ipsum dolor/sit amet/e/hello", testTree); var loopParent = testTree.GetItemsByPath("/sitecore/content lorem/ipsum dolor/sit amet").First(); var helloItem = testTree.GetItemsByPath("/sitecore/content lorem/ipsum dolor/sit amet/e/hello").First(); testTree.Remove(loopParent); Assert.False(File.Exists(loopParent.SerializedItemId)); Assert.False(Directory.Exists(Path.Combine(testTree.PhysicalRootPathTest, loopParent.Id.ToString()))); Assert.False(File.Exists(helloItem.SerializedItemId)); } }
public void Save_SetsSerializedItemId_WhenUsingDataCache() { using (var testTree = new TestSfsTree(useDataCache: true)) { testTree.CreateTestTree("/sitecore"); var item = testTree.GetItemsByPath("/sitecore").First(); Assert.Equal(item.SerializedItemId, Path.Combine(testTree.PhysicalRootPath, "sitecore.yml")); } }
public void Remove_DeletesItem_WhenItemHasChildrenInLoopbackDirectory() { using (var testTree = new TestSfsTree()) { // force the tree to loopback after only 50 chars after the root path testTree.MaxPathLengthForTests = testTree.PhysicalRootPath.Length + 50; // this tree is long enough to loopback, but the 'hello' is short enough to be a child of the first loopback at 'e' testTree.CreateTestTree("/sitecore/content lorem/ipsum dolor/sit amet/e/hello"); var loopParent = testTree.GetItemsByPath("/sitecore/content lorem/ipsum dolor/sit amet").First(); var helloItem = testTree.GetItemsByPath("/sitecore/content lorem/ipsum dolor/sit amet/e/hello").First(); testTree.Remove(loopParent); Assert.False(File.Exists(loopParent.SerializedItemId)); Assert.False(Directory.Exists(Path.Combine(testTree.PhysicalRootPath, loopParent.Id.ToString()))); Assert.False(File.Exists(helloItem.SerializedItemId)); } }
public void Remove_DeletesItem_WhenItemHasChildrenInDoubleLoopbackDirectory() { using (var testTree = new TestSfsTree()) { // force the tree to loopback after only 50 chars after the root path testTree.MaxPathLengthForTests = testTree.PhysicalRootPathTest.Length + 50; // this tree is long enough that it will loopback at 'elitr foo bar baz', and that '{id}+/elitr foo bar baz' will make it loopback again on 'h', leaving the final 'hello' a child of the second loopback CreateTestTree("/sitecore/content lorem/ipsum dolor/sit amet/elitr foo bar baz/h/hello", testTree); var loopParent = testTree.GetItemsByPath("/sitecore/content lorem/ipsum dolor/sit amet/elitr foo bar baz").First(); var loop2Parent = testTree.GetItemsByPath("/sitecore/content lorem/ipsum dolor/sit amet/elitr foo bar baz/h").First(); var helloItem = testTree.GetItemsByPath("/sitecore/content lorem/ipsum dolor/sit amet/elitr foo bar baz/h/hello").First(); testTree.Remove(loopParent); Assert.False(File.Exists(loop2Parent.SerializedItemId)); Assert.False(Directory.Exists(Path.Combine(testTree.PhysicalRootPathTest, loop2Parent.Id.ToString()))); Assert.False(File.Exists(helloItem.SerializedItemId)); } }
public void Remove_DeletesItem_WhenItemHasChildrenInDoubleLoopbackDirectory() { using (var testTree = new TestSfsTree()) { // force the tree to loopback after only 50 chars after the root path testTree.MaxPathLengthForTests = testTree.PhysicalRootPath.Length + 50; // this tree is long enough that it will loopback at 'elitr foo bar baz', and that '{id}+/elitr foo bar baz' will make it loopback again on 'h', leaving the final 'hello' a child of the second loopback testTree.CreateTestTree("/sitecore/content lorem/ipsum dolor/sit amet/elitr foo bar baz/h/hello"); var loopParent = testTree.GetItemsByPath("/sitecore/content lorem/ipsum dolor/sit amet/elitr foo bar baz").First(); var loop2Parent = testTree.GetItemsByPath("/sitecore/content lorem/ipsum dolor/sit amet/elitr foo bar baz/h").First(); var helloItem = testTree.GetItemsByPath("/sitecore/content lorem/ipsum dolor/sit amet/elitr foo bar baz/h/hello").First(); testTree.Remove(loopParent); Assert.False(File.Exists(loop2Parent.SerializedItemId)); Assert.False(Directory.Exists(Path.Combine(testTree.PhysicalRootPath, loop2Parent.Id.ToString()))); Assert.False(File.Exists(helloItem.SerializedItemId)); } }
public void GetItemsByPath_ReturnsExpectedItem_WhenChildPathIsRequested_AndTreeIsNested() { using (var testTree = new TestSfsTree("/sitecore/templates")) { testTree.CreateTestTree("/sitecore/templates/User Defined"); var root = testTree.GetItemsByPath("/sitecore/templates/User Defined").ToArray(); Assert.NotNull(root); Assert.NotEmpty(root); Assert.Equal(root.First().Name, "User Defined"); } }
public void GetItemsByPath_ReturnsExpectedItem_WhenChildPathIsRequested_AndTreeIsNested() { using (var testTree = new TestSfsTree("/sitecore/templates")) { testTree.CreateTestTree("/sitecore/templates/User Defined"); var root = testTree.GetItemsByPath("/sitecore/templates/User Defined").ToArray(); Assert.NotNull(root); Assert.NotEmpty(root); Assert.Equal(root.First().Name, "User Defined"); } }
public void GetItemsByPath_ReturnsExpectedItem_WhenRootPathIsRequested_AndTreeIsAtRoot() { using (var testTree = new TestSfsTree()) { testTree.CreateTestTree("/sitecore"); var root = testTree.GetItemsByPath("/sitecore").ToArray(); Assert.NotNull(root); Assert.NotEmpty(root); Assert.Equal(root.First().Name, "sitecore"); } }
public void GetItemsByPath_ReturnsExpectedItem_WhenChildPathIsRequested_AndNamesContainInvalidPathChars() { using (var testTree = new TestSfsTree("/?hello*")) { testTree.CreateTestTree("/?hello*/%there%"); var root = testTree.GetItemsByPath("/?hello*/%there%").ToArray(); Assert.NotNull(root); Assert.NotEmpty(root); Assert.Equal(root.First().Name, "%there%"); } }
public void GetItemsByPath_ReturnsExpectedItem_WhenRootPathIsRequested_AndTreeIsAtRoot() { using (var testTree = new TestSfsTree()) { testTree.CreateTestTree("/sitecore"); var root = testTree.GetItemsByPath("/sitecore").ToArray(); Assert.NotNull(root); Assert.NotEmpty(root); Assert.Equal(root.First().Name, "sitecore"); } }
public void GetItemById_ResolvesItem_WhenItemIsChild() { using (var testTree = new TestSfsTree()) { testTree.CreateTestTree("/sitecore/content/foo"); var item = testTree.GetItemsByPath("/sitecore/content/foo").First(); var byId = testTree.GetItemById(item.Id); Assert.NotNull(byId); Assert.Equal(item.Id, byId.Id); } }
public void GetItemById_ResolvesItem_WhenItemIsChild() { using (var testTree = new TestSfsTree()) { testTree.CreateTestTree("/sitecore/content/foo"); var item = testTree.GetItemsByPath("/sitecore/content/foo").First(); var byId = testTree.GetItemById(item.Id); Assert.NotNull(byId); Assert.Equal(item.Id, byId.Id); } }
public void GetChildren_ReturnsExpectedItem_WhenRootPathIsParent_AndTreeIsNested() { using (var testTree = new TestSfsTree("/sitecore/templates")) { testTree.CreateTestTree("/sitecore/templates/User Defined"); var root = testTree.GetItemsByPath("/sitecore/templates").First(); var children = testTree.GetChildren(root).ToArray(); Assert.NotNull(children); Assert.Equal(1, children.Length); Assert.Equal(children[0].Name, "User Defined"); } }
public void GetItemByPath_GetsExpectedItem_WhenItemNameIsTooLong() { using (var testTree = new TestSfsTree()) { // force the tree to shorten after 10 char names testTree.MaxFileNameLengthForTests = 10; testTree.CreateTestTree("/sitecore/hello hello"); var overlengthItem = testTree.GetItemsByPath("/sitecore/hello hello").ToArray(); Assert.Equal(1, overlengthItem.Length); Assert.Equal("/sitecore/hello hello", overlengthItem.First().Path); } }
public void GetChildren_ReturnsExpectedItem_WhenRootPathIsParent_AndTreeIsNested() { using (var testTree = new TestSfsTree("/sitecore/templates")) { testTree.CreateTestTree("/sitecore/templates/User Defined"); var root = testTree.GetItemsByPath("/sitecore/templates").First(); var children = testTree.GetChildren(root).ToArray(); Assert.NotNull(children); Assert.Equal(1, children.Length); Assert.Equal(children[0].Name, "User Defined"); } }
public void GetItemByPath_GetsExpectedItem_WhenPathIsAChildOfShortenedName() { using (var testTree = new TestSfsTree()) { // force the tree to shorten after 10 char names testTree.MaxFileNameLengthForTests = 10; CreateTestTree("/sitecore/hello hello/goodbye", testTree); var overlengthChild = testTree.GetItemsByPath("/sitecore/hello hello/goodbye").ToArray(); Assert.Equal(1, overlengthChild.Count()); Assert.Equal("/sitecore/hello hello/goodbye", overlengthChild.First().Path); } }
public void GetItemByPath_GetsExpectedItem_WhenItemNameIsTooLong() { using (var testTree = new TestSfsTree()) { // force the tree to shorten after 10 char names testTree.MaxFileNameLengthForTests = 10; CreateTestTree("/sitecore/hello hello", testTree); var overlengthItem = testTree.GetItemsByPath("/sitecore/hello hello").ToArray(); Assert.Equal(1, overlengthItem.Count()); Assert.Equal("/sitecore/hello hello", overlengthItem.First().Path); } }
public void GetItemByPath_GetsExpectedItem_WhenPathIsAChildOfShortenedName() { using (var testTree = new TestSfsTree()) { // force the tree to shorten after 10 char names testTree.MaxFileNameLengthForTests = 10; testTree.CreateTestTree("/sitecore/hello hello/goodbye"); var overlengthChild = testTree.GetItemsByPath("/sitecore/hello hello/goodbye").ToArray(); Assert.Equal(1, overlengthChild.Length); Assert.Equal("/sitecore/hello hello/goodbye", overlengthChild.First().Path); } }
public void GetItemsByPath_ReturnsExpectedItem_WhenChildPathIsRequested_AndTreeIsAtRoot_CaseInsensitive() { using (var testTree = new TestSfsTree()) { testTree.CreateTestTree("/sitecore/templates/User Defined"); testTree.ClearAllCaches(); var root = testTree.GetItemsByPath("/sitecore/templates/uSer dEfiNed").ToArray(); Assert.NotNull(root); Assert.NotEmpty(root); Assert.Equal(root.First().Name, "User Defined"); } }
public void GetItemsByPath_ReturnsExpectedItem_WhenChildPathIsRequested_AndTreeIsAtRoot_CaseInsensitive() { using (var testTree = new TestSfsTree()) { testTree.CreateTestTree("/sitecore/templates/User Defined"); testTree.ClearAllCaches(); var root = testTree.GetItemsByPath("/sitecore/templates/uSer dEfiNed").ToArray(); Assert.NotNull(root); Assert.NotEmpty(root); Assert.Equal(root.First().Name, "User Defined"); } }
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 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_WhenPathRequiresChildOfDoubleLoopbackFolder() { using (var testTree = new TestSfsTree()) { // force the tree to loopback after only 50 chars after the root path testTree.MaxPathLengthForTests = 50; // this tree is long enough that it will loopback at 'elitr foo bar baz', and that '{id}+/elitr foo bar baz' will make it loopback again on 'h', leaving the final 'hello' a child of the second loopback testTree.CreateTestTree("/sitecore/content lorem/ipsum dolor/sit amet/elitr foo bar baz/h/hello"); var loopParent = testTree.GetItemsByPath("/sitecore/content lorem/ipsum dolor/sit amet/elitr foo bar baz").First(); var helloItem = testTree.GetItemsByPath("/sitecore/content lorem/ipsum dolor/sit amet/elitr foo bar baz/h/hello").First(); Assert.Equal("/sitecore/content lorem/ipsum dolor/sit amet/elitr foo bar baz/h/hello", helloItem.Path); // hello item will have looped id in it Assert.True(helloItem.SerializedItemId.Contains(loopParent.Id.ToString())); } }
public void GetItemsByPath_ReturnsExpectedItems_WhenChildPathIsRequested_AndMultipleMatchesExist_ThroughSeparateParents() { using (var testTree = new TestSfsTree()) { const string treePath = "/sitecore/templates/User Defined"; CreateTestTree(treePath, testTree); var testItem = testTree.GetItemsByPath("/sitecore/templates"); var templates1 = testItem.First(); // add a second Templates item var templates2 = CreateTestItem("/sitecore/templates", templates1.ParentId); testTree.Save(templates2); // add a child under the second templates item, giving us '/sitecore/templates/User Defined' under templates1, and '/sitecore/templates/Evil' under templates2 // P.S. don't actually do this in real life. Please? But I'm testing it, because I'm an effing pedant :) testTree.Save(CreateTestItem("/sitecore/templates/Evil", templates2.Id)); var results = testTree.GetItemsByPath("/sitecore/templates").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.Id == templates1.Id)); Assert.True(results.Any(result => result.Id == templates2.Id)); } }
public void GetItemsByPath_ReturnsExpectedItem_WhenChildPathIsRequested_AndNamesContainInvalidPathChars() { using (var testTree = new TestSfsTree("/?hello*")) { CreateTestTree("/?hello*/%there%", testTree); var root = testTree.GetItemsByPath("/?hello*/%there%").ToArray(); Assert.NotNull(root); Assert.NotEmpty(root); Assert.Equal(root.First().Name, "%there%"); } }
public void GetChildren_ReturnsExpectedItems_WhenNameTruncationCausesSimilarNames() { using (var testTree = new TestSfsTree()) { testTree.MaxFileNameLengthForTests = 10; const string treePath = "/sitecore/templates"; testTree.CreateTestTree(treePath); var testItem = testTree.GetItemsByPath(treePath).First(); var multilist = "/sitecore/templates/Multilist".AsTestItem(testItem.Id); var multilistWithSearch = "/sitecore/templates/Multilist with Search".AsTestItem(testItem.Id); var multilistChild = "/sitecore/templates/Multilist/Menu".AsTestItem(multilist.Id); var multilistWithSearchChild = "/sitecore/templates/Multilist with Search/Menu".AsTestItem(multilistWithSearch.Id); testTree.Save(multilist); testTree.Save(multilistWithSearch); testTree.Save(multilistChild); testTree.Save(multilistWithSearchChild); // now we'll have "Multilist.yml" and "Multilist .yml" - make sure we get the right children from each // get the children of the root, which should include the two same named items var multilistChildren = testTree.GetChildren(multilist).ToArray(); var multilistWithSearchChildren = testTree.GetChildren(multilistWithSearch).ToArray(); Assert.Equal(1, multilistChildren.Length); Assert.Equal(multilistChild.Id, multilistChildren.First().Id); Assert.Equal(1, multilistWithSearchChildren.Length); Assert.Equal(multilistWithSearchChild.Id, multilistWithSearchChildren.First().Id); } }