Exemple #1
0
        public void ValidationMultipleSuccesTest()
        {
            var cb = new CsvSerializerBuilder<User>();
            cb.AddColumn(0, x => x.Name)
                .Name("CustomName")
                .AddValidation(new CsvRegularExpressionAttribute(string.Empty))
                .AddValidation(new CsvRegularExpressionAttribute(string.Empty));

            Assert.IsNotNull(cb.ToCsvSerializer());
        }
Exemple #2
0
        public void ValidationMultipleErrorTest()
        {
            var cb = new CsvSerializerBuilder<User>();
            cb.AddColumn(0, x => x.Name)
                .Name("CustomName")
                .AddValidation(new CsvMaxLengthAttribute(1))
                .AddValidation(new CsvMaxLengthAttribute(2));

            Assert.ThrowsException<InvalidOperationException>(() => cb.ToCsvSerializer());
        }
Exemple #3
0
        public void ValidationTest()
        {
            var cb = new CsvSerializerBuilder<User>();
            cb.AddColumn(0, x => x.Name)
                .Name("CustomName")
                .AddValidation(new CsvRequiredAttribute())
                .AddValidation(new CsvMaxLengthAttribute(1));

            var cs = cb.ToCsvSerializer();

            Assert.ThrowsException<CsvValidationException>(() => cs.Deserialize("abc,2000/01/01,foo\r\n"));
        }
Exemple #4
0
        public void BuildTest()
        {
            var cb = new CsvSerializerBuilder<User>();
            cb.AddColumn(3, x => x.ValueObject)
                .Converter(new ValueObjectConverter());
            cb.AddColumn(0, x => x.Name)
                .Name("CustomName")
                .AddValidation(new CsvRequiredAttribute())
                .AddValidation(new CsvMaxLengthAttribute(10));
            cb.AddColumn(1, x => x.Birthday)
                .Format("yyyy/MM/dd");

            var cs = cb.ToCsvSerializer();
            cs.HasHeader = true;

            var user = CreateUser();

            var csv = cs.Serialize(user);
            Assert.AreEqual("CustomName,Birthday,,ValueObject\r\nabc,2000/01/01,,foo\r\n", csv);

            var users = cs.Deserialize(csv);
            CollectionAssert.AreEqual(new User[] { user }, users);
        }
Exemple #5
0
 public void ColumnNotFoundTest()
 {
     var cb = new CsvSerializerBuilder<User>();
     Assert.ThrowsException<InvalidOperationException>(() => cb.ToCsvSerializer());
 }