Ejemplo n.º 1
0
    public static void ReadingAndWritingCsv()
    {
        // Initialize data (see code-example above):
        Contact[] contactArr = ContactExample.InitializeContacts();

        const string fileName = "FamilyDoe.csv";

        // Save the Contacts:
        contactArr.SaveCsv(fileName, CsvCompatibility.Thunderbird);

        // Display the content of the CSV file:
        Console.WriteLine("Saved CSV:");
        Console.WriteLine();
        Console.WriteLine(File.ReadAllText(fileName));

        // Reload the CSV file:
        List <Contact> contactList = ContactPersistence.LoadCsv(fileName, CsvCompatibility.Thunderbird);

        // Display the content of the reloaded Contact objects:
        Console.WriteLine();
        Console.WriteLine("Reloaded Contact objects:");

        for (int i = 0; i < contactList.Count; i++)
        {
            Console.WriteLine();
            Console.WriteLine($"Contact {i + 1}:");
            Console.WriteLine(contactArr[i]);
            Console.WriteLine();
        }
    }
        public void LoadCsvTest_Thunderbird3()
        {
            List <Contact> conts = ContactPersistence.LoadCsv(TestFiles.ThunderbirdUtf8EnglishColumnsInvalidBDayCsv, CsvCompatibility.Thunderbird);

            Assert.IsNotNull(conts);
            Assert.AreEqual(1, conts.Count);
            CollectionAssert.DoesNotContain(conts, null);
        }
        public void LoadCsvTest_Thunderbird2()
        {
            List <Contact> conts = ContactPersistence.LoadCsv(TestFiles.ThunderbirdUtf8UnknownAndLessColumnNamesCsv, CsvCompatibility.Thunderbird);

            Assert.IsNotNull(conts);
            Assert.AreEqual(1, conts.Count);
            CollectionAssert.DoesNotContain(conts, null);
        }
        public void LoadCsvTest_Google()
        {
            List <Contact> conts = ContactPersistence.LoadCsv(TestFiles.GoogleCsv, CsvCompatibility.Google);

            Assert.IsNotNull(conts);
            Assert.AreEqual(1, conts.Count);
            CollectionAssert.DoesNotContain(conts, null);
        }
        public void SaveTest_Outlook2()
        {
            string fileName = Path.Combine(TestContext.TestRunResultsDirectory, "Outlook2.csv");

            List <Contact> conts = ContactPersistence.LoadCsv(TestFiles.Outlook365Csv, CsvCompatibility.Outlook, CultureInfo.InvariantCulture);

            conts.SaveCsv(fileName, CsvCompatibility.Outlook);
        }
        public void SaveCsvTest()
        {
            List <Contact> conts = ContactPersistence.LoadCsv(TestFiles.GoogleCsv, CsvCompatibility.Google);

            conts.Insert(0, null !);

            string fileName = Path.Combine(TestContext.TestRunResultsDirectory, "Google_CollectionExtension1.csv");

            conts.SaveCsv(fileName, CsvCompatibility.Google);
        }
        public void LoadCsvTest_Outlook_DifferentColumnNames()
        {
            List <Contact> conts = ContactPersistence.LoadCsv(TestFiles.Outlook365DifferentColumnNamesCsv, CsvCompatibility.Outlook, CultureInfo.InvariantCulture);

            Assert.IsNotNull(conts);
            Assert.AreEqual(6, conts.Count);
            CollectionAssert.DoesNotContain(conts, null);
            Assert.IsNotNull(conts[0].Person);
            Assert.AreEqual(new DateTime(1981, 1, 20), conts[0]?.Person?.BirthDay);
            Assert.AreEqual(new DateTime(2005, 6, 3), conts[0]?.Person?.Anniversary);
        }
        public void LoadCsvTest_Outlook_DifferentColumnNamesLessColumns()
        {
            List <Contact> conts = ContactPersistence.LoadCsv(TestFiles.Outlook365DifferentColumnNamesLessColumnsCsv, CsvCompatibility.Outlook, CultureInfo.InvariantCulture);

            Assert.IsNotNull(conts);
            Assert.AreEqual(6, conts.Count);
            CollectionAssert.DoesNotContain(conts, null);

            Assert.IsNotNull(conts[5].Person);
            Assert.AreEqual("Mustermann", conts[5].Person?.Name?.LastName);
        }
        public void LoadCsvTest_Unspecified()
        {
            var sw = new Stopwatch();

            sw.Start();
            List <Contact> conts = ContactPersistence.LoadCsv(TestFiles.WindowsLiveMail, CsvCompatibility.Unspecified);

            sw.Stop();

            TestContext.WriteLine($"Stopwatch: {sw.ElapsedMilliseconds}");

            Assert.IsNotNull(conts);
            Assert.AreEqual(1, conts.Count);
            CollectionAssert.DoesNotContain(conts, null);
        }
        public void LoadCsvTest2()
        {
            List <Contact> res = ContactPersistence.LoadCsv(TestFiles.NoHeaderCsv, CsvCompatibility.Outlook, CultureInfo.InvariantCulture);

            Assert.AreEqual(0, res.Count);
        }
 public void LoadCsvTest1()
 {
     _ = ContactPersistence.LoadCsv(TestFiles.Outlook365Csv, (CsvCompatibility)4711, CultureInfo.InvariantCulture);
 }