public void InstanceCSVAccessInvalidParameterTest() { CSVAccess acc; acc = new CSVAccess(string.Empty); acc = new CSVAccess(null); }
public void InstanceCSVAccessNoParameterTest() { CSVAccess acc = new CSVAccess(); Assert.IsNotNull(acc); Assert.AreEqual(string.Empty, acc.Storage); }
public void InstanceCSVAccessParameterTest() { var s = "NewStudents"; CSVAccess acc = new CSVAccess(s); Assert.IsNotNull(acc); StringAssert.Contains(acc.Storage, s, "CSVAccess storage path not contains expected string: " + s); StringAssert.EndsWith(acc.Storage, s + ".csv", "CSVAccess storage path not end with expected: " + s + ".csv"); }
public void StudentTestInitialize() { studentData.Clear(); var tmpPath = Path.Combine(Environment.CurrentDirectory, "Student.csv"); if (File.Exists(tmpPath)) { File.Delete(tmpPath); } File.Copy(studentTestFile, tmpPath); Task t = studentCsv.LoadDataAsync(); t.Wait(); CSVAccess acc = new CSVAccess(); TextFieldParser parser = acc.GetCSVParser(studentTestFile); // skip over header line. parser.ReadLine(); while (!parser.EndOfData) { string[] v = new string[2]; string[] fields = parser.ReadFields(); v[0] = fields[1]; v[1] = fields[2]; try { if (!studentData.ContainsKey(fields[0])) { studentData.Add(fields[0], v); } } catch (Exception ex) { Console.WriteLine(ex.Message); } } parser.Dispose(); }
public void InstanceTextFieldParserInvalidPathTest() { CSVAccess acc = new CSVAccess(Courses); Assert.IsNotNull(acc); TextFieldParser paser; try{ paser = acc.GetCSVParser("notexist.csv"); } catch (ArgumentException ex) { StringAssert.Contains(ex.Message, "Path not found:"); return; } throw new Exception("Invalid CSV file path not being catch!"); }
public void InstanceTextFieldParserTest() { CSVAccess acc = new CSVAccess(courseTestFile); Assert.IsNotNull(acc); TextFieldParser parser; try{ parser = acc.GetCSVParser(Path.Combine(Environment.CurrentDirectory, "Temp.csv")); Assert.IsNotNull(parser); parser.Close(); } catch (Exception ex) { throw new Exception("Failed to instance TestFileParser from CSVAccess! Exception: " + ex.Message); } }
public void CourseCsvTestInitialize() { courseData.Clear(); var tmpPath = Path.Combine(Environment.CurrentDirectory, "Course.csv"); if (File.Exists(tmpPath)) { File.Delete(tmpPath); } File.Copy(courseTestFile, tmpPath); courseCsv = CourseCSV.Initialize(); Assert.IsNotNull(courseCsv, "Failed: Initialize CourseCSV object returns null!"); CSVAccess acc = new CSVAccess(); TextFieldParser parser = acc.GetCSVParser(courseTestFile); // skip over header line. parser.ReadLine(); while (!parser.EndOfData) { string[] v = new string[2]; string[] fields = parser.ReadFields(); v[0] = fields[1]; v[1] = fields[2]; try { if (!courseData.ContainsKey(fields[0])) { courseData.Add(fields[0], v); } } catch (Exception ex) { throw new Exception("Initializing unit test got exception: " + ex.Message); } } parser.Dispose(); }