//Import the data from csv file chosen private void btnImport_Click(object sender, EventArgs e) { if (openFileDialog.ShowDialog() == DialogResult.OK) { try { var fileName = openFileDialog.FileName; string error = ""; if (Helpers.FileAccess.ValidateFormat(fileName)) { _peoplelist = People_Class.ReadAllPeople(fileName, out error); if (string.IsNullOrEmpty(error))//File imported succesfully { toolStripStatusLabel.Text = "File Imported Succesfully"; dataGridView1.DataSource = _peoplelist; SetVisibility(); } else { toolStripStatusLabel.Text = error; } } else { toolStripStatusLabel.Text = "File format incorrect, [Name, Surname, Address]"; } } catch (Exception ex) { toolStripStatusLabel.Text = ex.Message; } } }
public void TestMissingData() { string file = System.IO.Path.GetFullPath(@"..\..\..\Data\\MissingData.csv"); if (FileAccess.ValidateFormat(file)) { string error = null; if (FileAccess.ValidateFormat(file)) { People_Class.ReadAllPeople(file, out error); } Assert.AreEqual("Index was outside the bounds of the array.", error); } }
public void TestResults() { string file = System.IO.Path.GetFullPath(@"..\..\..\Data\\data.csv"); if (FileAccess.ValidateFormat(file)) { string error = null; People_Class.ReadAllPeople(file, out error); List <string> expectedFirstNameList = new List <string>(); expectedFirstNameList.AddRange(new string[] { "Iago Tieman", "Cordie Bleibaum", "Shandie Rowles", "Genny Seys", "Renault Millichap", "Shandie Rowles", "Iago Tieman", "Genny Seys", "Iago Tieman" }); List <string> expectedAddressList = new List <string>(); expectedAddressList.AddRange(new string[] { "42 Basil Park", "74584 Moose Parkway", "81075 Killdeer Road", "2 Nova Circle", "32 Butterfield Drive" }); List <string> actualFirstNameList = People_Class.GetFullNameList(); List <string> actualAddressList = People_Class.GetAddressList(); CollectionAssert.AreEqual(expectedFirstNameList, actualFirstNameList); CollectionAssert.AreEqual(expectedAddressList, actualAddressList); } }