相关疑难解决方法(0)

如何以编程方式在C#中生成按键事件?

如何以编程方式创建一个模拟键盘上按键的事件?

.net c# wpf keyboard-events

104
推荐指数
5
解决办法
14万
查看次数

对文本框行为进行单元测试

我在对我编写的行为进行单元测试时遇到问题。行为如下:

NumericTextBoxBehavior : Behavior<TextBox>
{
 //handles few events like TextChanged ,PreviewTextInput , PreviewKeyDown , PreviewLostKeyboardFocus 
//to give make it accept numeric values only

}
Run Code Online (Sandbox Code Playgroud)

在单元测试相同的同时我编写了这段代码

TextBox textBoxInvoker = new TextBox();
NumericTextBoxBehavior target = new NumericTextBoxBehavior();
System.Windows.Interactivity.Interaction.GetBehaviors(TextBoxInvoker).Add(target);
Run Code Online (Sandbox Code Playgroud)

现在要提出这个事件我必须打电话

textBoxInvoker.RaiseEvent(routedEventArgs)
Run Code Online (Sandbox Code Playgroud)

此路由事件参数又将路由事件作为参数。

请帮助我如何创建模拟 RoutedEventArgs 来引发事件并进一步对行为进行单元测试。

提前致谢。

c# wpf textbox unit-testing behavior

5
推荐指数
1
解决办法
3772
查看次数

标签 统计

c# ×2

wpf ×2

.net ×1

behavior ×1

keyboard-events ×1

textbox ×1

unit-testing ×1