Ejemplo n.º 1
0
        public void IgnoresNullsAndDoesNotIgnoreDefaultValues()
        {
            var sut = new JsonSerializationBuilder()
                      .UsePrettyFormat()
                      .Build();

            var r     = new Response <BlogInfo>(HttpStatusCode.BadRequest, "something bad happend");
            var bytes = sut.Serialize(r);
            var str   = Encoding.UTF8.GetString(bytes);

            Assert.Contains("isSuccess", str);
            Assert.DoesNotContain("exception", str);
        }
Ejemplo n.º 2
0
        public void Shortenning()
        {
            var sut = new JsonSerializationBuilder()
                      .UseShortTypeNames(typeof(BlogInfo), typeof(BlogPost))
                      .UsePrettyFormat()
                      .Build();

            var data  = BlogInfo.Create();
            var bytes = sut.Serialize(data);
            var s     = Encoding.UTF8.GetString(bytes);

            Assert.Contains("BP.", s);

            var data2 = sut.Deserialize(bytes);

            Assert.True(data2 is BlogInfo);
        }
Ejemplo n.º 3
0
        public void Shortenning2()
        {
            var sut = new JsonSerializationBuilder()
                      .UseShortTypeNames(typeof(BlogInfo), typeof(BlogPost), typeof(Dictionary <string, object>))
                      .UsePrettyFormat()
                      .Build();

            var data = new Dictionary <string, object>
            {
                { "AAA", BlogInfo.Create() },
                { "BBB", 125.95 },
                { "CCC", new[] { "fff", "eee" } },
                { "DDD", BlogPost.Create() },
            };
            var bytes = sut.Serialize(data);
            var s     = Encoding.UTF8.GetString(bytes);

            var data2 = sut.Deserialize(bytes);
        }