Пример #1
0
        public void DeleteSearchNavigationNodeTest()
        {
            using (var clientContext = TestCommon.CreateClientContext())
            {
                var web = clientContext.Web;

                // First clear all search nav nodes
                var nodeCollection = web.LoadSearchNavigation();
                foreach (var node in nodeCollection.ToList())
                {
                    node.DeleteObject();
                }
                clientContext.ExecuteQueryRetry();

                web.AddNavigationNode("Test Node", new Uri("https://www.microsoft.com"), string.Empty, NavigationType.SearchNav);

                web.DeleteNavigationNode("Test Node", string.Empty, NavigationType.SearchNav);

                NavigationNodeCollection searchNavigation = web.LoadSearchNavigation();

                if (searchNavigation.Any())
                {
                    var navNode = searchNavigation.FirstOrDefault(n => n.Title == "Test Node");
                    Assert.IsNull(navNode);
                }
            }
        }
Пример #2
0
        /// <summary>
        /// Creates a navigation node as a child of another (first or second level) navigation node.
        /// </summary>
        /// <param name="web">Site to be processed - can be root web or sub site</param>
        /// <param name="parentNodes">Level one nodes under which the node should be created</param>
        /// <param name="nodeToCreate">Node information</param>
        /// <param name="parentNodeTitle">The title of the immediate parent node (level two if child should be level three, level one otherwise)</param>
        /// <param name="l1ParentNodeTitle">The level one parent title or null, if the node to be created should be a level two node</param>
        /// <returns></returns>
        private static NavigationNode CreateNodeAsChild(Web web, NavigationNodeCollection parentNodes, NavigationNodeCreationInformation nodeToCreate, string parentNodeTitle, string l1ParentNodeTitle)
        {
            if (l1ParentNodeTitle != null)
            {
                var l1ParentNode = parentNodes.FirstOrDefault(n => n.Title.Equals(l1ParentNodeTitle, StringComparison.InvariantCultureIgnoreCase));
                if (l1ParentNode == null)
                {
                    return(null);
                }
                web.Context.Load(l1ParentNode.Children);
                web.Context.ExecuteQueryRetry();
                parentNodes = l1ParentNode.Children;
            }

            var parentNode     = parentNodes.FirstOrDefault(n => n.Title.Equals(parentNodeTitle, StringComparison.InvariantCultureIgnoreCase));
            var navigationNode = parentNode?.Children.Add(nodeToCreate);

            return(navigationNode);
        }
Пример #3
0
        public void DeleteSearchNavigationNodeTest()
        {
            using (var clientContext = TestCommon.CreateClientContext())
            {
                var web = clientContext.Web;

                web.AddNavigationNode("Test Node", new Uri("https://www.microsoft.com"), string.Empty, NavigationType.SearchNav);

                web.DeleteNavigationNode("Test Node", string.Empty, NavigationType.SearchNav);

                NavigationNodeCollection searchNavigation = web.LoadSearchNavigation();

                if (searchNavigation.Any())
                {
                    var navNode = searchNavigation.FirstOrDefault(n => n.Title == "Test Node");
                    Assert.IsNull(navNode);
                }
            }
        }
Пример #4
0
        public void AddSearchNavigationNodeTest()
        {
            using (var clientContext = TestCommon.CreateClientContext())
            {
                var web = clientContext.Web;

                web.AddNavigationNode("Test Node", new Uri("https://www.microsoft.com"), string.Empty, NavigationType.SearchNav);

                NavigationNodeCollection searchNavigation = web.LoadSearchNavigation();

                Assert.IsTrue(searchNavigation.AreItemsAvailable);

                if (searchNavigation.Any())
                {
                    var navNode = searchNavigation.FirstOrDefault(n => n.Title == "Test Node");
                    Assert.IsNotNull(navNode);
                    navNode.DeleteObject();
                    clientContext.ExecuteQueryRetry();
                }
            }
        }