我有一个名为MyCodeActivity的WF代码活动的单元测试:
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只支持值类型和不可变类型System.String。类型MyComplexObject不能用作文字。
'Literal< MyComplexObject>': Literal only supports value types and the immutable type System.String. The type MyComplexObject cannot be used as a literal.
推荐答案
/ p>
To fix the immediate problem:
MyComplexObject = _complexObject到
MyComplexObject = new InArgument<MyComplexObject>((ctx) => _complexObject)更多阅读: msdn.microsoft/en-us/library/ee358749.aspx 。
注意: strong>您还应该使用NuGet上提供的 Microsoft.Activities.UnitTesting 软件包。它使IOC更容易(看到WF工作与服务定位器模式,而不是依赖注入)
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)
更多推荐
Workflow Foundation
发布评论