Exemple #1
0
        public void TestLogRecord_FullFields_2()
        {
            FieldMapperReading <LogRecord> fm = new FieldMapperReading <LogRecord>(_fileDescriptionNamesUs, null, false);

            Assert.IsNotNull(fm);
            Assert.IsNotNull(fm.FieldIndexInfo);
            Assert.IsNotNull(fm.NameToInfo);
            Assert.AreEqual(fm.NameToInfo.Count, 27);
            Assert.IsNotNull(fm.NameToInfo["PCI"]);
            Assert.AreEqual(fm.NameToInfo["PCI"].HasColumnAttribute, true);
            List <int> charLengths = fm.GetCharLengths();

            Assert.IsNull(charLengths);

            FileDataAccess dataAccess = new FileDataAccess(_testInput.GetStreamReader(), _fileDescriptionNamesUs);

            Assert.IsNotNull(dataAccess);
            RowReader <LogRecord> reader = dataAccess.ReadDataPreparation <LogRecord>(null);

            Assert.IsNotNull(reader);
            dataAccess.Row = new DataRow();

            List <LogRecord> records = dataAccess.ReadFieldDataRows(reader, null, fm, null).ToList();

            Assert.IsNotNull(records);
            Assert.AreEqual(records.Count, 1);
            Assert.AreEqual(records[0].Id, 0);
            Assert.AreEqual(records[0].Time.Millisecond, 359);
            Assert.AreEqual(records[0].Sinr, 10.1);
            Assert.AreEqual(records[0].UlMcs, 17);
            Assert.AreEqual(records[0].DlThroughput, 10749096);
        }
        public void TestInitialize()
        {
            _description = new CsvFileDescription
            {
                SeparatorChar           = ',',
                FirstLineHasColumnNames = true,
                IgnoreUnknownColumns    = true,
            };
            _input =
                @"Id,Name,Last Name,Age,City
1,John,Doe,15,Washington";

            byte[] stringAsByteArray = Encoding.UTF8.GetBytes(_input);
            Stream stream            = new MemoryStream(stringAsByteArray);

            _sr         = new StreamReader(stream, Encoding.UTF8);
            _dataAccess = new FileDataAccess(_sr, _description);

            _cs = new CsvStream(_sr, null, _description.SeparatorChar,
                                _description.IgnoreTrailingSeparatorChar);
            _row    = new DataRow();
            _fm     = new FieldMapperReading <Person>(_description, null, false);
            _ae     = new AggregatedException(typeof(Person).ToString(), null, _description.MaximumNbrExceptions);
            _reader = new RowReader <Person>(_description, _ae);
        }
Exemple #3
0
        public IEnumerable <T> ReadFieldDataRows <T>(RowReader <T> reader, string fileName,
                                                     FieldMapperReading <T> fm, List <int> charLengths) where T : class, new()
        {
            var firstRow = true;

            try
            {
                while (Cs.ReadRow(Row, charLengths))
                {
                    if ((Row.Count == 1) && ((Row[0].Value == null) || (string.IsNullOrEmpty(Row[0].Value.Trim()))))
                    {
                        continue;
                    }

                    var readingResult = reader.ReadingOneFieldRow(fm, Row, firstRow);

                    if (readingResult)
                    {
                        yield return(reader.Obj);
                    }
                    firstRow = false;
                }
            }
            finally
            {
                if (!string.IsNullOrEmpty(fileName))
                {
                    _stream.Close();
                }

                Ae.ThrowIfExceptionsStored();
            }
        }
Exemple #4
0
        public IEnumerable <T> ReadFieldData <T>(RowReader <T> reader, string fileName) where T : class, new()
        {
            var fm          = new FieldMapperReading <T>(FileDescription, fileName, false);
            var charLengths = fm.GetCharLengths();

            return(ReadFieldDataRows(reader, fileName, fm, charLengths));
        }
        public void FileWithUnknownColumns_ShouldDiscardColumns_BasicParameters2()
        {
            FieldMapperReading<Person> fm = new FieldMapperReading<Person>(_description, null, false);
            List<int> charLengths = fm.GetCharLengths();
            Assert.IsNull(charLengths);

            Assert.IsNotNull(_dataAccess.Row);
            Assert.AreEqual(_dataAccess.Row.Count, 0);
        }
        public void FileWithUnknownColumns_ShouldDiscardColumns_BasicParameters2()
        {
            FieldMapperReading <Person> fm = new FieldMapperReading <Person>(_description, null, false);
            List <int> charLengths         = fm.GetCharLengths();

            Assert.IsNull(charLengths);

            Assert.IsNotNull(_dataAccess.Row);
            Assert.AreEqual(_dataAccess.Row.Count, 0);
        }
