public void ShouldSerializeAlternateType() { var r = new ResourceWithAlternateType { Id = 1 }; var ro = new ResourceObject(r, _p); JToken json = ro.ToJson(); Assert.AreEqual("Bananas", (string)json["type"]); }
public void ShouldSerializeIdWithIdAttribute() { var r = new ResourceWithoutIdWithAttribute { Value = 1 }; var ro = new ResourceObject(r, _p); JToken json = ro.ToJson(); Assert.AreEqual("1", (string)json["id"]); }
public void NoMetadataShouldNotSerializeMetaAttribute() { var r = new Resource { Id = 1 }; var ro = new ResourceObject(r, _p); JToken json = ro.ToJson(); Assert.IsNull(json["meta"]); }
public void ShouldSerializeIdAndTypeAsString() { var r = new Resource { Id = 1 }; var ro = new ResourceObject(r, _p); JToken json = ro.ToJson(); Assert.AreEqual(JTokenType.String, json["id"].Type); Assert.AreEqual(JTokenType.String, json["type"].Type); }
public void ShouldSerializeIdAndType() { var r = new Resource { Id = 1 }; var ro = new ResourceObject(r, _p); JToken json = ro.ToJson(); Assert.AreEqual("1", (string)json["id"]); Assert.AreEqual("Resources", (string)json["type"]); }
public void ShouldErrorWhenLinkAndPropertyShareName() { var r = new ResourceWithConflictingRelationship { Conflict = new Resource { Id = 1 }, CoNfLiCt = 1 }; var ro = new ResourceObject(r, _p); JToken json = ro.ToJson(); }
public void ShouldErrorSerializingIllegalComplexAttributeWithMeta() { var r = new ResourceWithIllegalComplexAttributes { Id = 1, WithMeta = new ComplexAttributeWithMeta { Meta = 1 } }; var ro = new ResourceObject(r, _p); JToken json = ro.ToJson(); }
public void ResourceObjectWithMetadaShouldSerializeMetaAttribute() { var r = new Resource { Id = 1 }; var ro = new ResourceObject(r, _p); ro.Meta.MyMeta = "foo"; JToken json = ro.ToJson(); Assert.AreEqual("foo", (string)json["meta"]["my-meta"]); }
public void ShouldSerializeResourceAttributes() { var r = new Resource { Id = 1, AttributeI = 10, AttributeS = "10" }; var ro = new ResourceObject(r, _p); JToken json = ro.ToJson(); Assert.AreEqual(10, (int)json["attribute-i"]); Assert.AreEqual(JTokenType.Integer, json["attribute-i"].Type); Assert.AreEqual("10", (string)json["attribute-s"]); Assert.AreEqual(JTokenType.String, json["attribute-s"].Type); }
public void SimpleObjectsShouldNotHaveLinks() { var r = new Resource { Id = 1 }; var ro = new ResourceObject(r, _p); var links = ro.ExtractAndRewireResourceLinks(); Assert.IsEmpty(links); Assert.IsEmpty(ro.Links); JToken json = ro.ToJson(); Assert.Null(json["links"]); }
public void ShouldErrorSerializingComplexAttributeIllegalNested() { var r = new ResourceWithIllegalComplexAttributes { Id = 1, WithNested = new ComplexAttributeWithIllegalAttribute { WithId = new ComplexAttributeWithId { Id = 1 } } }; var ro = new ResourceObject(r, _p); JToken json = ro.ToJson(); }
public void ShouldSerializeComplexAttributes() { var r = new ResourceWithComplexAttribute { Id = 1, AttributeC = new ComplexAttribute { AttributeI = 10, AttributeS = "10" } }; var ro = new ResourceObject(r, _p); JToken json = ro.ToJson(); Assert.AreEqual(JTokenType.Object, json["attribute-c"].Type); Assert.AreEqual(10, (int)json["attribute-c"]["attribute-i"]); Assert.AreEqual("10", (string)json["attribute-c"]["attribute-i"]); }
public void LinkedObjectsShouldHaveLinks() { var r = new ResourceWithRelationship { Id = 1, ToOne = new Resource { Id = 2 } }; var ro = new ResourceObject(r, _p); var links = ro.ExtractAndRewireResourceLinks(); Assert.IsNotEmpty(links); Assert.IsNotEmpty(ro.Links); JToken json = ro.ToJson(); Assert.NotNull(json["links"]); }