Пример #1
0
        public void LinkItemToStringTest()
        {
            var linkItem = new LinkItem("/orders");

            linkItem.Name      = "ea";
            linkItem.Templated = true;
            linkItem.AddProperty("age", 10);
            var str = linkItem.ToString();
        }
Пример #2
0
        public void LinkItemCollectionToStringTest()
        {
            var linkItem = new LinkItem("/orders");

            linkItem.Name      = "ea";
            linkItem.Templated = true;
            linkItem.AddProperty("age", 10);

            var collection = new LinkItemCollection()
            {
                linkItem
            };

            var json = collection.ToString();
        }
Пример #3
0
        public void LinkItemCollectionWithMultipleItemsToStringTest()
        {
            var linkItem1 = new LinkItem("/orders");

            linkItem1.Name      = "ea";
            linkItem1.Templated = true;
            linkItem1.AddProperty("age", 10);

            var linkItem2 = new LinkItem("/customers");

            var collection = new LinkItemCollection()
            {
                linkItem1, linkItem2
            };

            var json = collection.ToString();
        }
Пример #4
0
        /// <summary>
        /// Builds the <see cref="Resource" /> instance.
        /// </summary>
        /// <param name="resource"></param>
        /// <returns>
        /// The <see cref="Resource" /> instance to be built.
        /// </returns>
        protected override Resource DoBuild(Resource resource)
        {
            var link = resource.Links.FirstOrDefault(x => x.Rel.Equals(this.rel));

            if (link == null)
            {
                link = new Link(this.rel);
                resource.Links.Add(link);
            }

            if (link.Items == null)
            {
                link.Items = new LinkItemCollection(this.enforcingArrayConverting);
            }

            var linkItem = new LinkItem(this.href)
            {
                Deprecation = this.deprecation,
                Hreflang    = this.hreflang,
                Name        = this.name,
                Profile     = this.profile,
                Templated   = this.templated,
                Title       = this.title,
                Type        = this.type
            };

            if (this.additionalProperties != null && this.additionalProperties.Count > 0)
            {
                foreach (var property in this.additionalProperties)
                {
                    linkItem.AddProperty(property.Key, property.Value);
                }
            }

            link.Items.Add(linkItem);

            return(resource);
        }