I have the following unit test for a WF code activity called MyCodeActivity:
[ExpectedException(typeof(ArgumentException))]
[TestMethod]
public void ShouldRequireParam()
{
//arrange
var invoker = new WorkflowInvoker(new MyCodeActivity()
{
MyInt = 2,
MyComplexObject = _complexObject
});
//act
invoker.Invoke();
//assert
Assert.Fail("Expected ArgumentException");
}
When I run the test I get the following exception
'Literal< MyComplexObject>': Literal only supports value types and the immutable type System.String. The type MyComplexObject cannot be used as a literal.
This includes workflow arguments passed to the root activity. In imperative code, workflow arguments are specified as properties on a new CLR type, and in XAML they are declared by using x:Class and x:Member. Because there is no new CLR type created when a workflow definition is created as a tree of in-memory objects, arguments cannot be added.
In imperative code, workflow arguments are specified as properties on a new CLR type, and in XAML they are declared by using x:Class and x:Member. Because there is no new CLR type created when a workflow definition is created as a tree of in-memory objects, arguments cannot be added. However, arguments can be added to a DynamicActivity.
A workflow definition is a tree of configured activity objects. This tree of activities can be defined many ways, including by hand-editing XAML or by using the Workflow Designer to produce XAML. Use of XAML, however, is not a requirement. Workflow definitions can also be created programmatically.
C# expressions must be compiled before the workflow containing them is invoked. If the C# expressions are not compiled, a NotSupportedException is thrown when the workflow is invoked with a message similar to the following: Expression Activity type 'CSharpValue`1' requires compilation in order to run.
To fix the immediate problem:
MyComplexObject = _complexObject
to
MyComplexObject = new InArgument<MyComplexObject>((ctx) => _complexObject)
Further reading : http://msdn.microsoft.com/en-us/library/ee358749.aspx .
Note: You should also use the Microsoft.Activities.UnitTesting package available on NuGet. It makes IOC alot easier (seeing as WF works with the Service Locator pattern and not Dependency Injection)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With