【问题标题】:How do I assert activity counts in a workflow trace after a unit test?如何在单元测试后在工作流跟踪中断言活动计数?
【发布时间】:2015-01-22 20:53:03
【问题描述】:

我正在使用 the Unit testing Nuget package 对 WF4 服务进行单元测试。有一个功能可以断言测试结束跟踪信息中存在或不存在东西。

考虑以下单元测试代码:

WorkflowServiceTestHost host = null;
using (host = CreateHost())
{
    var proxy = new ServiceClient(Binding, ServiceAddress);
// Call receive points in the workflow

}
finally
{
    host.Tracking.Trace();
    // I would like to assert stuff like the WF did not abort
    // For now, I would just like to assert that there are a 
    // certain number of invocations of a specific activity.
    // I can find no examples of how to call this:
    host.Tracking.Assert.ExistsCount(?????what goes here???);
}

如何拨打ExistsCount()?原型如下所示:

public void ExistsCount<TRecord>(Predicate<TRecord> predicate, int count, string message = null) where TRecord : TrackingRecord

但我找不到任何示例或文档来了解 predicate 的预期内容。

【问题讨论】:

    标签: unit-testing workflow-foundation-4 workflowservice


    【解决方案1】:

    好吧,事实证明,处理这个问题的最简单方法不是通过

    host.Tracking.Assert.ExistsCount()
    

    你更想看看收藏

    host.Tracking.Records
    

    然后在它们上使用 LINQ 来确认您认为应该存在的内容。例如,如果您希望工作流调用 ABC 活动类五次,您可以按如下方式进行检查:

    var trackingRecords = host.Tracking.Records.ToArray();
    var myRecords = trackingRecords.OfType<ActivityStateRecord>()
        .Where(
            r =>
                r.Activity != null && r.State == "Executing" &&
                r.Activity.TypeName.EndsWith("ABC")).ToArray();
    Assert.AreEqual(5,myRecords.Length);
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2021-12-05
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多