コード例 #1
0
        public void GivenEventObjectSerializeObjectShouldReturnString()
        {
            //Arrange

            var    obj  = new ObjectToDeserializeTo(1, "Dupont");
            string json = JsonConvert.SerializeObject(obj, Formatting.Indented,
                                                      new JsonSerializerSettings
            {
                ReferenceLoopHandling = ReferenceLoopHandling.Ignore
            });

            //Act
            IJsonProvider sut    = new JsonProvider();
            var           result = sut.SerializeObject(obj);

            //Assert

            Assert.Equal(json, result);
        }
コード例 #2
0
        public void GivenStringDeserializeObjectShouldReturnObject()
        {
            //Arrange

            var json = @"
                {
                    'Id' :1,
                    'Name':'Dupont'
                }";
            var obj  = new ObjectToDeserializeTo(1, "Dupont");
            var type = obj.GetType().AssemblyQualifiedName;

            //Act
            IJsonProvider sut    = new JsonProvider();
            var           result = sut.DeserializeObject <ObjectToDeserializeTo>(json, type);

            //Assert

            Assert.Equal(obj.Id, result.Id);
            Assert.Equal(obj.Name, result.Name);
        }