在單元測試中,我通過自定義活動的組件的構造函數爲當地組裝 VAR xamlInjector =新XamlInjector(「CreditAtRenewalFlow.xaml」的typeof (CreateFollowUp).Assembly);解決方案「XamlInjector,無法創建未知類型的錯誤」不工作
CreateFollowUp是AsynCodeActivity
我得到錯誤「 '在解析規則 '元素:: = EmptyElement '意外' PROPERTYELEMENT |。(起始元素ElementBody)'。'行號「2」和行位置「4」。「在執行以下行
var host = WorkflowInvokerTest.Create(xamlInjector.GetActivity());
單元測試的樣品是[TestMethod的] [DeploymentItem(@ 「SRC \ ProcessFlows \ Activity1.xaml」)] 公共無效Activity1Test() {
var xamlInjector = new XamlInjector("Activity1.xaml", typeof(CreateFollowUp).Assembly); xamlInjector.ReplaceAll(typeof(CreateFollowUp), typeof (MockCreateFollowUp)); var mockExternalServiceManager = new Mock<IExternalServices>(); mockExternalServiceManager.Setup(x => x.CreateFollowUp()).Verifiable(); var host = WorkflowInvokerTest.Create(xamlInjector.GetActivity()); dynamic parameterValues1 = new WorkflowArguments(); parameterValues1.value1 = mockExternalServiceManager.Object; IDictionary<string, object> dictionary = host.TestActivity(); }
並且CreateFollowUp如下給出
public sealed class CreateFollowUp:AsyncCodeActivity {
[RequiredArgument] public InArgument ExternalServices {get;組; }protected override IAsyncResult BeginExecute(AsyncCodeActivityContext context, AsyncCallback callback,
對象狀態) { 行動createFollowUp = this.ExternalServices.Get(上下文).CreateFollowUp; context.UserState = createFollowUp; return createFollowUp.BeginInvoke(callback,state); 。 }
protected override void EndExecute(AsyncCodeActivityContext context, IAsyncResult result) { var createFollowUp = context.UserState as Action; if (createFollowUp == null) { throw new ArgumentNullException("The AsyncState of the IAsyncResult was not of the type
ExternalServices.AsyncCreateFollowUp「,(例外)NULL); }
createFollowUp.EndInvoke(result); } }
有趣......以前從未見過。你介意把你的XAML給我嗎? ron(dot)jacobs(at)microsoft(dot)com – 2012-03-16 19:38:38
很抱歉,在再次完成我的代碼後,我遲到了回覆,我意識到WorkflowArguments出現問題。所以當我改變輸入作爲字典對象時,它工作得很好。 – userpb 2012-03-29 17:07:01
就你而言,你是如何解決它的?爲什麼你需要將輸入參數改爲字典對象?我在這裏有同樣的問題,我不知道什麼是錯的。 – 2014-11-19 01:18:34