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

北慕城南 提交于 2019-12-19 18:50:18

问题


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.


回答1:


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)



来源:https://stackoverflow.com/questions/16554084/workflow-foundation-literal-only-supports-value-types-and-the-immutable-type-s

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!