Example #1
0
        /// <summary>
        /// Imports a csv file which path is given by the 
        /// commandline arguments.
        /// </summary>
        /// <param name="args">The commandline arguments split by ' '.</param>
        /// <returns>Whether the data was imported.</returns>
        public bool Import(string[] args)
        {
            var file = String.Join(" ", args);
            file = file.Substring(7);
            file = file.Trim();

            if (args.Length > 1 && file != "") {
                try {
                    using (var reader = new StreamReader(file)) {
                        Console.WriteLine(@"Importing from: "+file);

                        string line;
                        var i = 0;

                        while ((line = reader.ReadLine()) != null) {
                            if (i > 0) {
                                var row = line.Split(';');

                                var personEntity = new PersonEntity {
                                    Firstname = row[0],
                                    Lastname = row[1],
                                    Cpr = row[2],
                                    VoterId = Convert.ToInt32(row[3]),
                                    PollingTable = row[4],
                                    PollingVenue = row[5]
                                };

                                Console.WriteLine(@"Imported: "+personEntity.VoterId);

                                personEntity.Save();
                            }

                            i++;
                        }
                    }

                    return true;
                } catch (Exception e) {
                    Debug.WriteLine(e.ToString());
                }
            }

            return false;
        }
Example #2
0
        public void TestPersonCreationUpdatingAndDeletion()
        {
            var person = new PersonEntity();
            person.Firstname = "Jan";
            person.Lastname = "Aagaard Meier";
            person.Cpr = "0123456789";
            person.VoterId = 1337;
            person.PollingVenue = "ITU";
            person.PollingTable = "42";

            person.Save();

            person = new PersonEntity();
            person.Load(new Hashtable { { "polling_table", "42" } });

            Assert.That(person.Exists());
            Assert.That(person.Firstname == "Jan");
            Assert.That(person.Lastname == "Aagaard Meier");
            Assert.That(person.Cpr == "0123456789");
            Assert.That(person.VoterId == 1337);
            Assert.That(person.PollingVenue == "ITU");
            Assert.That(person.PollingTable == "42");

            person.Firstname = "Niels";
            person.VoterId = 314;

            person.Save();

            person = new PersonEntity();
            person.Load(new Hashtable { { "polling_table", "42" } });

            Assert.That(person.Exists());
            Assert.That(person.Firstname == "Niels");
            Assert.That(person.Lastname == "Aagaard Meier");
            Assert.That(person.Cpr == "0123456789");
            Assert.That(person.VoterId == 314);
            Assert.That(person.PollingVenue == "ITU");
            Assert.That(person.PollingTable == "42");

            person.Delete();

            person = new PersonEntity();
            person.Load(new Hashtable { { "polling_table", "42" } });

            Assert.That(!person.Exists());
        }