Exemplo n.º 1
0
        public void ToJson2CallsSerializeToStringWithName()
        {
            ResetSeralizers();

            var serializerMocks = GetSerializerMocks();

            Serializer.SetJsonSerializers(serializerMocks.Values.Select(v => v.Object));

            var toSerialize = new Type1ForSerializer();
            var json        = toSerialize.ToJson(typeof(Type2ForSerializer), "notdefault");

            serializerMocks["default"].Verify(m => m.SerializeToString(It.IsAny <object>(), typeof(Type1ForSerializer)), Times.Never);
            serializerMocks["default"].Verify(m => m.SerializeToString(It.IsAny <object>(), typeof(Type2ForSerializer)), Times.Never);
            serializerMocks["notdefault"].Verify(m => m.SerializeToString(It.IsAny <object>(), typeof(Type1ForSerializer)), Times.Never);
            serializerMocks["notdefault"].Verify(m => m.SerializeToString(It.IsAny <object>(), typeof(Type2ForSerializer)), Times.Once);
        }
Exemplo n.º 2
0
        public void ToJson4CallsSerializeToStreamWithName()
        {
            ResetSeralizers();

            var serializerMocks = GetSerializerMocks();

            Serializer.SetJsonSerializers(serializerMocks.Values.Select(v => v.Object));

            using var stream = new MemoryStream();
            var toSerialize = new Type1ForSerializer();

            toSerialize.ToJson(typeof(Type2ForSerializer), stream, "notdefault");

            serializerMocks["default"].Verify(m => m.SerializeToStream(stream, It.IsAny <object>(), typeof(Type1ForSerializer)), Times.Never);
            serializerMocks["default"].Verify(m => m.SerializeToStream(stream, It.IsAny <object>(), typeof(Type2ForSerializer)), Times.Never);
            serializerMocks["notdefault"].Verify(m => m.SerializeToStream(stream, It.IsAny <object>(), typeof(Type1ForSerializer)), Times.Never);
            serializerMocks["notdefault"].Verify(m => m.SerializeToStream(stream, It.IsAny <object>(), typeof(Type2ForSerializer)), Times.Once);
        }