Ejemplo n.º 1
0
 public void should_serialize_specified_type_by_default()
 {
     Serialize.Csv(new List <ActualType> {
         new ActualType
         {
             Actual = "oh", Specified = "hai"
         }
     }, typeof(List <ISpecifiedType>))
     .ShouldEqual("\"Specified\"\r\n\"hai\"\r\n");
 }
Ejemplo n.º 2
0
 public void should_serialize_actual_type_when_configured()
 {
     Serialize.Csv(new List <ActualType> {
         new ActualType
         {
             Actual = "oh", Specified = "hai"
         }
     }, typeof(List <ISpecifiedType>),
                   x => x.Serialization(y => y.UseActualType()))
     .ShouldEqual("\"Actual\",\"Specified\"\r\n\"oh\",\"hai\"\r\n");
 }
Ejemplo n.º 3
0
        public void should_serialize_simple_types(Type type, object value)
        {
            var model = Activator.CreateInstance(typeof(SimpleTypeModel <>).MakeGenericType(type));

            model.SetPropertyOrFieldValue("Value", value);
            var list = model.GetType().MakeGenericListType().CreateInstance();

            list.As <IList>().Add(model);
            Serialize.Csv(list).ShouldEqual("\"Value\"\r\n" +
                                            (type.IsNumeric() || type.IsBoolean()
                ? value.ToString().ToLower() : $"\"{value}\"") + "\r\n");
        }
Ejemplo n.º 4
0
 public void should_serialize_csv_with_custom_separators()
 {
     Serialize.Csv(new List <Record>
     {
         new Record {
             Property = "oh,", Field = "*hai*"
         }
     }, x => x
                   .IncludePublicFields()
                   .WithCsvDelimiter("-")
                   .WithCsvQualifier("*")
                   .WithCsvNewLine("#"))
     .ShouldEqual("*Property*-*Field*#*oh,*-***hai***#");
 }
Ejemplo n.º 5
0
 public void should_serialize_csv()
 {
     Serialize.Csv(new List <Record>
     {
         new Record {
             Property = "oh", Field = "\"hai\""
         },
         new Record {
             Property = "fark", Field = "\"farker\""
         }
     }, x => x.IncludePublicFields()).ShouldEqual(
         "\"Property\",\"Field\"\r\n" +
         "\"oh\",\"\"\"hai\"\"\"\r\n" +
         "\"fark\",\"\"\"farker\"\"\"\r\n");
 }
Ejemplo n.º 6
0
 public void should_serialize_list_of_complex_type(Type type, object list)
 {
     Serialize.Csv(list, type).ShouldEqual((type.IsGenericEnumerable() ?
                                            "\"Property\"\r\n" : "") + "\"hai\"\r\n");
 }
Ejemplo n.º 7
0
 public void should_serialize_nested_objects_as_csv(List <NestedRecordParent> source, string result)
 {
     Serialize.Csv(source, x => x.IncludePublicFields()).ShouldEqual(result);
 }