我是单位测试我的一个功能.这是我的代码:
public void TestLabels() { //Step 1: Creating a mock table with columns exactly like in the real table. DataTable table = new DataTable(); DataRow mydatarow; mydatarow = table.NewRow(); //Step 2: Adding the row as same as the Real Data! mydatarow["Name"] = "Test"; mydatarow["Address"] = "00000 ST."; mydatarow["ZipCode"] = "77665"; mydatarow["Tracking#"] = ""; table.Rows.Add(mydatarow); foreach (DataColumn column in table.Columns) Console.WriteLine(column.ColumnName); //Step 3: Call method we are testing. var updateTable = IceTechUPSClient.Instance.CreateLabels(table); foreach (DataRow row in updateTable.Rows) { var trackingNumber = row["Tracking#"].ToString(); Assert.IsFalse(String.IsNullOrWhiteSpace(trackingNumber),"Expecting tracking number generated for every row!"); Assert.IsTrue(File.Exists(trackingNumber + ".gif")); } }
现在我收到一个错误:列“名称”不属于表.正如你所看到的,我在这里指定了列名“Name”,并添加了该行.那么为什么我得到这个错误?任何帮助?
谢谢!