【发布时间】:2014-01-29 10:49:55
【问题描述】:
我正在为一个看起来有点像这样的 DataGridViewCell 类编写单元测试(在 VS2010 中):
public class MyCell : DataGridViewCell
{
protected override object GetFormattedValue(object value, int rowIndex, ref System.Windows.Forms.DataGridViewCellStyle cellStyle, System.ComponentModel.TypeConverter valueTypeConverter, System.ComponentModel.TypeConverter formattedValueTypeConverter, System.Windows.Forms.DataGridViewDataErrorContexts context)
{
return MyCustomFormatting(value);
}
private object MyCustomFormatting(object value)
{
var formattedValue = string.Empty;
// ... logic to test here
return FormattedValue;
}
}
我想测试公共属性 .FormattedValue 是否设置正确。但是,如果正在测试的单元格没有设置 DataGridView,这总是返回 null(我使用 Telerik 的 JustDecompile refection 工具检查了这一点)。
我显然可以绕过这一点,只使用访问器来访问受保护的或私有的方法,但访问器在 VS2012 之后已被弃用。
如何在不使用访问器的情况下对该逻辑进行单元测试?
【问题讨论】:
标签: c# unit-testing datagridview mstest accessor