using System;
using System.Collections.Generic;
using System.Text;
[Serializable]
public class ColumnDataField
{
#region Fields
private int _columnIndex;
private string _dataFields;
#endregion Fields
#region Properties
/// <summary>
/// Column index
/// </summary>
public int ColumnIndex
{
get { return _columnIndex; }
set { _columnIndex = value; }
}
/// <summary>
/// Data fields
/// </summary>
public string DataFields
{
get { return _dataFields; }
set { _dataFields = value; }
}
/// <summary>
/// Convert DataFields string to data field list
/// </summary>
internal List<String> DataFieldList
{
get
{
if (string.IsNullOrWhiteSpace(DataFields)) return new List<String>();
string[] _array = DataFields.Split(new Char[] { ',' }, StringSplitOptions.RemoveEmptyEntries);
List<String> _fields = new List<String>(_array);
for (int _i = _fields.Count - 1; _i >= 0; _i--)
{
_fields[_i] = _fields[_i].Trim();
if (string.IsNullOrWhiteSpace(_fields[_i])) _fields.RemoveAt(_i);
}
return _fields;
}
set
{
StringBuilder _buffer = new StringBuilder();
foreach (string _field in value)
{
if (_buffer.Length > 0) _buffer.Append(",");
_buffer.Append(_field);
}
DataFields = _buffer.ToString();
}
}
#endregion Properties
}
}
我是 C# 中的实习生单元测试,所以请放轻松。
我的其他项目没有太多问题,但我似乎无法弄清楚我应该如何对内部列表进行单元测试。
这是我到目前为止的单元测试代码:
[TestMethod]
public void DataFields_Test()
{
ColumnDataField questionText = new ColumnDataField();
questionText.DataFields = "test";
string expected = "test";
string actual = questionText.DataFields;
Assert.AreEqual(expected, actual);
}
所以这将运行 DataFields 属性,但除此之外它不会遍历任何其他代码。我已经在网上搜索了几天,试图找出解决这个问题的最佳方法。我不需要确切地告诉我该怎么做,但我们将不胜感激。