浏览代码

test datacolumn caption handling

Remo 11 月之前
父节点
当前提交
b122744c60
共有 2 个文件被更改,包括 24 次插入1 次删除
  1. 1 1
      Terminal.Gui/Views/TableView/DataTableSource.cs
  2. 23 0
      UnitTests/Views/TableViewTests.cs

+ 1 - 1
Terminal.Gui/Views/TableView/DataTableSource.cs

@@ -25,5 +25,5 @@ public class DataTableSource : ITableSource
     public int Columns => DataTable.Columns.Count;
     public int Columns => DataTable.Columns.Count;
 
 
     /// <inheritdoc/>
     /// <inheritdoc/>
-    public string [] ColumnNames => DataTable.Columns.Cast<DataColumn> ().Select (c => c.Caption ?? c.ColumnName).ToArray ();
+    public string [] ColumnNames => DataTable.Columns.Cast<DataColumn> ().Select (c => c.Caption).ToArray ();
 }
 }

+ 23 - 0
UnitTests/Views/TableViewTests.cs

@@ -3169,6 +3169,29 @@ A B C
         Assert.Equal (8, tableView.GetAllSelectedCells ().Count ());
         Assert.Equal (8, tableView.GetAllSelectedCells ().Count ());
     }
     }
 
 
+    [Fact]
+    public void TestDataColumnCaption()
+    {
+        var tableView = new TableView ();
+
+        var dt = new DataTable ();
+        dt.Columns.Add (new DataColumn ()
+        {
+            Caption = "Caption 1",
+            ColumnName = "Column Name 1"
+        });
+        dt.Columns.Add (new DataColumn ()
+        {
+            ColumnName = "Column Name 2"
+        });
+
+        var dts = new DataTableSource (dt);
+        var cn = dts.ColumnNames;
+
+        Assert.Equal ("Caption 1", cn [0]);
+        Assert.Equal ("Column Name 2", cn [1]);
+    }
+
     private TableView GetABCDEFTableView (out DataTable dt)
     private TableView GetABCDEFTableView (out DataTable dt)
     {
     {
         var tableView = new TableView ();
         var tableView = new TableView ();