2015-01-22 10 views
0

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 예상되는 이해하는 것이 더 예 또는 문서를 찾을 수 없습니다 : 프로토 타입은 다음과 같습니다.

답변

0

글쎄, 그것은이 처리하는 가장 쉬운 방법은 당신이 컬렉션

host.Tracking.Records 

보고 후 무엇을 확인하기 위해 그들에 LINQ를 사용할

오히려
host.Tracking.Assert.ExistsCount() 

를 통해 아니라고 밝혀 당신은 거기에 있어야한다고 생각합니다. 예를 들어 워크 플로가 ABC 활동 등급으로 5 번 전화를 걸기를 기대하는 경우 다음과 같이 확인할 수 있습니다.

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);