public void ShouldSerializeWithCustomSerializerForCommonType() { var customSerializerMock = new Mock <IGraphSONSerializer>(); var customSerializerByType = new Dictionary <Type, IGraphSONSerializer> { { typeof(int), customSerializerMock.Object } }; var writer = new GraphSON2Writer(customSerializerByType); writer.WriteObject(12); customSerializerMock.Verify(m => m.Dictify(It.Is <int>(v => v == 12), It.IsAny <GraphSONWriter>())); }
public void ShouldSerializeWithCustomSerializerForNewType() { var customSerializerByType = new Dictionary <Type, IGraphSONSerializer> { { typeof(TestClass), new TestGraphSONSerializer { TestNamespace = "NS" } } }; var writer = new GraphSON2Writer(customSerializerByType); var testObj = new TestClass { Value = "test" }; var serialized = writer.WriteObject(testObj); Assert.Equal("{\"@type\":\"NS:TestClass\",\"@value\":\"test\"}", serialized); }
/// <summary> /// Initializes a new instance of the <see cref="GraphSON2MessageSerializer" /> class with custom serializers. /// </summary> /// <param name="graphSONReader">The <see cref="GraphSON2Reader"/> used to deserialize from GraphSON.</param> /// <param name="graphSONWriter">The <see cref="GraphSON2Writer"/> used to serialize to GraphSON.</param> public GraphSON2MessageSerializer(GraphSON2Reader graphSONReader = null, GraphSON2Writer graphSONWriter = null) : base(MimeType, graphSONReader ?? new GraphSON2Reader(), graphSONWriter ?? new GraphSON2Writer()) { }