Ejemplo n.º 1
0
        public void OpensFile()
        {
            using (var file = new CSVFile(filename))
            {
                file.Open();
            }

            Assert.IsTrue(true);
        }
Ejemplo n.º 2
0
        public void ReadAndParseFirstLine()
        {
            ExampleEntityParseByHeader entity;

            using (var file = new CSVFile(filename))
            {
                file.Open();
                List<ExampleEntityParseByHeader> entities = CSVParser.ReadAndParseCSV<ExampleEntityParseByHeader>(file.Stream);
                entity = entities[0];
            }

            Assert.AreEqual("Pepsi Max", entity.Name);
            Assert.AreEqual(1.69M, entity.Price);
            Assert.AreEqual("0120000011880", entity.UPC);
            Assert.AreEqual("20oz", entity.Size);
            Assert.AreEqual("Pepsi", entity.Brand);
            Assert.AreEqual(new DateTime(2011, 6, 18), entity.EffectiveDate);
        }
Ejemplo n.º 3
0
        public void ReadAndParseFirstLine()
        {
            ItemEntity entity = new ItemEntity();
            using (var file = new CSVFile(filename))
            {
                file.Open();
                var line = file.ReadLine();
                entity.Name = line.GetField(0).ToString().Trim();
                entity.Price = line.GetField(1).TryToDecimal() ?? 0;
                entity.UPC = line.GetField(2).ToString();
                entity.Size = line.GetField(3).ToString().Trim();
                entity.Brand = line.GetField(4).ToString().Trim();
                entity.EffectiveDate = line.GetField(5).TryToDateTime();
            }

            Assert.AreEqual("Pepsi Max", entity.Name);
            Assert.AreEqual(1.69M, entity.Price);
            Assert.AreEqual("0120000011880", entity.UPC);
            Assert.AreEqual("20oz", entity.Size);
            Assert.AreEqual("Pepsi", entity.Brand);
            Assert.AreEqual(new DateTime(2011, 6, 18), entity.EffectiveDate);
        }
Ejemplo n.º 4
0
        public void AlternateFieldAccessMethod()
        {
            ItemEntity entity = new ItemEntity();
            using (var file = new CSVFile(filename))
            {
                file.Open();
                var line = file.ReadLine();
                entity.Name = line[0].ToString().Trim();
                entity.Price = line[1].TryToDecimal() ?? 0;
                entity.UPC = line[2].ToString();
                entity.Size = line[3].ToString().Trim();
                entity.Brand = line[4].ToString().Trim();
                entity.EffectiveDate = line[5].TryToDateTime();
            }

            Assert.AreEqual("Pepsi Max", entity.Name);
            Assert.AreEqual(1.69M, entity.Price);
            Assert.AreEqual("0120000011880", entity.UPC);
            Assert.AreEqual("20oz", entity.Size);
            Assert.AreEqual("Pepsi", entity.Brand);
            Assert.AreEqual(new DateTime(2011, 6, 18), entity.EffectiveDate);
        }
Ejemplo n.º 5
0
        public void ReadEmptyLineReturnsNull()
        {
            File.Delete(filename);

            var testfile = new StreamWriter(File.OpenWrite(filename));
            testfile.WriteLine("");
            testfile.Close();

            using (var file = new CSVFile(filename))
            {
                file.Open();
                var line = file.ReadLine();
                Assert.AreEqual(string.Empty, line.ToString());
            }
        }
Ejemplo n.º 6
0
        public void ThrowsFileNotFoundWhenDoesNotExist()
        {
            using (var file = new CSVFile("doesnotexist.txt"))
            {
                try
                {
                    file.Open();
                }
                catch (FileNotFoundException e)
                {
                    Assert.IsTrue(true);
                    return;
                }

                Assert.IsTrue(false);
            }
        }
Ejemplo n.º 7
0
        public void ReadUntilEOL()
        {
            using (var file = new CSVFile(filename))
            {
                file.Open();
                CSVLine line;
                do
                {
                    line = file.ReadLine();
                } while (!line.IsEOF);

                Assert.IsTrue(true);
            }
        }
Ejemplo n.º 8
0
 public void ReadSingleLine()
 {
     using (var file = new CSVFile(filename))
     {
         file.Open();
         var line = file.ReadLine();
         Assert.AreEqual(firstline, line.ToString());
     }
 }