I intend to test only one sequence of a workflow (it is not a separate CodeActivity). Is there a way I can invoke only the desired Sequence and pass in the required arguments?
Thanks for your interest.
Answer is: no you can't.
At least not efficiently. You can do a bunch of thinks with the workflow's XAML. Extract the inner sequence comes to my mind but, please, don't do it!
What about if your sequence is using local variables assigned on the outer scope? That's just about one think that can go wrong while testing an isolated inner sequence.
Anyway, why would you want to do something like that? That's just like unit testing a method call which is inside another method. Either you call the outer method (the workflow itself) or you isolate the inner method (the sequence) to be able to test it.
Edit:
Ok, if you want to go along with that, and counting you've a XAML with that huge workflow, maybe you can get away with something like this:
Load your XAML to an activity:
var activity = ActivityXamlServices.Load("c:\hugeworkflow.xaml");
Having your serialized activity, and counting that you know where inner sequence is, search for it inside activity
. Lets imagine that that sequence is inside another sequence (which is the workflow root):
var rootSequence = activity as Sequence;
var innerSequence = rootSequence
.Activities
.FirstOrDefault(a => a is Sequence) as Sequence;
Now you can execute the inner sequence like this:
var arguments = new Dictionary<string, object>
{
{ "IntArgument", 10 },
{ "StringArgument", "hello world" }
};
WorkflowInvoker.Invoke(innerSequence, arguments);
How can you assert something from a sequence, I don't know.
Haven't tested any of this code so something might be missing but you get the idea.