小编Yan*_*nik的帖子

Moq - mock.Raise应该在没有安装程序的情况下在测试单元中引发事件

我有一个演示者类,它附加了注入视图的事件.现在我想测试演示者对事件的正确反应.

这是视图界面IView:

public interface IView 
{
    event EventHandler MyEvent;
    void UpdateView(string test);
}
Run Code Online (Sandbox Code Playgroud)

这是实现IView的视图

public partial class MyView : IView
{
    public event EventHandler MyEvent;

    public MyView()
    {
        this.combo.SelectedIndexChanged += this.OnSelectedIndexChanged;
    }

    public void UpdateView(string test)
    {
        this.textBox.Text = test;
    }

    private OnSelectedIndexChanged(Object sender, EventArgs e)
    {
        if (this.MyEvent != null)
        {
            this.MyEvent(sender, e);
        }
    }
}
Run Code Online (Sandbox Code Playgroud)

这是受测试的主持人:

public class MyPresenter
{
    private IView _view;
    public MyPresenter(IView view)
    {
        this._view = view;
        this._view.MyEvent += this.OnMyEvent;
    }

    private void OnMyEvent(Object sender, …
Run Code Online (Sandbox Code Playgroud)

c# tdd moq

33
推荐指数
1
解决办法
4万
查看次数

WPF - Task.Run(()=> window.ShowDialog)失败

我必须实施忙碌指示和进度报告.约束是,我必须使用提供的控制库,它提供了一个进度报告窗口.

以下代码工作正常,但不会阻止UI,这在某些时候是必需的.

private async void StartLongRunningTask2Sync() {
var wndHandle = Application.Current.Windows.OfType<Window>().SingleOrDefault(x => x.IsActive);
if (wndHandle == null)
{
    return;
}

IntPtr windowHandle = new WindowInteropHelper(wndHandle).Handle;
var progressWindow = new ProgressBarCustomized(windowHandle)
{
    Value = 0, CanCancel = true, CanRetry = false, Thumbnail = null, IsIndeterminate = true
};
progressWindow.Show();

await Task.Run(() => this.longRunningTaskComponent.DoLongRunningTask(this.taskIterations, this.iterationSleepTime));
progressWindow.Close();
Run Code Online (Sandbox Code Playgroud)

}

阻止UI的以下代码到目前为止可以打开对话框,但是在对话框再次关闭之前,长时间运行的任务永远不会执行:

private async void StartLongRunningTask2Sync() {
var wndHandle = Application.Current.Windows.OfType<Window>().SingleOrDefault(x => x.IsActive);
if (wndHandle == null)
{
    return;
}

IntPtr windowHandle = new WindowInteropHelper(wndHandle).Handle;
var …
Run Code Online (Sandbox Code Playgroud)

wpf modal-dialog thread-safety

3
推荐指数
1
解决办法
5762
查看次数

标签 统计

c# ×1

modal-dialog ×1

moq ×1

tdd ×1

thread-safety ×1

wpf ×1