Esempio n. 1
0
        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"]);
        }
Esempio n. 2
0
        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"]);
        }
Esempio n. 3
0
        public void NoMetadataShouldNotSerializeMetaAttribute()
        {
            var r = new Resource {
                Id = 1
            };
            var    ro   = new ResourceObject(r, _p);
            JToken json = ro.ToJson();

            Assert.IsNull(json["meta"]);
        }
Esempio n. 4
0
        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);
        }
Esempio n. 5
0
        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"]);
        }
Esempio n. 6
0
 public void ShouldErrorWhenLinkAndPropertyShareName()
 {
     var r = new ResourceWithConflictingRelationship
     {
         Conflict = new Resource {
             Id = 1
         },
         CoNfLiCt = 1
     };
     var    ro   = new ResourceObject(r, _p);
     JToken json = ro.ToJson();
 }
Esempio n. 7
0
 public void ShouldErrorSerializingIllegalComplexAttributeWithMeta()
 {
     var r = new ResourceWithIllegalComplexAttributes
     {
         Id       = 1,
         WithMeta = new ComplexAttributeWithMeta {
             Meta = 1
         }
     };
     var    ro   = new ResourceObject(r, _p);
     JToken json = ro.ToJson();
 }
Esempio n. 8
0
        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"]);
        }
Esempio n. 9
0
        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);
        }
Esempio n. 10
0
        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"]);
        }
Esempio n. 11
0
 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();
 }
Esempio n. 12
0
        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"]);
        }
Esempio n. 13
0
        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"]);
        }