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); }
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); }
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()); }
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>())); }
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))); }
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); }