使用 Specflow for Silverlight 处理异步

发布于 2024-09-12 01:43:56 字数 303 浏览 2 评论 0原文

Silverlight 单元测试框架定义了处理异步调用的流程(从 Microsoft.Silverlight.Testing.SilverlightTest 派生测试类,添加异步属性,使用 EnqueueXXX 方法。)考虑到 SpecFlow 在测试类和步骤之间呈现的分离:

  • 可以这些工具是否可以用来等待测试中异步行为的 Silverlight 方法调用(例如进行 Web 服务调用)?
  • 如果不能,SpecFlow 测试文件中处理此行为的指导是什么? (也许使用在事件处理程序中被触发的 AutoResetEvent 并等待它?)

The Silverlight Unit test Framework defines a process for dealing with Async calls (derive test class from Microsoft.Silverlight.Testing.SilverlightTest, add Asynchronous attribute, use EnqueueXXX methods.) Considering the separation that SpecFlow presents between the test class and the steps:

  • Can these tools be brought to bear to wait on Silverlight method calls within the test that behave asynchronously (such as making web service calls)?
  • If they cannot, what is the guidance for handling this behavior in SpecFlow test files? (Perhaps use an AutoResetEvent that gets tripped in an event handler and wait on it?)

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

旧街凉风 2024-09-19 01:43:56

使用 AutoResetEvent 不起作用,因为 WaitOne 调用会阻塞 UI 线程。即使在对数据服务进行异步调用时,Silverlight 也会使用 UI 线程(请参阅这篇文章 - Thead 被使用 WebClient 和 ManualResetEvent 阻止),因此 WaitOne 实际上会停止调用服务。

Using an AutoResetEvent won't work because the WaitOne call will block the UI thread. Silverlight makes use of the UI thread even when making async calls to a data services (see this post - Thead is blocked using WebClient and ManualResetEvent) so the WaitOne will actually stop the service from being called.

半葬歌 2024-09-19 01:43:56

我知道这可能已经太晚了,但就这样吧。

对于 silverlight 异步调用,您可以使用 Specflow AsyncContext api

https://github。 com/techtalk/SpecFlow/wiki/Testing-Silverlight-Asynchronous-Code

当它在这里开发时,我在博客上介绍了这一点

http://rburnham.wordpress.com/2011/05/13/testing-silverlight-asynchronous-code-with-specflow/

它有助于解释这个概念。

I know this is probably to late but here goes.

For silverlight async calls you can use the Specflow AsyncContext api

https://github.com/techtalk/SpecFlow/wiki/Testing-Silverlight-Asynchronous-Code

I blogged about this when it was being developed here

http://rburnham.wordpress.com/2011/05/13/testing-silverlight-asynchronous-code-with-specflow/

It helps to explain the concept.

几味少女 2024-09-19 01:43:56

我想每个看过并投票支持这个问题的人都在等待有人给出一个很棒的、优雅的答案,但看起来这不会发生在这里。为了帮助现在需要可用答案的其他人...

我对其他单元测试情况所做的是使用 AutoResetEvent 就像您在问题中提到的那样:

AutoResetEvent MyAutoReset = new AutoResetEvent();
[TestMethod]
public void MyTestMethod()
{
   var MyItem.GetItem(x => 
      {
         // Return handler
         MyAutoReset.Set();
      });
   MyAutoReset.WaitOne(5000, false));
}

显然,这种方法需要考虑一些事情,但它得到了想法跨越。

I guess everyone who has looked at and upvoted this question has been waiting for someone to have an awesome, elegant answer, but it does not look that that will happen here. To help others who need a usable answer now...

What I have done with other unit-testing situations is use an AutoResetEvent like you have mentioned in the question:

AutoResetEvent MyAutoReset = new AutoResetEvent();
[TestMethod]
public void MyTestMethod()
{
   var MyItem.GetItem(x => 
      {
         // Return handler
         MyAutoReset.Set();
      });
   MyAutoReset.WaitOne(5000, false));
}

Obviously there are a few things to consider with this approach, but it gets the idea across.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文