public void TestPrintValidTable() { var items = new[] { new MyFormatItem { Name = "Bob", Age = 21 }, new MyFormatItem { Name = "Alice", Age = 5 } }; var tableFormatter = new TableFormater <MyFormatItem>() .AddColumn("Name", i => i.Name, c => c) .AddColumn("Age", i => i.Age, c => c.ToString("D")); var result = tableFormatter.CreateTable(items); var expectedTable = new StringBuilder() .AppendLine("| Name | Age |") .AppendLine("| Bob | 21 |") .Append("| Alice | 5 |"); Assert.AreEqual(expectedTable.ToString(), result); }
public void TestAddColumnWithValidSelectors() { var tableFormatter = new TableFormater<MyFormatItem>(); tableFormatter.AddColumn("BadColumn", i => "Hello", i => i); Assert.AreEqual(1, tableFormatter.ColumnCount); }
public void TestAddColumnWithValidSelectors() { var tableFormatter = new TableFormater <MyFormatItem>(); tableFormatter.AddColumn("BadColumn", i => "Hello", i => i); Assert.AreEqual(1, tableFormatter.ColumnCount); }
public void TestPrintTableWithNoRowsReturnsJustHeaders() { var tableFormatter = new TableFormater <MyFormatItem>() .AddColumn("Name", i => i.Name, c => c) .AddColumn("Age", i => i.Age, c => c.ToString("D")); var result = tableFormatter.CreateTable(new List <MyFormatItem>(0)); Assert.AreEqual("| Name | Age |", result); }
public void TestPrintTableWithRowExclusionEnableReturnsNullIfNoRowsExist() { var tableFormatter = new TableFormater <MyFormatItem>() .ExcludePrintingIfNoRows() .AddColumn("Name", i => i.Name, c => c) .AddColumn("Age", i => i.Age, c => c.ToString("D")); var result = tableFormatter.CreateTable(new List <MyFormatItem>(0)); Assert.IsNull(result); }
public void TestAddColumnWithNullValueSelectorThrowsException() { var tableFormatter = new TableFormater<MyFormatItem>(); try { tableFormatter.AddColumn("BadColumn", i => "Hello", null); } catch (ArgumentNullException ex) { Assert.AreEqual("valueSelector", ex.ParamName); throw; } }
/// <summary> /// Gets the comparison table. /// </summary> /// <returns>The formatted comparison table.</returns> internal string GetComparisonTable() { var tableFormatter = new TableFormater <ValidationItemResult>(); foreach (var itemValidation in this.validations) { tableFormatter.AddColumn( itemValidation.ToString(), i => i.PropertyResults.First(p => p.Validation == itemValidation), f => f.FieldExists ? f.ActualValue : "<NOT FOUND>"); } return(tableFormatter.CreateTable(this.CheckedItems)); }
/// <summary> /// Gets the comparison table. /// </summary> /// <returns>The formatted comparison table.</returns> internal string GetComparisonTable() { var tableFormatter = new TableFormater<ValidationItemResult>(); foreach (var itemValidation in this.validations) { tableFormatter.AddColumn( itemValidation.ToString(), i => i.PropertyResults.First(p => p.Validation == itemValidation), f => f.FieldExists ? f.ActualValue : "<NOT FOUND>"); } return tableFormatter.CreateTable(this.CheckedItems); }
public void TestAddColumnWithNullValueSelectorThrowsException() { var tableFormatter = new TableFormater <MyFormatItem>(); try { tableFormatter.AddColumn("BadColumn", i => "Hello", null); } catch (ArgumentNullException ex) { Assert.AreEqual("valueSelector", ex.ParamName); throw; } }
/// <summary> /// Gets the comparison table displayed by rule. /// </summary> /// <returns>The formatted table.</returns> internal string GetComparisonTableByRule() { if (this.CheckedItems.Count != 1) { throw new InvalidOperationException("Only one checked item can exist to process items by rule."); } var properties = this.CheckedItems.First().PropertyResults; var tableFormatter = new TableFormater <ValidationItemResult.PropertyResult>() .AddColumn("Field", p => p, p => p.Validation.RawFieldName, CheckFieldExists) .AddColumn("Rule", p => p.Validation.RawComparisonType, p => p) .AddColumn("Value", p => p, p => p.Validation.RawComparisonValue, CheckFieldValue); return(tableFormatter.CreateTable(properties)); }
/// <summary> /// Gets the comparison table displayed by rule. /// </summary> /// <returns>The formatted table.</returns> internal string GetComparisonTableByRule() { if (this.CheckedItems.Count != 1) { throw new InvalidOperationException("Only one checked item can exist to process items by rule."); } var properties = this.CheckedItems.First().PropertyResults; var tableFormatter = new TableFormater<ValidationItemResult.PropertyResult>() .AddColumn("Field", p => p, p => p.Validation.RawFieldName, CheckFieldExists) .AddColumn("Rule", p => p.Validation.RawComparisonType, p => p) .AddColumn("Value", p => p, p => p.Validation.RawComparisonValue, CheckFieldValue); return tableFormatter.CreateTable(properties); }
public void TestAddColumnWithNullCellSelectorThrowsException() { var tableFormatter = new TableFormater <MyFormatItem>(); Assert.Throws <ArgumentNullException>(() => { try { tableFormatter.AddColumn <string>("BadColumn", null, null); } catch (ArgumentNullException ex) { Assert.AreEqual("cellSelector", ex.ParamName); throw; } }); }
public void TestPrintValidTable() { var items = new[] { new MyFormatItem { Name = "Bob", Age = 21 }, new MyFormatItem { Name = "Alice", Age = 5 } }; var tableFormatter = new TableFormater<MyFormatItem>() .AddColumn("Name", i => i.Name, c => c) .AddColumn("Age", i => i.Age, c => c.ToString("D")); var result = tableFormatter.CreateTable(items); var expectedTable = new StringBuilder() .AppendLine("| Name | Age |") .AppendLine("| Bob | 21 |") .Append("| Alice | 5 |"); Assert.AreEqual(expectedTable.ToString(), result); }
public void TestPrintTableWithNoRowsReturnsJustHeaders() { var tableFormatter = new TableFormater<MyFormatItem>() .AddColumn("Name", i => i.Name, c => c) .AddColumn("Age", i => i.Age, c => c.ToString("D")); var result = tableFormatter.CreateTable(new List<MyFormatItem>(0)); Assert.AreEqual("| Name | Age |", result); }
public void TestPrintTableWithRowExclusionEnableReturnsNullIfNoRowsExist() { var tableFormatter = new TableFormater<MyFormatItem>() .ExcludePrintingIfNoRows() .AddColumn("Name", i => i.Name, c => c) .AddColumn("Age", i => i.Age, c => c.ToString("D")); var result = tableFormatter.CreateTable(new List<MyFormatItem>(0)); Assert.IsNull(result); }