Exemplo n.º 1
0
        public void Add_Columns_Manually_Test()
        {
            Type type = typeof(Measurement);

            DocumentFormatDefinitionBuilder <Measurement> builder = new DocumentFormatDefinitionBuilder <Measurement>("\t", true)
                                                                    .SetCommentString("'")
                                                                    .SetExportHeaderLine(true, "' ");

            builder.AddColumn(type.GetProperty("Name"));
            builder.AddColumn(type.GetProperty("X"), "0.000");
            builder.AddColumn(type.GetProperty("Y"), "0.000");
            builder.AddColumn(type.GetProperty("Z"), "0.000");
            builder.AddColumn(type.GetProperty("DateTime"), "dd.MM.yyyy HH:mm:ss");
            builder.AddColumn(type.GetProperty("IsActive"));

            IDocumentFormatDefinition <Measurement> definition = builder.Build();

            string exportResult = definition.Export(new[] { _measurement });

            Assert.AreEqual(@"' Name    X       Y       Z       DateTime            IsActive
Point01	10.000	20.000	30.000	03.03.2013 14:48:00	T"    , exportResult);

            List <Measurement> importList = definition.Import(exportResult);

            AssertAreEqual(importList);
        }
        public void Test_With_Comments()
        {
            const string importData = @"001-01  12.11 1222.87 334.32 #Test
001-02 223.91  778.64 234.24
002-01 106.18  345.33 789.32
002-02  22.60  233.22 321.88 #Test
# 002-02 106.18  345.33 789.32
 # 002-02 106.18  345.33 789.32
003-01  98.31  983.33 564.89
003-02 345.77  324.21 123.94
#003-02 345.77  324.21 123.94
";

            IDocumentFormatDefinition <Location> definition = GetDefinition("#");

            List <Location> importList = definition.Import(new StringReader(importData));

            Assert.AreEqual(6, importList.Count());

            Compare(importList[0], "001-01", 12.11, 1222.87, 334.32);
            Compare(importList[1], "001-02", 223.91, 778.64, 234.24);
            Compare(importList[2], "002-01", 106.18, 345.33, 789.32);
            Compare(importList[3], "002-02", 22.60, 233.22, 321.88);
            Compare(importList[4], "003-01", 98.31, 983.33, 564.89);
            Compare(importList[5], "003-02", 345.77, 324.21, 123.94);
        }
Exemplo n.º 3
0
        public void AutoBuild_Test()
        {
            IDocumentFormatDefinition <Measurement> definition = DocumentFormatDefinitionBuilder <Measurement> .AutoBuild("\t", true, "'", true, "' ");

            string             exportResult = definition.Export(new[] { _measurement });
            List <Measurement> importList   = definition.Import(exportResult);

            AssertAreEqual(importList);
        }
Exemplo n.º 4
0
        public void ExportImportExport()
        {
            IDocumentFormatDefinition <Person> definition = GetDefinition();
            string        exportData1  = definition.Export(GetPocoList());
            List <Person> importResult = definition.Import(new StringReader(exportData1));
            string        exportData2  = definition.Export(importResult);

            Assert.AreEqual(exportData1, exportData2);
        }
Exemplo n.º 5
0
        public void ImportPoco()
        {
            IDocumentFormatDefinition <SimplePoco> definition = GetPocoDefinition();

            List <SimplePoco> result = definition.Import(new StringReader(StringPropValue1 + "\t" + Int32PropValue1));

            Assert.AreEqual(1, result.Count);
            Assert.AreEqual(StringPropValue1, result[0].StringProp);
            Assert.AreEqual(Int32PropValue1, result[0].Int32Prop);
        }
        public void DataOverflowInColumn_ThrowsExportException()
        {
            DocumentFormatDefinitionBuilder <ChequeRow> definition = GetDefinition();
            var record = new ChequeRow()
            {
                AccountNo = 1234567890123                  // Overflowed
            };
            IDocumentFormatDefinition <ChequeRow> document = definition.Build();

            Assert.Throws <ExportException>(() => document.Export(new ChequeRow[] { record }));
        }
Exemplo n.º 7
0
        public void ImportTest()
        {
            IDocumentFormatDefinition <Location> definition = GetDefinition();

            List <Location> importResult = definition.Import(new StringReader(ExampleCsv));

            Assert.AreEqual(14, importResult.Count);

            Compare(importResult[0], "X-T0191q_1", -2.19819, -2.182, 188.952);
            Compare(importResult[5], "X-T0196q_6", -5.414, 0.200, 191.19199);
            Compare(importResult[13], "X-T0204q_14", 5.1925, 4.1986, 195.525);
        }
Exemplo n.º 8
0
        public void ExportPoco()
        {
            IDocumentFormatDefinition <SimplePoco> definition = GetPocoDefinition();

            var poco = new SimplePoco {
                Int32Prop = Int32PropValue1, StringProp = StringPropValue1
            };
            string result = definition.Export(new List <SimplePoco> {
                poco
            });

            Assert.AreEqual(StringPropValue1 + "\t" + Int32PropValue1, result);
        }
Exemplo n.º 9
0
        public void ImportExport()
        {
            IDocumentFormatDefinition <State> definition = GetDefinition();

            using (var reader = new StreamReader("Data\\states.csv", Encoding.GetEncoding(1252)))
            {
                string fileContent = reader.ReadToEnd();

                List <State> allStates = definition.Import(new StringReader(fileContent), 1);

                var exportResult = definition.Export(allStates);

                Assert.AreEqual(fileContent, exportResult);
            }
        }
Exemplo n.º 10
0
        public void NoDefaultConstructorTest()
        {
            var measurements = new List <GpsLocation>()
            {
                new GpsLocation(48.3224, 18.3224)
            };

            IDocumentFormatDefinition <GpsLocation> definition = GetDefinition();

            string             exportResult = definition.Export(measurements);
            List <GpsLocation> importResult = definition.Import(new StringReader(exportResult));

            Assert.AreEqual(1, importResult.Count);
            Assert.AreEqual(measurements[0].Lat, importResult[0].Lat);
            Assert.AreEqual(measurements[0].Lon, importResult[0].Lon);
        }
Exemplo n.º 11
0
        public void ExportMultiplePocos()
        {
            IDocumentFormatDefinition <SimplePoco> definition = GetPocoDefinition();

            var pocoList = new List <SimplePoco>
            {
                new SimplePoco {
                    Int32Prop = Int32PropValue1, StringProp = StringPropValue1
                },
                new SimplePoco {
                    Int32Prop = Int32PropValue2, StringProp = StringPropValue2
                }
            };

            string result = definition.Export(pocoList);

            Assert.AreEqual(StringPropValue1 + "\t" + Int32PropValue1 + "\r\n" + StringPropValue2 + "\t" + Int32PropValue2, result);
        }
Exemplo n.º 12
0
        public void ExportTest()
        {
            IDocumentFormatDefinition <Location> definition = GetDefinition();

            List <Location> importResult = definition.Import(new StringReader(ExampleCsv));

            string exportResult = definition.Export(importResult);

            string[] expectedLines = ExampleCsv.Split(new[] { "\r\n", "\n" }, StringSplitOptions.RemoveEmptyEntries);
            string[] actualLines   = exportResult.Split(new[] { "\r\n", "\n" }, StringSplitOptions.RemoveEmptyEntries);

            Assert.AreEqual(expectedLines.Length, actualLines.Length);

            for (int i = 0; i < expectedLines.Length; i++)
            {
                Assert.AreEqual(expectedLines[i], actualLines[i]);
            }
        }
Exemplo n.º 13
0
        public void Import()
        {
            IDocumentFormatDefinition <State> definition = GetDefinition();

            using (var reader = new StreamReader("Data\\states.csv", Encoding.GetEncoding(1252)))
            {
                List <State> allStates   = definition.Import(reader, 1);
                List <State> membersOfEu = allStates.Where(x => x.EU_MEMBER != null && x.EU_MEMBER.IsMember).OrderBy(x => x.EU_MEMBER.Year).ThenBy(x => x.NAME_ENG).ToList();

                Console.WriteLine("Members of EU: " + membersOfEu.Count);

                foreach (var euCountry in membersOfEu)
                {
                    Console.WriteLine(euCountry.NAME_ENG + " (" + euCountry.EU_MEMBER.Year + ")");
                }

                Assert.AreEqual(27, membersOfEu.Count);
            }
        }
Exemplo n.º 14
0
        public void ColumnSeparatorInColumn()
        {
            var location = new Location()
            {
                Name = "House;Green", X = 12.24, Y = 34.213, Z = 12.1231231
            };

            IDocumentFormatDefinition <Location> definition = GetDefinition();
            string exportResult = definition.Export(new[] { location });

            List <Location> importResult = definition.Import(exportResult);

            Assert.AreEqual(1, importResult.Count);

            Assert.AreEqual(location.Name, importResult.First().Name);
            Assert.AreEqual(location.X, importResult.First().X);
            Assert.AreEqual(location.Y, importResult.First().Y);
            Assert.AreEqual(location.Z, importResult.First().Z);
        }
Exemplo n.º 15
0
        public void PropertyList_Test()
        {
            var propertyList = new List <PropertyInfo>
            {
                typeof(Measurement).GetProperty("Name"),
                typeof(Measurement).GetProperty("X"),
                typeof(Measurement).GetProperty("Y"),
                typeof(Measurement).GetProperty("Z"),
                typeof(Measurement).GetProperty("DateTime"),
                typeof(Measurement).GetProperty("IsActive"),
            };

            IDocumentFormatDefinition <Measurement> definition = DocumentFormatDefinitionBuilder <Measurement> .Build(propertyList, "\t", true, "'", true, "' ");

            string             exportResult = definition.Export(new[] { _measurement });
            List <Measurement> importList   = definition.Import(exportResult);

            AssertAreEqual(importList);
        }
Exemplo n.º 16
0
        public void ExportQuotedStrings()
        {
            var location = new Location()
            {
                Name = "House \"Red\"", X = 12.24, Y = 34.213, Z = 12.1231231
            };

            IDocumentFormatDefinition <Location> definition = GetDefinition();
            string exportResult = definition.Export(new[] { location });

            List <Location> importResult = definition.Import(exportResult);

            Assert.AreEqual(1, importResult.Count);
            Assert.AreEqual(2, importResult.First().Name.Count(x => x == '"'));

            Assert.AreEqual(location.Name, importResult.First().Name);
            Assert.AreEqual(location.X, importResult.First().X);
            Assert.AreEqual(location.Y, importResult.First().Y);
            Assert.AreEqual(location.Z, importResult.First().Z);
        }
Exemplo n.º 17
0
        public void Test()
        {
            const int          count = 100000;
            List <Measurement> list  = CreateList(count);
            IDocumentFormatDefinition <Measurement> definition = GetDefinition();

            Stopwatch sw           = Stopwatch.StartNew();
            string    exportResult = definition.Export(list);

            sw.Stop();

            Console.WriteLine(sw.ElapsedMilliseconds);
            double perSec = Math.Round(count / (double)sw.ElapsedMilliseconds * 1000);

            Console.WriteLine("Export: " + perSec + " pocos/sec");
            Console.WriteLine();

            sw = Stopwatch.StartNew();
            List <Measurement> importList = definition.Import(new StringReader(exportResult));

            sw.Stop();

            Console.WriteLine(sw.ElapsedMilliseconds);
            perSec = Math.Round(count / (double)sw.ElapsedMilliseconds * 1000);
            Console.WriteLine("Import: " + perSec + " pocos/sec");


            for (int i = 0; i < count; i++)
            {
                Assert.AreEqual(list[i].Name, importList[i].Name);
                Assert.IsTrue(Math.Abs((list[i].DateTime - importList[i].DateTime).TotalMinutes) < 1);
                Assert.AreEqual(list[i].X, importList[i].X);
                Assert.AreEqual(list[i].Y, importList[i].Y);
                Assert.AreEqual(list[i].Z, importList[i].Z);
                Assert.AreEqual(list[i].IsActive, importList[i].IsActive);
            }
        }