public void Adding2Customers() { const string lineExpected1 = "Dennis;Ritchie;9/9/1941;"; var customer1 = new CustomerRecord { Firstname = "Dennis", Lastname = "Ritchie", BirthDay = "9/9/1941" }; const string lineExpected2 = "Ken;Thompson;2/4/1943;"; var customer2 = new CustomerRecord { Firstname = "Ken", Lastname = "Thompson", BirthDay = "2/4/1943" }; var csvFile = Path.GetTempFileName(); var lineFile = new LineFile(csvFile); var repo = new CustomerRepository <CustomerRecord>(lineFile, ';'); repo.Open(); repo.Store(customer1); repo.Store(customer2); repo.Close(); var lines = File.ReadAllLines(csvFile); Assert.AreEqual(lineExpected1, lines[0]); Assert.AreEqual(lineExpected2, lines[1]); }
public void UpdatingACustomer() { var customer = new CustomerRecord { Firstname = "Bjorn", Lastname = "Stroustrup", BirthDay = "12/30/1950" }; var csvFile = Path.GetTempFileName(); var lineFile = new LineFile(csvFile); var repo = new CustomerRepository <CustomerRecord>(lineFile, ';'); repo.Open(); repo.Store(customer); customer.Firstname = "Bjarne"; repo.Store(customer); repo.Close(); var lines = File.ReadAllLines(csvFile); const string lineExpected = "Bjarne;Stroustrup;12/30/1950;"; Assert.IsTrue(lines.Length == 1); Assert.AreEqual(lineExpected, lines[0]); }
public void DeletingSomeLines() { const int totalLines = 10000; var filename = Path.Combine(Path.GetTempPath(), string.Format("{0}.txt", DateTime.Now.Ticks)); var lineFileWriter = new LineFile(filename); var linesToAdd = new List <string>(); for (int i = 0; i < totalLines; i++) { linesToAdd.Add(string.Format("This is a medium lenght line, and, incidentally, this is the {0} line :)", i)); } lineFileWriter.AddLines(linesToAdd.ToArray()); var linesToDelete = new List <string>(); for (int i = 0; i < totalLines; i += 10) { linesToDelete.Add(string.Format("This is a medium lenght line, and, incidentally, this is the {0} line :)", i)); } lineFileWriter.DeleteLines(linesToDelete.ToArray()); var readLines = lineFileWriter.ReadAllLines(); Assert.AreEqual(totalLines - (totalLines / 10), readLines.Count); }
public void Set(LineFile l) { myFile = l; GetComponentInChildren <Text>().text = l.fileName; GetComponentInChildren <Button>().SetOnClickListener(() => { Select(this); }); }
public void AddALine_ToAnInexistentFile_CreatesFile() { var filename = Path.Combine(Path.GetTempPath(), string.Format("{0}.txt", DateTime.Now.Ticks)); var lineFileWriter = new LineFile(filename); lineFileWriter.AddLine("hello!"); Assert.IsTrue(File.Exists(filename)); }
public static List <LineFile> GetFiles() { List <LineFile> l = new List <LineFile>(); foreach (string i in Directory.GetFiles(directory)) { LineFile n = new LineFile(); n.fullPath = i; n.fileName = Path.GetFileNameWithoutExtension(i); l.Add(n); } return(l); }
public void AddingTooMuchLines() { var filename = Path.Combine(Path.GetTempPath(), string.Format("{0}.txt", DateTime.Now.Ticks)); var lineFileWriter = new LineFile(filename); var lines = new List <string>(); for (int i = 0; i < 1000000; i++) { lines.Add(string.Format("This is a medium lenght line, and, incidentally, this is the {0} line :)", i)); } lineFileWriter.AddLines(lines.ToArray()); Assert.IsTrue(File.Exists(filename)); }
public void ReadLine(int number) { var filename = Path.Combine(Path.GetTempPath(), string.Format("{0}.txt", DateTime.Now.Ticks)); var lineFileWriter = new LineFile(filename); var lines = new List <string>(); for (int i = 0; i < 1000; i++) { lines.Add(i.ToString()); } lineFileWriter.AddLines(lines.ToArray()); var line = lineFileWriter.ReadLine(number); Assert.AreEqual(number.ToString(), line); }
public void ReadAllLines() { var filename = Path.Combine(Path.GetTempPath(), string.Format("{0}.txt", DateTime.Now.Ticks)); var lineFileWriter = new LineFile(filename); var lines = new List <string>(); for (int i = 0; i < 1000000; i++) { lines.Add(string.Format("This is a medium lenght line, and, incidentally, this is the {0} line :)", i)); } lineFileWriter.AddLines(lines.ToArray()); var readLines = lineFileWriter.ReadAllLines(); Assert.AreEqual(1000000, readLines.Count); }
public void AddingACustomer() { var customer = new CustomerRecord { Firstname = "Niklaus", Lastname = "Wirth", BirthDay = "02/15/1934" }; var csvFile = Path.GetTempFileName(); var lineFile = new LineFile(csvFile); var repo = new CustomerRepository <CustomerRecord>(lineFile, ';'); repo.Open(); repo.Store(customer); repo.Close(); var line = File.ReadAllText(csvFile); const string lineExpected = "Niklaus;Wirth;02/15/1934;\r\n"; Assert.AreEqual(lineExpected, line); }
public void AddAndRetrieveACustomer() { var customer = new CustomerRecord { Firstname = "James", Lastname = "Gosling", BirthDay = "05/19/1955" }; var csvFile = Path.GetTempFileName(); var lineFile = new LineFile(csvFile); var repo = new CustomerRepository <CustomerRecord>(lineFile, ';', true); repo.Open(); repo.Store(customer); repo.Flush(); var func = new Func <CustomerRecord, bool>(f => f.Lastname == "Gosling"); var customerResult = repo.Select(func).FirstOrDefault(); Assert.AreEqual(customer, customerResult); }