Exemple #1
0
        public void CsvFileReaderWriter_ReadTest()
        {
            var csvText = "1;2;3\n\"1;2\";\"1;2\n";
            var reader  = new StringReader(csvText);
            var target  = new CsvFileReaderWriter(
                '\n',
                ';',
                '"',
                (i, j, txt) => txt.Trim(new[] { '"' }));
            var tabularItem = new TabularListsItem();

            target.Read(tabularItem, reader);

            // Número de linhas
            Assert.AreEqual(2, tabularItem.Count);

            // Primeira linha
            var row = tabularItem[0];

            Assert.AreEqual(3, row.Count);
            Assert.AreEqual("1", row[0].GetCellValue <string>());
            Assert.AreEqual("2", row[1].GetCellValue <string>());
            Assert.AreEqual("3", row[2].GetCellValue <string>());

            // Segunda linha
            row = tabularItem[1];
            Assert.AreEqual(2, row.Count);
            Assert.AreEqual("1;2", row[0].GetCellValue <string>());
            Assert.AreEqual("1;2\n", row[1].GetCellValue <string>());

            // Aplicação de validações sem validar dados existentes.
            var validation = new FuncDrivenColumnValudation <object>();

            validation.RegisterValidator(
                0,
                v => { if (v is int)
                       {
                           return(true);
                       }
                       else
                       {
                           return(false);
                       } });
            tabularItem.AddValidation(validation, false);

            // Aplicação de validações com dados existentes
            validation = new FuncDrivenColumnValudation <object>();
            validation.RegisterValidator(
                0,
                v => { return(v is string); });
            tabularItem.AddValidation(validation, true);
        }
Exemple #2
0
        public void TabularItem_ValidationPassTest()
        {
            var csvText       = "1;2\n3;4\n5;6";
            var reader        = new StringReader(csvText);
            var csvFileReader = new CsvFileReaderWriter(
                '\n',
                ';',
                '"',
                (i, j, txt) => int.Parse(txt.Trim(new[] { '"' })));
            var tabularItem               = new TabularListsItem();
            var dataValidation            = new FuncDrivenColumnValudation <object>();
            Func <object, bool> validator = o => o is int;

            dataValidation.RegisterValidator(0, validator);
            dataValidation.RegisterValidator(1, validator);
            csvFileReader.Read(tabularItem, reader);
        }
Exemple #3
0
        public void TabularItem_ValidationChangeCellValueFailTest()
        {
            var csvText       = "1;2\n3;4\n5;6";
            var reader        = new StringReader(csvText);
            var csvFileReader = new CsvFileReaderWriter(
                '\n',
                ';',
                '"',
                (i, j, txt) => int.Parse(txt.Trim(new[] { '"' })));
            var tabularItem = new TabularListsItem();

            csvFileReader.Read(tabularItem, reader);
            Func <object, bool> validator = o => o is int;
            var dataValidation            = new FuncDrivenColumnValudation <object>();

            dataValidation.RegisterValidator(0, validator);
            dataValidation.RegisterValidator(1, validator);
            tabularItem.AddValidation(dataValidation, false);

            // Tenta alterar a célula para um valor não inteiro
            tabularItem[0][0].SetCellValue <string>("1");
        }