2012-03-16 56 views
1

在單元測試中,我通過自定義活動的組件的構造函數爲當地組裝 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); 
    } 
} 
+1

有趣......以前從未見過。你介意把你的XAML給我嗎? ron(dot)jacobs(at)microsoft(dot)com – 2012-03-16 19:38:38

+0

很抱歉,在再次完成我的代碼後,我遲到了回覆,我意識到WorkflowArguments出現問題。所以當我改變輸入作爲字典對象時,它工作得很好。 – userpb 2012-03-29 17:07:01

+0

就你而言,你是如何解決它的?爲什麼你需要將輸入參數改爲字典對象?我在這裏有同樣的問題,我不知道什麼是錯的。 – 2014-11-19 01:18:34

回答

0

嘗試修改活動的源代碼而改變。 」的xmlns:本地=「 clr- namespace:Activity1「to xmlns:local =」clr-namespace:Activity1; assembly = Activity1「。

包含名稱空間引用中的程序集(使用正確的程序集名稱)

相關問題