public void CanSerializeSimpleLinks(Type documentType) { var document = new MockJsonApiDocument { Links = new JsonApiDocumentLinks { Self = "http://example.com/articles", Next = "http://example.com/articles?page[offset]=2", Prev = "http://example.com/articles?page[offset]=1", Last = "http://example.com/articles?page[offset]=10", First = "http://example.com/articles?page[offset]=0", Related = "http://example.com/related" } }; var json = document.SerializeDocument(documentType); Assert.Equal(@" { 'links': { 'self': 'http://example.com/articles', 'next': 'http://example.com/articles?page[offset]=2', 'prev': 'http://example.com/articles?page[offset]=1', 'last': 'http://example.com/articles?page[offset]=10', 'first': 'http://example.com/articles?page[offset]=0', 'related': 'http://example.com/related' }, 'data': null }".Format(), json, JsonStringEqualityComparer.Default); }
public void CanSerializeJsonApiWithVersionAndMeta(Type documentType) { var document = new MockJsonApiDocument { Data = null, JsonApi = new JsonApiObject { Version = "1.1", Meta = new JsonApiMeta { { "count", 5.ToElement() } } } }; var json = document.SerializeDocument(documentType); Assert.Equal(@" { 'data': null, 'jsonapi': { 'version': '1.1', 'meta': { 'count': 5 } } }".Format(), json, JsonStringEqualityComparer.Default); }
public void CanSerializeMetaWithData(Type documentType) { var document = new MockJsonApiDocument { Data = null, Meta = new JsonApiMeta { { "name", JsonApiMeta.Value("Bloggs") }, { "count", JsonApiMeta.Value(4) }, { "authors", JsonApiMeta.Value(new[] { "Tom", "Dick", "Harry" }) }, { "details", JsonApiMeta.Value(new { title = "book", active = true, count = 2 }) } } }; var json = document.SerializeDocument(documentType); Assert.Equal(@" { 'meta': { 'name': 'Bloggs', 'count': 4, 'authors': [ 'Tom', 'Dick', 'Harry' ], 'details': { 'title': 'book', 'active': true, 'count': 2 } } }".Format(), json, JsonStringEqualityComparer.Default); }
public void CanSerializeEmptyErrorsAsDocument(Type documentType) { var document = new MockJsonApiDocument { Errors = Array.Empty <JsonApiError>() }; var json = document.SerializeDocument(documentType); Assert.Equal(@" { 'errors': [] }".Format(), json, JsonStringEqualityComparer.Default); }
public void CanSerializeComplexLinks(Type documentType) { var document = new MockJsonApiDocument { Links = new JsonApiDocumentLinks { Self = new JsonApiLink { Href = "http://example.com/articles", Meta = new JsonApiMeta { { "count", 10.ToElement() }, { "title", "articles".ToElement() } } }, Next = new JsonApiLink { Href = "http://example.com/articles?page[offset]=2", Meta = new JsonApiMeta { { "count", 4.ToElement() }, { "title", "blogs".ToElement() } } } } }; var json = document.SerializeDocument(documentType); Assert.Equal(@" { 'links': { 'self': { 'href': 'http://example.com/articles', 'meta': { 'count': 10, 'title': 'articles' } }, 'next': { 'href': 'http://example.com/articles?page[offset]=2', 'meta': { 'count': 4, 'title': 'blogs' } } }, 'data': null }".Format(), json, JsonStringEqualityComparer.Default); }
public void SerializesWithDefaultJsonApiVersion(Type documentType) { var document = new MockJsonApiDocument { Data = null, JsonApi = new JsonApiObject() }; var json = document.SerializeDocument(documentType); Assert.Equal(@" { 'data': null, 'jsonapi': { 'version': '1.0' } }".Format(), json, JsonStringEqualityComparer.Default); }
public void CanSerializeMissingErrorsAsDocument(Type documentType) { var document = new MockJsonApiDocument { Links = new JsonApiDocumentLinks { Self = "http://localhost" } }; var json = document.SerializeDocument(documentType); Assert.Equal(@" { 'data': null, 'links': { 'self': 'http://localhost' } }".Format(), json, JsonStringEqualityComparer.Default); }
public void CanSerializeJsonApiObjectWithNoMembers(Type documentType) { var document = new MockJsonApiDocument { Data = null, JsonApi = new JsonApiObject { Version = null } }; var json = document.SerializeDocument(documentType); Assert.Equal(@" { 'data': null, 'jsonapi': { } }".Format(), json, JsonStringEqualityComparer.Default); }
public void CanSerializeSimpleNonStandardLink(Type documentType) { var document = new MockJsonApiDocument { Links = new JsonApiDocumentLinks { { "articles", "http://example.com/articles" }, { "blogs", "http://example.com/blogs" } } }; var json = document.SerializeDocument(documentType); Assert.Equal(@" { 'links': { 'articles': 'http://example.com/articles', 'blogs': 'http://example.com/blogs' }, 'data': null }".Format(), json, JsonStringEqualityComparer.Default); }