Workflow Foundation

编程入门 行业动态 更新时间:2024-10-24 01:52:18
本文介绍了Workflow Foundation - Literal仅支持值类型和不可变类型System.String的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我有一个名为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

本文发布于:2023-11-12 23:59:26,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1582852.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:Workflow   Foundation

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!