Exemple #7
0
 public bool ReadingOneFieldRow(FieldMapperReading <T> fm, IDataRow row, bool firstRow)
 {
     if (firstRow && _description.FirstLineHasColumnNames)
     {
         fm.ReadNames(row);
         return(false);
     }
     Obj = fm.ReadObject(row, _ae);
     return(true);
 }
        public void GoodFileNoSeparatorCharUSEnglish()
        {
            // Arrange

            CsvFileDescription fileDescription_namesUs = new CsvFileDescription
            {
                NoSeparatorChar = true,
                UseOutputFormatForParsingCsvValue = false,
                FirstLineHasColumnNames = false,
                EnforceCsvColumnAttribute = true, // default is false
                FileCultureName = "en-US" // default is the current culture
            };

            const string testInput = @"AAAAAAAA34.18405/23/08
            BBBBBBBB10.31105/12/12
            CCCCCCCC12.00012/23/08";

            var expected = new[] {
                new ProductDataCharLength
                {
                    Name = "AAAAAAAA", Weight = 34.184, StartDate = new DateTime(2008, 5, 23),
                },
                new ProductDataCharLength {
                    Name = "BBBBBBBB", Weight = 10.311, StartDate = new DateTime(2012, 5, 12),
                },
                new ProductDataCharLength {
                    Name = "CCCCCCCC", Weight = 12.000, StartDate = new DateTime(2008, 12, 23),
                }
            };

            // Act and Assert
            FileDataAccess dataAccess = new FileDataAccess(testInput.GetStreamReader(), fileDescription_namesUs);
            RowReader<ProductDataCharLength> reader = dataAccess.ReadDataPreparation<ProductDataCharLength>(null);
            dataAccess.Row = new DataRow();
            FieldMapperReading<ProductDataCharLength> fm = new FieldMapperReading<ProductDataCharLength>(
                fileDescription_namesUs, null, false);
            List<int> charLengths = fm.GetCharLengths();
            Assert.AreEqual(charLengths.Count, 3);
            bool firstRow = true;
            List<ProductDataCharLength> actual=new List<ProductDataCharLength>();
            while (dataAccess.Cs.ReadRow(dataAccess.Row, charLengths))
            {
                if ((dataAccess.Row.Count == 1) && ((dataAccess.Row[0].Value == null)
                    || (string.IsNullOrEmpty(dataAccess.Row[0].Value.Trim()))))
                {
                    continue;
                }

                bool readingResult = reader.ReadingOneFieldRow(fm, dataAccess.Row, firstRow);

                if (readingResult) { actual.Add(reader.Obj); }
                firstRow = false;
            }
            AssertCollectionsEqual(actual, expected);
        }
        public void FileWithUnknownColumns_ShouldDiscardColumns_ReadFieldData()
        {
            FieldMapperReading<Person> fm = new FieldMapperReading<Person>(_description, null, false);
            List<int> charLengths = fm.GetCharLengths();

            List<Person> actual
                = _dataAccess.ReadFieldDataRows(_reader, null, fm, charLengths).ToList();

            Assert.AreEqual(actual.Count, 2);
            Assert.AreEqual(actual[0].Age, 15);
            Assert.AreEqual(actual[1].Name, "Jane");
        }
        public void FileWithUnknownColumns_ShouldDiscardColumns_ReadFieldData()
        {
            FieldMapperReading <Person> fm = new FieldMapperReading <Person>(_description, null, false);
            List <int> charLengths         = fm.GetCharLengths();

            List <Person> actual
                = _dataAccess.ReadFieldDataRows(_reader, null, fm, charLengths).ToList();

            Assert.AreEqual(actual.Count, 2);
            Assert.AreEqual(actual[0].Age, 15);
            Assert.AreEqual(actual[1].Name, "Jane");
        }
