9
基本上,我正在尋找關於如何單元測試WPF自定義控件的資源/指南。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;
}
}
P.S.我正在使用內置的Visual Studio測試框架(Microsoft.VisualStudio.QualityTools.UnitTestFramework
)。
要避免遇到有關內存暴露明文口令反彈:我明白,我會反對微軟的安全推理由一個DependencyProperty暴露明文密碼,但考慮到我能夠使用Snoop揭露來自標準PasswordBox的明文密碼我不覺得這一切很重要。
UI自動化是不一樣的單元測試。 – 2015-04-17 18:36:48