Basically, I'm looking for resources/guides on how to unit test a WPF Custom Control.
In this particular instance, the custom control I created happens to extend the Decorator
class. It wraps a PasswordBox child to expose the CLR Password Property as a 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. I'm using the built-in Visual Studio Testing Framework (Microsoft.VisualStudio.QualityTools.UnitTestFramework
).
To avoid getting backlash about exposing plaintext passwords in memory: I understand that I'm going against Microsoft's security reasoning by exposing the plaintext password in a DependencyProperty, but considering that I was able to use Snoop to expose the plaintext password from a standard PasswordBox I don't find it all that important anymore.
You can use UI Automation, see the following links for more info:
UI Automation Overview
UI Automation of a WPF Custom Control
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With