Exemple #11
0
        public void TestLogRecord_FullFields()
        {
            FieldMapperReading <LogRecord> fm = new FieldMapperReading <LogRecord>(_fileDescriptionNamesUs, null, false);

            Assert.IsNotNull(fm);
            Assert.IsNotNull(fm.FieldIndexInfo);
            Assert.IsNotNull(fm.NameToInfo);
            Assert.AreEqual(fm.NameToInfo.Count, 27);
            Assert.IsNotNull(fm.NameToInfo["PCI"]);
            Assert.AreEqual(fm.NameToInfo["PCI"].HasColumnAttribute, true);
            List <int> charLengths = fm.GetCharLengths();

            Assert.IsNull(charLengths);

            FileDataAccess dataAccess = new FileDataAccess(_testInput.GetStreamReader(), _fileDescriptionNamesUs);

            Assert.IsNotNull(dataAccess);
            RowReader <LogRecord> reader = dataAccess.ReadDataPreparation <LogRecord>(null);

            Assert.IsNotNull(reader);

            Assert.IsNotNull(dataAccess.Cs);
            dataAccess.Row = new DataRow();
            Assert.IsTrue(dataAccess.Cs.ReadRow(dataAccess.Row));

            bool readingResult = reader.ReadingOneFieldRow(fm, dataAccess.Row, true);

            Assert.IsFalse(readingResult);

            Assert.IsTrue(dataAccess.Cs.ReadRow(dataAccess.Row));
            Assert.AreEqual(dataAccess.Row[0].Value, "0");
            Assert.AreEqual(dataAccess.Row[1].Value, "13:58:08:359");
            Assert.AreEqual(dataAccess.Row.Count, 18, "row count");
            Assert.AreEqual(fm.FieldIndexInfo.IndexToInfo.Length, 27, "index to info");

            Assert.AreEqual(fm.FieldIndexInfo.GetMaxRowCount(18), 18);

            TypeFieldInfo tfi = fm.FieldIndexInfo.QueryTypeFieldInfo(true, 1);

            Assert.IsNotNull(tfi);
            Assert.AreEqual(tfi.OutputFormat, "HH:mm:ss.fff");

            string value = dataAccess.Row[1].Value;

            Assert.AreEqual(value, "13:58:08:359");
        }
Exemple #12
0
        public void TestLogRecord_FullFields()
        {
            FieldMapperReading<LogRecord> fm = new FieldMapperReading<LogRecord>(_fileDescriptionNamesUs, null, false);
            Assert.IsNotNull(fm);
            Assert.IsNotNull(fm.FieldIndexInfo);
            Assert.IsNotNull(fm.NameToInfo);
            Assert.AreEqual(fm.NameToInfo.Count, 27);
            Assert.IsNotNull(fm.NameToInfo["PCI"]);
            Assert.AreEqual(fm.NameToInfo["PCI"].HasColumnAttribute, true);
            List<int> charLengths = fm.GetCharLengths();
            Assert.IsNull(charLengths);

            FileDataAccess dataAccess = new FileDataAccess(_testInput.GetStreamReader(), _fileDescriptionNamesUs);
            Assert.IsNotNull(dataAccess);
            RowReader<LogRecord> reader = dataAccess.ReadDataPreparation<LogRecord>(null);
            Assert.IsNotNull(reader);

            Assert.IsNotNull(dataAccess.Cs);
            dataAccess.Row = new DataRow();
            Assert.IsTrue(dataAccess.Cs.ReadRow(dataAccess.Row));

            bool readingResult = reader.ReadingOneFieldRow(fm, dataAccess.Row, true);
            Assert.IsFalse(readingResult);

            Assert.IsTrue(dataAccess.Cs.ReadRow(dataAccess.Row));
            Assert.AreEqual(dataAccess.Row[0].Value, "0");
            Assert.AreEqual(dataAccess.Row[1].Value, "13:58:08:359");
            Assert.AreEqual(dataAccess.Row.Count, 18, "row count");
            Assert.AreEqual(fm.FieldIndexInfo.IndexToInfo.Length, 27, "index to info");

            Assert.AreEqual(fm.FieldIndexInfo.GetMaxRowCount(18), 18);

            TypeFieldInfo tfi = fm.FieldIndexInfo.QueryTypeFieldInfo(true, 1);
            Assert.IsNotNull(tfi);
            Assert.AreEqual(tfi.OutputFormat, "HH:mm:ss.fff");

            string value = dataAccess.Row[1].Value;
            Assert.AreEqual(value, "13:58:08:359");
        }
        public void TestInitialize()
        {
            _description = new CsvFileDescription
            {
                SeparatorChar = ',',
                FirstLineHasColumnNames = true,
                IgnoreUnknownColumns = true,
            };
            _input =
@"Id,Name,Last Name,Age,City
1,John,Doe,15,Washington";

            byte[] stringAsByteArray = Encoding.UTF8.GetBytes(_input);
            Stream stream = new MemoryStream(stringAsByteArray);
            _sr = new StreamReader(stream, Encoding.UTF8);
            _dataAccess = new FileDataAccess(_sr, _description);
            
            _cs = new CsvStream(_sr, null, _description.SeparatorChar,
                _description.IgnoreTrailingSeparatorChar);
            _row = new DataRow();
            _fm = new FieldMapperReading<Person>(_description, null, false);
            _ae = new AggregatedException(typeof(Person).ToString(), null, _description.MaximumNbrExceptions);
            _reader = new RowReader<Person>(_description, _ae);
        }
