コード例 #1
0
        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);
            }
        }
コード例 #2
0
		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);
			}
		}
コード例 #3
0
        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);
            }
        }
コード例 #4
0
        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);
            }
        }
コード例 #5
0
        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");
            }
        }
コード例 #6
0
        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>");
            }
        }
コード例 #7
0
        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");
            }
        }
コード例 #8
0
        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");
            }
        }
コード例 #9
0
        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");
            }
        }
コード例 #10
0
        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>");
            }
        }
コード例 #11
0
        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);
            }
        }
コード例 #12
0
        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);
            }
        }
コード例 #13
0
		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);
			}
		}
コード例 #14
0
        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");
            }
        }
コード例 #15
0
		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");
			}
		}
コード例 #16
0
        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");
            }
        }
コード例 #17
0
        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);
            }
        }
コード例 #18
0
        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);
            }
        }
コード例 #19
0
        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);
            }
        }
コード例 #20
0
		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()));
			}
		}
コード例 #21
0
        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);
            }
        }
コード例 #22
0
		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"));
			}
		}
コード例 #23
0
		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");
			}
		}
コード例 #24
0
		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);
			}
		}
コード例 #25
0
		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()));
			}
		}
コード例 #26
0
		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"));
			}
		}