Workflow Foundation - Literal only supports value types and the immutable System.String type

I have the following unit test for WF code 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 of System.String. The MyComplexObject type cannot be used as a literal.

+7
source share
1 answer

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. This makes IOC much easier (since WF works with the Locator Service pattern, not the Injection Dependency)

+11
source

All Articles