public void SetupLinks(Uri queryString) { //check if baseUri contains actual information if (queryString == null || string.IsNullOrWhiteSpace(queryString.Host)) { return; } // setup link to self Links = new JsonApiLinksObject { Self = new JsonApiLink(queryString.AbsoluteUri) }; }
public void TestLinkObjectSerializationWithMeta() { JsonApiLinksObject l = new JsonApiLinksObject { Self = new JsonApiLink { Href = testUrl, Meta = meta }, First = new JsonApiLink { Href = testUrl, Meta = meta }, Last = new JsonApiLink { Href = testUrl, Meta = meta }, Next = new JsonApiLink { Href = testUrl, Meta = meta }, Prev = new JsonApiLink { Href = testUrl, Meta = meta }, Related = new JsonApiLink { Href = testUrl, Meta = meta } }; ; JObject reference = new JObject( new JProperty("self", JObject.FromObject(new JsonApiLink { Href = testUrl, Meta = meta })), new JProperty("related", JObject.FromObject(new JsonApiLink { Href = testUrl, Meta = meta })), new JProperty("prev", JObject.FromObject(new JsonApiLink { Href = testUrl, Meta = meta })), new JProperty("next", JObject.FromObject(new JsonApiLink { Href = testUrl, Meta = meta })), new JProperty("first", JObject.FromObject(new JsonApiLink { Href = testUrl, Meta = meta })), new JProperty("last", JObject.FromObject(new JsonApiLink { Href = testUrl, Meta = meta })) ); var result = JsonConvert.SerializeObject(l, Formatting.Indented); var referenceResult = JsonConvert.SerializeObject(reference, Formatting.Indented); Assert.IsTrue(string.Equals(result, referenceResult)); }
public void TestLinkObjectSerializationEmtyLinks() { JsonApiLinksObject l = new JsonApiLinksObject { Self = new JsonApiLink { Href = testUrl }, }; JObject reference = new JObject( new JProperty("self", testUrl) ); var result = JsonConvert.SerializeObject(l, Formatting.Indented); var referenceResult = JsonConvert.SerializeObject(reference, Formatting.Indented); Assert.IsTrue(string.Equals(result, referenceResult)); }
public void TestLinkObjectDeserializationEmtyLinks() { var link1 = new JsonApiLink { Href = testUrl, Meta = meta }; var link2 = new JsonApiLink { Href = testUrl }; JsonApiLinksObject l = new JsonApiLinksObject { Self = link1, Related = link2 }; var json = JsonConvert.SerializeObject(l, Formatting.Indented); var result = JsonConvert.DeserializeObject <JsonApiLinksObject>(json); Assert.IsTrue(string.Equals(result.Self.Href, link1.Href)); Assert.IsTrue(string.Equals(result.Related.Href, link2.Href)); }