public List <OrganizationData> GetOrganizations() { var resultList = new List <OrganizationData>(); var dataReader = new CsvDataReader(); var csvResult = dataReader.ReadData(_filePath); var columnNames = csvResult.ColumnNames; var indexOfId = columnNames.ToList().IndexOf("Id"); var indexOfName = columnNames.ToList().IndexOf("Name"); var indexOfAddress = columnNames.ToList().IndexOf("Adress"); var indexOfEmail = columnNames.ToList().IndexOf("Email"); var indexOfContactPerson = columnNames.ToList().IndexOf("Contact Person"); foreach (var row in csvResult.Rows) { var volunteer = new OrganizationData() { Id = row[indexOfId], Name = row[indexOfName], Address = row[indexOfAddress], Email = row[indexOfEmail], ContactPerson = row[indexOfContactPerson] }; resultList.Add(volunteer); } return(resultList); }
public void ReadData_SendIncorrectFilePath_ThrowExcepion() { var filePath = "..\\..\\..\\Resources\\NonExistFile.csv"; var dataReader = new CsvDataReader(filePath); Assert.ThrowsException <FileNotFoundException>(() => dataReader.ReadData()); }
public List <VolunteerData> GetVolunteers() { var ci = new CultureInfo("pl-PL"); var resultList = new List <VolunteerData>(); var dataReader = new CsvDataReader(); var csvResult = dataReader.ReadData(_volunteersFilePath); var columnNames = csvResult.ColumnNames; var indexOfId = columnNames.ToList().IndexOf("Id"); var indexOfName = columnNames.ToList().IndexOf("Name"); var indexOfSurname = columnNames.ToList().IndexOf("Surname"); var indexOfStartDate = columnNames.ToList().IndexOf("RegDate"); var indexOfClass = columnNames.ToList().IndexOf("Group"); foreach (var row in csvResult.Rows) { var volunteer = new VolunteerData() { Id = row[indexOfId], Name = row[indexOfName], Surname = row[indexOfSurname], StartDate = DateTime.Parse(row[indexOfStartDate], ci), ClassName = row[indexOfClass] }; resultList.Add(volunteer); } return(resultList); }
public void ReadData_SendCorrectFilePath_ShouldLoadData() { var filePath = "..\\..\\..\\Resources\\data.csv"; var expectedColumns = 4; var expectedRows = 10; var dataReader = new CsvDataReader(filePath); var loadedData = dataReader.ReadData(); Assert.AreEqual(expectedColumns, loadedData.Columns.Count); Assert.AreEqual(expectedRows, loadedData.Rows.Count); }
public List <VolunteerWorkingHoursData> GetVolunteersWorkingHours() { var resultList = new List <VolunteerWorkingHoursData>(); var dataReader = new CsvDataReader(); var csvResult = dataReader.ReadData(_filePath); var columnNames = csvResult.ColumnNames; var indexOfId = columnNames.ToList().IndexOf("Id"); var indexOfDateFrom = columnNames.ToList().IndexOf("From"); var indexOfDateTo = columnNames.ToList().IndexOf("To"); var ci = new CultureInfo("pl-PL"); foreach (var row in csvResult.Rows) { var volunteer = new VolunteerWorkingHoursData() { Id = row[indexOfId], DateFrom = DateTime.Parse(row[indexOfDateFrom], ci), DateTo = DateTime.Parse(row[indexOfDateTo], ci) }; resultList.Add(volunteer); } return(resultList); }