Exemple #14
0
        public void TestLogRecord_FullFields_2()
        {
            FieldMapperReading<LogRecord> fm = new FieldMapperReading<LogRecord>(_fileDescriptionNamesUs, null, false);
            Assert.IsNotNull(fm);
            Assert.IsNotNull(fm.FieldIndexInfo);
            Assert.IsNotNull(fm.NameToInfo);
            Assert.AreEqual(fm.NameToInfo.Count, 27);
            Assert.IsNotNull(fm.NameToInfo["PCI"]);
            Assert.AreEqual(fm.NameToInfo["PCI"].HasColumnAttribute, true);
            List<int> charLengths = fm.GetCharLengths();
            Assert.IsNull(charLengths);

            FileDataAccess dataAccess = new FileDataAccess(_testInput.GetStreamReader(), _fileDescriptionNamesUs);
            Assert.IsNotNull(dataAccess);
            RowReader<LogRecord> reader = dataAccess.ReadDataPreparation<LogRecord>(null);
            Assert.IsNotNull(reader);
            dataAccess.Row = new DataRow();

            List<LogRecord> records = dataAccess.ReadFieldDataRows(reader, null, fm, null).ToList();

            Assert.IsNotNull(records);
            Assert.AreEqual(records.Count, 1);
            Assert.AreEqual(records[0].Id, 0);
            Assert.AreEqual(records[0].Time.Millisecond, 359);
            Assert.AreEqual(records[0].Sinr, 10.1);
            Assert.AreEqual(records[0].UlMcs, 17);
            Assert.AreEqual(records[0].DlThroughput, 10749096);
        }
Exemple #15
0
        public void GoodFileNoSeparatorCharUSEnglish()
        {
            // Arrange

            CsvFileDescription fileDescription_namesUs = new CsvFileDescription
            {
                NoSeparatorChar = true,
                UseOutputFormatForParsingCsvValue = false,
                FirstLineHasColumnNames           = false,
                EnforceCsvColumnAttribute         = true, // default is false
                FileCultureName = "en-US"                 // default is the current culture
            };

            const string testInput = @"AAAAAAAA34.18405/23/08
BBBBBBBB10.31105/12/12
CCCCCCCC12.00012/23/08";

            var expected = new[] {
                new ProductDataCharLength
                {
                    Name = "AAAAAAAA", Weight = 34.184, StartDate = new DateTime(2008, 5, 23),
                },
                new ProductDataCharLength {
                    Name = "BBBBBBBB", Weight = 10.311, StartDate = new DateTime(2012, 5, 12),
                },
                new ProductDataCharLength {
                    Name = "CCCCCCCC", Weight = 12.000, StartDate = new DateTime(2008, 12, 23),
                }
            };

            // Act and Assert
            FileDataAccess dataAccess = new FileDataAccess(testInput.GetStreamReader(), fileDescription_namesUs);
            RowReader <ProductDataCharLength> reader = dataAccess.ReadDataPreparation <ProductDataCharLength>(null);

            dataAccess.Row = new DataRow();
            FieldMapperReading <ProductDataCharLength> fm = new FieldMapperReading <ProductDataCharLength>(
                fileDescription_namesUs, null, false);
            List <int> charLengths = fm.GetCharLengths();

            Assert.AreEqual(charLengths.Count, 3);
            bool firstRow = true;
            List <ProductDataCharLength> actual = new List <ProductDataCharLength>();

            while (dataAccess.Cs.ReadRow(dataAccess.Row, charLengths))
            {
                if ((dataAccess.Row.Count == 1) && ((dataAccess.Row[0].Value == null) ||
                                                    (string.IsNullOrEmpty(dataAccess.Row[0].Value.Trim()))))
                {
                    continue;
                }

                bool readingResult = reader.ReadingOneFieldRow(fm, dataAccess.Row, firstRow);

                if (readingResult)
                {
                    actual.Add(reader.Obj);
                }
                firstRow = false;
            }
            AssertCollectionsEqual(actual, expected);
        }