m-y*_*m-y 9 wpf unit-testing dependency-properties custom-controls
基本上,我正在寻找有关如何对WPF自定义控件进行单元测试的资源/指南.
在这个特定的实例中,我创建的自定义控件恰好扩展了Decorator类.它包装一个PasswordBox子项以将CLR密码属性公开为DependencyProperty.
public class BindablePasswordBox : Decorator
{
public BindablePasswordBox()
{
Child = new PasswordBox();
((PasswordBox)Child).PasswordChanged += this.PasswordChanged;
}
public static readonly DependencyProperty PasswordProperty =
DependencyProperty.Register("Password", typeof(String), typeof(BindablePasswordBox),
new FrameworkPropertyMetadata
{
BindsTwoWayByDefault = true,
DefaultUpdateSourceTrigger = UpdateSourceTrigger.LostFocus
});
public String Password
{
get { return (String)GetValue(PasswordProperty); }
set { SetValue(PasswordProperty, value); }
}
void PasswordChanged(Object sender, RoutedEventArgs e)
{
Password = ((PasswordBox)Child).Password;
}
}
Run Code Online (Sandbox Code Playgroud)
PS我正在使用内置的Visual Studio Testing Framework(Microsoft.VisualStudio.QualityTools.UnitTestFramework).
为了避免在内存中暴露明文密码的反对:我明白我通过在DependencyProperty中公开明文密码来反对微软的安全推理,但考虑到我能够使用Snoop从标准PasswordBox中公开明文密码再也找不到那么重要了.