Esempio n. 1
0
        public void SerializeReadonlyObject()
        {
            Configuration.Instance
            .UseAutofacContainer()
            .UseJsonNet();

            ObjectProviderFactory.Instance
            .Build();
            //var ex = new Exception("test");
            //var json = ex.ToJson();
            //var ex2 = json.ToObject<Exception>();
            //Assert.Equal(ex.Message, ex2.Message);
            var a     = new AClass("ddd", "name");
            var aJson = a.ToJson();
            var b     = aJson.ToJsonObject <AClass>();

            Assert.NotNull(aJson);
            Assert.NotNull(b.Name);
            Assert.Equal(a.CreatedTime, b.CreatedTime);


            var de    = new DomainException(1, "test");
            var json2 = de.ToJson();
            var de2   = json2.ToJsonObject <DomainException>();

            Assert.Equal(de.Message, de2.Message);
            Assert.Equal(de.ErrorCode, de2.ErrorCode);

            var e    = new AException("test");
            var json = e.ToJson();
            var e2   = json.ToJsonObject <AException>();

            Assert.Equal(e.Message, e2.Message);


            de    = new DomainException("2", "test");
            json2 = de.ToJson();
            de2   = json2.ToJsonObject <DomainException>();
            Assert.Equal(de.Message, de2.Message);
            Assert.Equal(de.ErrorCode, de2.ErrorCode);

            de    = new DomainException(null, "test");
            json2 = de.ToJson();
            de2   = json2.ToJsonObject <DomainException>();
            Assert.Equal(de.Message, de2.Message);
            Assert.Equal(de.ErrorCode, de2.ErrorCode);
        }