I have used Mock to unit test ViewModels. My problem is with the views. I have to test the KeyUp event of a textbox.
In my ViewTest class, I have the following code.
View1 ViewTarget = null;
[TestInitialize()]
public void MyTestInitialize()
{
ViewTarget = new Veiw1();
}
[TestMethod]
public void searchTextBox_KeyUpTest()
{
TextBox element = new TextBox();
element.RaiseEvent(
new KeyEventArgs(
Keyboard.PrimaryDevice,
Keyboard.PrimaryDevice.ActiveSource,
0,
Key.Enter) { RoutedEvent = Keyboard.KeyUpEvent }
);
}
What do I pass as the input source? Keyboard.PrimaryDevice.ActiveSource returns null. I tried mocking the PresentationSource for input source but throws a ProxyGenerationException.
Aucun commentaire:
Enregistrer un commentaire