public void ToString_BreadcrumbListGoogleStructuredData_ReturnsExpectedJsonLd()
        {
            var breadcrumbList = new BreadcrumbList()
            {
                ItemListElement = new List <ListItem>()
                {
                    new ListItem()
                    {
                        Position = 1,
                        Item     = new Book()
                        {
                            Name  = "Books",
                            Image = new Uri("http://example.com/images/icon-book.png")
                        }
                    },
                    new ListItem()
                    {
                        Position = 2,
                        Item     = new Person()
                        {
                            Name  = "Authors",
                            Image = new Uri("http://example.com/images/icon-author.png")
                        }
                    }
                }
            };
            var expectedJson =
                "{" +
                "\"@context\":\"http://schema.org\"," +
                "\"@type\":\"BreadcrumbList\"," +
                "\"itemListElement\":[" +
                "{" +
                "\"@type\":\"ListItem\"," +
                "\"item\":{" +                                            // Required
                "\"@type\":\"Book\"," +
                "\"name\":\"Books\"," +                                   // Required
                "\"image\":\"http://example.com/images/icon-book.png\"" + // Optional
                "}," +
                "\"position\":1" +                                        // Required
                "}," +
                "{" +
                "\"@type\":\"ListItem\"," +
                "\"item\":{" +
                "\"@type\":\"Person\"," +
                "\"name\":\"Authors\"," +
                "\"image\":\"http://example.com/images/icon-author.png\"" +
                "}," +
                "\"position\":2" +
                "}" +
                "]" +
                "}";

            var json = breadcrumbList.ToString();

            Assert.Equal(expectedJson, json);
        }
Beispiel #2
0
        protected override void OnLoad(EventArgs e)
        {
            base.OnLoad(e);

            // Include all pages but the root page
            BreadcrumbList.DataSource = DataFactory.Instance.GetAncestors(CurrentPage.ContentLink)
                                        .Where(p => !p.ContentLink.CompareToIgnoreWorkID(SiteDefinition.Current.RootPage))
                                        .Reverse();

            BreadcrumbList.DataBind();
        }
        public void BreadcrumbListTest()
        {
            var breadcrumbList = new BreadcrumbList();

            breadcrumbList.ItemListElement = new LinkedList <ListItem>();
            breadcrumbList.ItemListElement.AddLast(new ListItem()
            {
                Item = new Thing()
                {
                    Name = "Home", Url = "http://www.1010tires.com/", Id = "http://www.1010tires.com/"
                },
            });
            breadcrumbList.ItemListElement.AddLast(new ListItem()
            {
                Item = new Thing()
                {
                    Name = "Tires by Brand", Url = "http://www.1010tires.com/Tires/Search", Id = "http://www.1010tires.com/Tires/Search",
                },
            });

            if (breadcrumbList.ItemListOrder == ItemListOrderType.ItemListOrderAscending)
            {
                var i = 1;
                for (LinkedListNode <ListItem> currentNode = breadcrumbList.ItemListElement.First; currentNode != null; currentNode = currentNode.Next)
                {
                    currentNode.Value.Position = i++;
                    //currentNode.Value.Type = currentNode.Value.Url;
                    //currentNode.Value.NextItem = currentNode.Next == null ? null : currentNode.Next.Value;
                    //currentNode.Value.PreviousItem = currentNode.Previous == null ? null : currentNode.Previous.Value;
                }
            }

            System.Diagnostics.Debug.WriteLine(breadcrumbList.ToIndentedJson());

            //<script type="application/ld+json">{
            //  "itemListElement": [
            //    {
            //      "item": {
            //        "additionalType": null,
            //        "alternateName": null,
            //        "description": null,
            //        "image": null,
            //        "name": "Home",
            //        "potentialAction": null,
            //        "sameAs": null,
            //        "url": "http://www.1010tires.com/",
            //        "@context": "http://schema.org",
            //        "@type": "Thing"
            //      },
            //      "nextItem": null,
            //      "position": 1,
            //      "previousItem": null,
            //      "additionalType": null,
            //      "alternateName": null,
            //      "description": null,
            //      "image": null,
            //      "name": null,
            //      "potentialAction": null,
            //      "sameAs": null,
            //      "url": null,
            //      "@context": "http://schema.org",
            //      "@type": "ListItem"
            //    },
            //    {
            //      "item": {
            //        "additionalType": null,
            //        "alternateName": null,
            //        "description": null,
            //        "image": null,
            //        "name": "Tires by Brand",
            //        "potentialAction": null,
            //        "sameAs": null,
            //        "url": "http://www.1010tires.com/Tires/Search",
            //        "@context": "http://schema.org",
            //        "@type": "Thing"
            //      },
            //      "nextItem": null,
            //      "position": 2,
            //      "previousItem": null,
            //      "additionalType": null,
            //      "alternateName": null,
            //      "description": null,
            //      "image": null,
            //      "name": null,
            //      "potentialAction": null,
            //      "sameAs": null,
            //      "url": null,
            //      "@context": "http://schema.org",
            //      "@type": "ListItem"
            //    }
            //  ],
            //  "itemListOrder": "ItemListOrderAscending",
            //  "numberOfItems": 0,
            //  "additionalType": null,
            //  "alternateName": null,
            //  "description": null,
            //  "image": null,
            //  "name": null,
            //  "potentialAction": null,
            //  "sameAs": null,
            //  "url": null,
            //  "@context": "http://schema.org",
            //  "@type": "BreadcrumbList"
            //}</script>
        }
