Ejemplo n.º 1
0
 static SerializerFactory()
 {
     _autoSerializer             = new AutoSerializer();
     _booleanSerializer          = new BooleanSerializer();
     _enumNameSerializer         = new EnumNameSerializer();
     _enumValueSerializer        = new EnumValueSerializer();
     _jsonSerializableSerializer = new JsonSerializableSerializer();
     _numericSerializer          = new NumericSerializer();
     _registeredObjectSerializer = new RegisteredObjectSerializer();
     _stringSerializer           = new StringSerializer();
     _schemaSerializer           = new SchemaSerializer();
     _uriSerializer = new UriSerializer();
     _library       = new Dictionary <Type, ISerializer>
     {
         { typeof(sbyte), _numericSerializer },
         { typeof(byte), _numericSerializer },
         { typeof(char), _numericSerializer },
         { typeof(short), _numericSerializer },
         { typeof(ushort), _numericSerializer },
         { typeof(int), _numericSerializer },
         { typeof(uint), _numericSerializer },
         { typeof(long), _numericSerializer },
         { typeof(ulong), _numericSerializer },
         { typeof(float), _numericSerializer },
         { typeof(double), _numericSerializer },
         { typeof(decimal), _numericSerializer },
         { typeof(bool), _booleanSerializer },
         { typeof(string), _stringSerializer },
         { typeof(Uri), _uriSerializer }
     };
 }
 public void should_deserialize_a_defined_value()
 {
     var input = Values.One;
     var serializer = new EnumValueSerializer<Values>();
     var output = serializer.Deserialize((int)input);
     Assert.That(output, Is.EqualTo(output));
 }
 public void should_deserialize_a_combined_value_if_it_is_a_flags_enum()
 {
     var input = Values.One | Values.Two;
     var serializer = new EnumValueSerializer<Values>();
     var output = serializer.Deserialize((int)input);
     Assert.That(output, Is.EqualTo(output));
 }
 public void should_throw_if_input_data_is_invalid()
 {
     var serializer = new EnumValueSerializer<Values>();
     Assert.That(() => serializer.Deserialize(4), Throws.TypeOf<InvalidCastException>());
 }
 public void should_return_null_if_data_is_null()
 {
     var serializer = new EnumValueSerializer<Values>();
     var value = serializer.Deserialize(null);
     Assert.That(value, Is.Null);
 }