public void should_fail_to_deserialize_null_value() { var results = Deserialize.Csv <List <SimpleTypeModel <int?> > >("\"Value\",\"Fark\"\r\n,\r\n"); results.Count.ShouldEqual(1); results.First().Value.ShouldBeNull(); }
public void should_deserialize_csv_with_custom_seperators() { var results = Deserialize.Csv <List <Record> >( "\"Property\"-\"Field\"\r\n\"oh\"-\"\"\"hai\"\"\"\r\n", x => x.IncludePublicFields().WithCsvDelimiter("-")); results.Count.ShouldEqual(1); results[0].Property.ShouldEqual("oh"); results[0].Field.ShouldEqual("\"hai\""); }
public void should_deserialize_array_of_complex_type(Type type) { var Csv = "\"Property\"\r\n\"hai\""; var result = Deserialize.Csv(Csv, type).As <IList <ComplexType> >(); result.ShouldNotBeNull(); result.Count.ShouldEqual(1); result[0].Property.ShouldEqual("hai"); }
public void should_fail_to_deserialize_non_generic_arrays_of_complex_type(Type type) { var exception = Assert.Throws <MappingException>(() => Deserialize.Csv("\"Property\"\r\n\"hai\"", type)); exception.Message.ShouldEqual(("Error deserializing character separated row '1:' to " + "'{0}': Non generic {1} '{0}' is not supported for deserialization. Only " + "generic lists and generic enumerable interfaces can be deserialized.") .ToFormat(type.GetFriendlyTypeFullName(), type.IsList() ? "list" : "enumerable")); exception.InnerException.ShouldBeType <TypeNotSupportedException>(); }
public void should_deserialize_simple_types(Type type, object value, object defaultValue) { var Csv = "\"Value\"\r\n{0}\r\n".ToFormat(type.IsNumeric() || type.IsBoolean() ? value.ToString().ToLower() : "\"" + value + "\""); var listType = typeof(SimpleTypeModel <>).MakeGenericType(type).MakeGenericListType(); var result = Deserialize.Csv(Csv, listType).As <IList>(); result.ShouldNotBeNull(); result.ShouldBeType(listType); result.Count.ShouldEqual(1); result[0].GetPropertyOrFieldValue("Value").ShouldEqual(value); }
public void should_fail_to_deserialize_generic_enumerable_impls_of_complex_type() { var exception = Assert.Throws <MappingException>(() => Deserialize.Csv <GenericEnumerableImpl <ComplexType> >( "\"Property\"\r\n\"hai\"")); exception.Message.ShouldEqual("Error deserializing character separated row '1:' to " + "'Tests.Collections.Implementations.GenericEnumerableImpl<Tests.Deserializer.CharacterSeparated.ArrayTests.ComplexType>': " + "Enumerable 'Tests.Collections.Implementations.GenericEnumerableImpl<Tests.Deserializer.CharacterSeparated.ArrayTests.ComplexType>' " + "is not supported for deserialization. Only generic lists and generic enumerable interfaces can be deserialized."); exception.InnerException.ShouldBeType <TypeNotSupportedException>(); }
public void should_not_deserialize_empty_values_when_configured() { var results = Deserialize.Csv <List <NestedRecordParent> >( "\"Property\",\"ChildProperty\",\"ChildField\",\"Field\"\r\n" + "\"oh,\",,,\"\"\"hai\"\"\"\r\n", x => x.IncludePublicFields().Deserialization(d => d.IgnoreEmptyCsvValues())); results.Count.ShouldEqual(1); results[0].Property.ShouldEqual("oh,"); results[0].Field.ShouldEqual("\"hai\""); results[0].Child.ShouldBeNull(); }
public void should_deserialize_csv() { var results = Deserialize.Csv <List <Record> >( "\"Property\",\"Field\"\r\n" + "\"oh,\",\"\"\"hai\"\"\"\r\n" + "\"fark,\",\"\"\"farker\"\"\"\r\n", x => x.IncludePublicFields()); results.Count.ShouldEqual(2); results[0].Property.ShouldEqual("oh,"); results[0].Field.ShouldEqual("\"hai\""); results[1].Property.ShouldEqual("fark,"); results[1].Field.ShouldEqual("\"farker\""); }
public void should_deserialize_nested_objects_as_csv() { var results = Deserialize.Csv <List <NestedRecordParent> >( "\"Property\",\"ChildProperty\",\"ChildField\",\"Field\"\r\n" + "\"oh,\",\"fark,\",\"\"\"farker\"\"\",\"\"\"hai\"\"\"\r\n", x => x.IncludePublicFields()); results.Count.ShouldEqual(1); results[0].Property.ShouldEqual("oh,"); results[0].Field.ShouldEqual("\"hai\""); var child = results[0].Child; child.ShouldNotBeNull(); child.Property.ShouldEqual("fark,"); child.Field.ShouldEqual("\"farker\""); }