Beispiel #4
0
 /// <summary>
 /// BreadcrumbListOrText as a BreadcrumbList.
 /// </summary>
 /// <param name="breadcrumbList">BreadcrumbListOrText as a BreadcrumbList.</param>
 public BreadcrumbListOrText(BreadcrumbList breadcrumbList)
     : base(breadcrumbList.Name.AsText)
 {
     AsBreadcrumbList = breadcrumbList;
 }
        public void BreadcrumbListTest()
        {
            var breadcrumbList = new BreadcrumbList();
            breadcrumbList.ItemListElement = new LinkedList<ListItem>();
            breadcrumbList.ItemListElement.AddLast(new ListItem()
            {
                Item = new Thing() { Name = "Home", Url = "http://www.1010tires.com/", Id = "http://www.1010tires.com/" },

            });
            breadcrumbList.ItemListElement.AddLast(new ListItem()
            {
                Item = new Thing() { Name = "Tires by Brand", Url = "http://www.1010tires.com/Tires/Search", Id = "http://www.1010tires.com/Tires/Search", },
            });

            if (breadcrumbList.ItemListOrder == ItemListOrderType.ItemListOrderAscending)
            {
                var i = 1;
                for (LinkedListNode<ListItem> currentNode = breadcrumbList.ItemListElement.First; currentNode != null; currentNode = currentNode.Next)
                {
                    currentNode.Value.Position = i++;
                    //currentNode.Value.Type = currentNode.Value.Url;                    
                    //currentNode.Value.NextItem = currentNode.Next == null ? null : currentNode.Next.Value;
                    //currentNode.Value.PreviousItem = currentNode.Previous == null ? null : currentNode.Previous.Value;
                }
            }

            System.Diagnostics.Debug.WriteLine(breadcrumbList.ToIndentedJson());

            //<script type="application/ld+json">{
            //  "itemListElement": [
            //    {
            //      "item": {
            //        "additionalType": null,
            //        "alternateName": null,
            //        "description": null,
            //        "image": null,
            //        "name": "Home",
            //        "potentialAction": null,
            //        "sameAs": null,
            //        "url": "http://www.1010tires.com/",
            //        "@context": "http://schema.org",
            //        "@type": "Thing"
            //      },
            //      "nextItem": null,
            //      "position": 1,
            //      "previousItem": null,
            //      "additionalType": null,
            //      "alternateName": null,
            //      "description": null,
            //      "image": null,
            //      "name": null,
            //      "potentialAction": null,
            //      "sameAs": null,
            //      "url": null,
            //      "@context": "http://schema.org",
            //      "@type": "ListItem"
            //    },
            //    {
            //      "item": {
            //        "additionalType": null,
            //        "alternateName": null,
            //        "description": null,
            //        "image": null,
            //        "name": "Tires by Brand",
            //        "potentialAction": null,
            //        "sameAs": null,
            //        "url": "http://www.1010tires.com/Tires/Search",
            //        "@context": "http://schema.org",
            //        "@type": "Thing"
            //      },
            //      "nextItem": null,
            //      "position": 2,
            //      "previousItem": null,
            //      "additionalType": null,
            //      "alternateName": null,
            //      "description": null,
            //      "image": null,
            //      "name": null,
            //      "potentialAction": null,
            //      "sameAs": null,
            //      "url": null,
            //      "@context": "http://schema.org",
            //      "@type": "ListItem"
            //    }
            //  ],
            //  "itemListOrder": "ItemListOrderAscending",
            //  "numberOfItems": 0,
            //  "additionalType": null,
            //  "alternateName": null,
            //  "description": null,
            //  "image": null,
            //  "name": null,
            //  "potentialAction": null,
            //  "sameAs": null,
            //  "url": null,
            //  "@context": "http://schema.org",
            //  "@type": "BreadcrumbList"
            //}</script>
        }