Пример #1
0
 public void TestReadOperations()
 {
     var dao = new AdvancedDsvDao(DataFolder + "AdvancedReadOnlyTsv.txt", '\t', true);
     Assert.AreEqual("Name", dao.GetHeaders()[0]);
     
     var dataEntries = dao.GetDataEntries().ToList();
     Assert.AreEqual(2, dataEntries.Count());
     Assert.AreEqual("simple text", dataEntries[0][2]);
     Assert.AreEqual("Asturian", dataEntries[1][3]);
 }
Пример #2
0
        public void TestAddRemoveHeaders()
        {
            AdvancedDsvDao dao = new AdvancedDsvDao(DataFolder + "AdvancedReadWriteTsv.txt", '\t', true);
            var headers = dao.GetHeaders();
            int dataEntriesCount = dao.GetDataEntries().Count();

            dao.RemoveHeaders();
            Assert.AreEqual(null, dao.GetHeaders());
            Assert.AreEqual(dataEntriesCount, dao.GetDataEntries().Count());

            dao.UpdateHeaders(headers);
            Assert.AreEqual("Name", dao.GetHeaders()[0]);
            Assert.AreEqual(dataEntriesCount, dao.GetDataEntries().Count());
        }
Пример #3
0
        public void ReadConvertAndMap()
        {
            var dicToObjMappingInfos = new List<DictionaryItemToObjectMappingInfo>()
            {
                new DictionaryItemToObjectMappingInfo()
                {
                    Key = "person name",
                    PropertyName = "Name",
                    FromStringMapping = st => st,
                    ToStringMapping = ob => (string)ob
                }, 
                new DictionaryItemToObjectMappingInfo()
                {
                    Key = "how old",
                    PropertyName = "Age",
                    FromStringMapping = st => Convert.ToInt32(st),
                    ToStringMapping = num => num.ToString()
                }
            };

            var dirSep = System.IO.Path.DirectorySeparatorChar;
            //var filePath = FileHelper.GetProgramFolder() + @"..\..\..\TestData\ReadAndMapTsv.txt";
            var filePath = FileHelper.GetProgramFolder()
                + (".." + dirSep).Multiply(3)
                + "TestData" + dirSep
                + "ReadAndMapTsv.txt";
            var dao = new AdvancedDsvDao(filePath, '\t', true);
            var headersList = dao.GetHeaders();

            var colToObjMappingInfos = new MappingInfoConverter().Convert(dicToObjMappingInfos, headersList).ToList();
            Assert.AreEqual(0, colToObjMappingInfos[0].Index);
            Assert.AreEqual(3, colToObjMappingInfos[1].Index);

            //the "real life" usage would go on like this:
            var mapper = new CollectionToFromObjectMapper<Person>(colToObjMappingInfos);
            var people = dao.GetDataEntries()
                .Select(personRow => mapper.Map(personRow))
                .ToList();

            Assert.AreEqual(people[0].Name, "Johan");
            Assert.AreEqual(people[0].Age, 34);

            Assert.AreEqual(people[1].Name, "Xose");
            Assert.AreEqual(people[1].Age, 36);
        }
Пример #4
0
        public void TestAddRemoveDataEntries()
        {
            AdvancedDsvDao dao = new AdvancedDsvDao(DataFolder + "AdvancedReadWriteTsv.txt", '\t', true);
            var entries = dao.GetDataEntries().ToList();


            ////my own tests to see how the enumerator works
            //var entries1 = dao.GetDataEntries();
            //int count1 = entries1.Count();
            //int count2 = entries1.Count();

            dao.RemoveDataEntries();
            Assert.AreEqual(0, dao.GetDataEntries().Count());
            
            dao.AddDataEntries(entries);
            Assert.AreEqual(entries.Count(), dao.GetDataEntries().Count());
            Assert.AreEqual("Johan", dao.GetDataEntries().ToList()[0][0]);

            dao.AddDataEntries(entries);
            Assert.AreEqual(entries.Count() * 2, dao.GetDataEntries().Count());
        }