我对名为 MyCodeActivity 的 WF 代码事件进行了以下单元测试:
[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");
}
当我运行测试时,出现以下异常
'Literal< MyComplexObject>': Literal only supports value types and the immutable type System.String. The type MyComplexObject cannot be used as a literal.
最佳答案
要解决眼前的问题:
MyComplexObject = _complexObject
至
MyComplexObject = new InArgument<MyComplexObject>((ctx) => _complexObject)
进一步阅读:http://msdn.microsoft.com/en-us/library/ee358749.aspx .
注意:您还应该使用 Microsoft.Activities.UnitTesting NuGet 上提供了包。它使 IOC 变得更容易(因为 WF 使用服务定位器模式而不是依赖注入(inject))
关于c#-4.0 - Workflow Foundation - Literal 仅支持值类型和不可变类型 System.String,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16554084/