예제 #1
0
        public void MergeAsStringTest()
        {
            var payload = new PayloadStub
            {
                Prop1 = 1,
                Prop2 = "value",
                Prop3 = false,
                Prop4 = new List <PayloadStub>()
                {
                    new PayloadStub {
                        Prop2 = "nested"
                    }
                }
            };
            var links = new List <Link>()
            {
                new Link {
                    Href = "a/b/c", Rel = "first", Method = "Get"
                },
                new Link {
                    Href = "another/link", Rel = "other", Method = "Post"
                }
            };
            var serializer           = new JsonOutputSerializer(new Settings {
            });
            var str                  = serializer.MergeAsString(payload, links);
            Packet <PayloadStub> obj = JsonConvert.DeserializeObject <Packet <PayloadStub> >(str);

            Assert.IsTrue(str.Contains("payload"));
            Assert.IsTrue(str.Contains("links"));
            Assert.AreEqual(payload.Prop4[0].Prop2, obj.Payload.Prop4[0].Prop2);
            Assert.AreEqual(links[1].Href, obj.Links[1].Href);
        }
예제 #2
0
        public void MergeTest()
        {
            var payload = new PayloadStub
            {
                Prop1 = 1,
                Prop2 = "value",
                Prop3 = false,
                Prop4 = new List <PayloadStub>()
                {
                    new PayloadStub {
                        Prop2 = "nested"
                    }
                }
            };
            var links = new List <Link>()
            {
                new Link {
                    Href = "a/b/c", Rel = "first", Method = "Get"
                },
                new Link {
                    Href = "another/link", Rel = "other", Method = "Post"
                }
            };
            var serializer = new JsonOutputSerializer(new Settings {
            });
            var obj        = serializer.Merge(payload, links);

            Assert.AreEqual(payload, obj.Payload);
            Assert.AreEqual(links.Count, obj.Links.Count());
            Assert.AreEqual(links[0].Href, obj.Links.First().Href);
            Assert.AreEqual(links[1].Href, obj.Links.Last().Href);
        }
예제 #3
0
        public void SerializePayloadObjectTest()
        {
            var payload = new PayloadStub
            {
                Prop1 = 1,
                Prop2 = "value",
                Prop3 = false,
                Prop4 = new List <PayloadStub>()
                {
                    new PayloadStub {
                        Prop2 = "nested"
                    }
                }
            };
            var serializer = new JsonOutputSerializer(new Settings {
            });
            var str        = serializer.SerializePayload <PayloadStub>(payload);
            var obj        = JsonConvert.DeserializeObject <PayloadStub>(str);

            Assert.AreEqual(payload.Prop1, obj.Prop1);
            Assert.AreEqual(payload.Prop2, obj.Prop2);
            Assert.AreEqual(payload.Prop3, obj.Prop3);
            Assert.AreEqual(payload.Prop4.Count, obj.Prop4.Count);
            Assert.AreEqual(payload.Prop4[0].Prop2, obj.Prop4[0].Prop2);
        }