public void Munro_MissingGridRefMapping_ExpectedMunro() { var expected = new Munro() { Name = "Munro", Height = 1000, HillCategory = Munro.CategoryType.MUN, GridReference = null }; var values = new List <string>() { "Munro", "1000", "MUN", "Ref" }; var map = new Dictionary <int, ColumnToPropertyPair> { { 0, new ColumnToPropertyPair("Name", "Name") }, { 1, new ColumnToPropertyPair("Height (m)", "Height") }, { 2, new ColumnToPropertyPair("Post 1997", "HillCategory") }, }; var actual = new Munro(values, map); Assert.AreEqual(expected, actual); }
public MunroFiltteringResult PopulateDataToObject(List <string> headerList, List <string[]> dataList) { var results = new MunroFiltteringResult(); MunroData = new List <Munro>(); var tempIndexHolder = new int[4]; for (var i = 0; i < headerList.Count; i++) { if (headerList[i].Equals("Name")) { tempIndexHolder[0] = i; } if (headerList[i].Equals("Height (m)")) { tempIndexHolder[1] = i; } if (headerList[i].Equals("post 1997")) { tempIndexHolder[2] = i; } if (headerList[i].Equals("Grid Ref")) { tempIndexHolder[3] = i; } } try { foreach (var element in dataList) { var munroObject = new Munro() { Name = element[tempIndexHolder[0]], Height = Convert.ToInt32(element[tempIndexHolder[1]]), Category = element[tempIndexHolder[2]], GridReference = element[tempIndexHolder[3]] }; MunroData.Add(munroObject); } results.MunroList = MunroData; } catch (Exception ex) { Debug.WriteLine("Convert Exception:" + ex.Message); Debug.WriteLine("Convert Exception:" + ex.StackTrace); results.Error = ex.Message; } return(results); }
public void Munro_InvalidHeight_ThrowArgumentException(params string[] values) { var munro = new Munro(); var map = new Dictionary <int, ColumnToPropertyPair> { { 0, new ColumnToPropertyPair("Name", "Name") }, { 1, new ColumnToPropertyPair("Height (m)", "Height") }, { 2, new ColumnToPropertyPair("Post 1997", "HillCategory") }, { 3, new ColumnToPropertyPair("Grid Ref", "GridReference") } }; var ex = Assert.Throws <ArgumentException>(() => new Munro(values.ToList(), map)); Assert.AreEqual(nameof(munro.Height), ex.ParamName); }
public void Assign_Parameters_On_Construction() { // Arrange const int id = 5; const string name = "Test"; const decimal heightMeters = 1.1m; const string gridRef = "1234567"; const MunroType munroType = MunroType.MUN; // Act var sut = new Munro(id, name, heightMeters, gridRef, munroType); // Assert Assert.Equal(id, sut.Id); Assert.Equal(name, sut.Name); Assert.Equal(heightMeters, sut.HeightMeters); Assert.Equal(gridRef, sut.GridRef); Assert.Equal(munroType, sut.MunroType); }
/// <summary> /// Create a <see cref="Munro"/> object parsing one line of the CSV file /// </summary> /// <param name="line">String containing the values of one record from the CSV file</param> /// <returns><see cref="Munro"/> object containing the corresponding values based on the mapping</returns> private Munro CreateMunro(string line) { try { Regex CSVParser = new Regex(",(?=(?:[^\"]*\"[^\"]*\")*(?![^\"]*\"))"); var values = new List <string>(CSVParser.Split(line)); var munro = new Munro(values, _columnsMap); return(munro); } catch (ArgumentException ex) { Console.WriteLine(ex.Message); return(null); } catch (Exception e) { throw e; } }
public void Munro_MissingHeightMapping_ThrowArgumentException() { var munro = new Munro(); var values = new List <string>() { "Munro", "1000", "MUN", "Ref" }; var map = new Dictionary <int, ColumnToPropertyPair> { { 0, new ColumnToPropertyPair("Name", "Name") }, { 2, new ColumnToPropertyPair("Post 1997", "HillCategory") }, { 3, new ColumnToPropertyPair("Grid Ref", "GridReference") } }; var ex = Assert.Throws <ArgumentException>(() => new Munro(values, map)); Assert.AreEqual(nameof(munro.Height), ex.ParamName); }
public void Munro_ValidValues_CreateExpectedMunro(params string[] values) { var expected = new Munro() { Name = values[0], Height = double.Parse(values[1]), HillCategory = (Munro.CategoryType)Enum.Parse(typeof(Munro.CategoryType), values[2]), GridReference = values[3] }; var map = new Dictionary <int, ColumnToPropertyPair> { { 0, new ColumnToPropertyPair("Name", "Name") }, { 1, new ColumnToPropertyPair("Height (m)", "Height") }, { 2, new ColumnToPropertyPair("Post 1997", "HillCategory") }, { 3, new ColumnToPropertyPair("Grid Ref", "GridReference") } }; var actual = new Munro(values.ToList(), map); Assert.AreEqual(expected, actual); }