public void ToSting_1Row() { const string expectedString = "A,1"; var table1 = new Table(expectedString); var result = table1.ToString(); Assert.That(result, Is.EqualTo(expectedString)); }
public void MapValuesFrom_OneValueFound() { var table1 = new Table("A,1"); var table2 = new Table("A"); table2.MapValuesFrom(table1); Assert.That(table2.Rows.First().Value, Is.EqualTo(1)); }
public void MapValuesFrom_MultipleKeys_FirstValueMapped() { var table1 = new Table("A,1\nA,2"); var table2 = new Table("A"); table2.MapValuesFrom(table1); Assert.That(table2.Rows.First().Value, Is.EqualTo(1)); }
public void MapValuesFrom_2ValuesFound() { var table1 = new Table("A,1\nB,2"); var table2 = new Table("A\nB"); table2.MapValuesFrom(table1); Assert.That(table2.Rows[0].Value, Is.EqualTo(1)); Assert.That(table2.Rows[1].Value, Is.EqualTo(2)); }
/// <summary> /// Maps the Values from provided value by the Keys. /// </summary> /// <param name="sourseTable">Sourse table.</param> public void MapValuesFrom(Table sourseTable) { try { Rows.ForEach( x => x.Value = sourseTable.Rows.First( y => y.Key.Equals(x.Key)).Value); } catch (InvalidOperationException) { throw new ApplicationException("Key not found in source Table"); } }
public void MapValuesFromError_KeyNotFound() { var table1 = new Table("A,1"); var table2 = new Table("B"); const string message = "Key not found in source Table"; try { table2.MapValuesFrom(table1); } catch (ApplicationException ex) { Assert.That(ex.Message, Is.EqualTo(message)); } }
/// <summary> /// Run the instance of application. /// </summary> public void Run() { try { if (_file1 == null && _file2 == null) GetFilesFromArgumets(); var table1 = new Table(FileHandler.ReadFile(_file1)); var table2 = new Table(FileHandler.ReadFile(_file2)); table2.MapValuesFrom(table1); FileHandler.WriteFile(_file2, table2.ToString()); } catch (ApplicationException ex) { Console.Write(ex.Message); return; } catch (Exception ex) { Console.WriteLine("Unexpected error occured: {0}", ex); return; } Console.Write("Values were successfully mapped from <{0}> to <{1}>", _file1, _file2); }
public void Constructor_2RowTable() { var table = new Table("A,1\nB,2"); Assert.That(table.Rows.Count, Is.EqualTo(2)); }
public void Constructor_1RowTable() { var table = new Table("A,1"); Assert.That(table.Rows.Count, Is.EqualTo(1)); }