예제 #1
0
        public void RespectISerializableObjects()
        {
            var loggerMock = new Mock<ILogger>();

            ISerializer serializer = new JsonNetSerializer(loggerMock.Object);

            var iSerializableObj = new TestObjectAsISerializable();

            var result = serializer.Serialize(iSerializableObj);

            Assert.Equal("{\"otherKey\":\"otherValue\"}", result);
        }
예제 #2
0
        public void SerializeObjects()
        {
            var loggerMock = new Mock<ILogger>();

            ISerializer serializer = new JsonNetSerializer(loggerMock.Object);

            var simpleObject = new {String = "A string", Integer = 5};

            string result = serializer.Serialize(simpleObject);

            Assert.Equal("{\"string\":\"A string\",\"integer\":5}", result);
        }
예제 #3
0
        public void IgnoreEnumerableReferenceLoop()
        {
            var loggerMock = new Mock<ILogger>();

            ISerializer serializer = new JsonNetSerializer(loggerMock.Object);

            var loop = new TestObjectWithEnumerableReferenceLoop();

            string result = serializer.Serialize(loop);

            Assert.Equal("[]", result);
            loggerMock.Verify(l => l.Error(It.IsAny<string>(), It.IsAny<Exception>()), Times.Never());
        }
예제 #4
0
        public void IgnorePropertiesWithErrors()
        {
            var loggerMock = new Mock<ILogger>();

            ISerializer serializer = new JsonNetSerializer(loggerMock.Object);

            var badObject = new TestObjectWithException();

            string result = serializer.Serialize(badObject);

            Assert.Equal("{\"string\":\"A string\"}", result);
            //This verify is not registered due to lambda. It has been verified to work
            //loggerMock.Verify(l=>l.Error(It.IsAny<string>(), It.IsAny<NotSupportedException>()));
        }
예제 #5
0
        public void IgnorePropertiesWithErrors()
        {
            var loggerMock = new Mock<ILogger>();

            ISerializer serializer = new JsonNetSerializer(loggerMock.Object);

            var badObject = new TestObjectWithException();

            string result = serializer.Serialize(badObject);

            Assert.Equal("{\"string\":\"A string\"}", result);
            loggerMock.Verify(l => l.Error(It.IsAny<string>(),
                                           It.Is<JsonException>(ex => ex.InnerException is NotSupportedException)));
        }
예제 #6
0
        public void RespectJsonPropertyOverrides()
        {
            var loggerMock = new Mock<ILogger>();

            ISerializer serializer = new JsonNetSerializer(loggerMock.Object);

            var overrideObject = new TestObjectWithJsonAttributes();

            string result = serializer.Serialize(overrideObject);

            Assert.Equal("{\"meaningfullName\":\"A string\"}", result);
        }