“XamlInjector-无法创建未知类型错误”的解决方案不起作用

时间:2012-03-16 19:08:09

标签: unit-testing workflow-foundation-4

在单元测试中,我将Custom Activity的程序集作为本地程序集传递给ctor   var xamlInjector = new XamlInjector(“CreditAtRenewalFlow.xaml”,typeof(CreateFollowUp).Assembly);

CreateFollowUp是一个AsynCodeActivity

我在解析规则'Element :: =。EmptyElement |(StartElement ElementBody)中收到错误“'意外'PROPERTYELEMENT'。'。'行号'2'和行位置'4'。“在执行以下行

var host = WorkflowInvokerTest.Create(xamlInjector.GetActivity());

  

单元测试的样本是[TestMethod]          [DeploymentItem(@ “SRC \ ProcessFlows \ Activity1.xaml”)]          public void 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,
     

对象状态)           {               Action createFollowUp = this.ExternalServices.Get(context).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。“,(Exception)null);               }

        createFollowUp.EndInvoke(result);
    }
}

1 个答案:

答案 0 :(得分:0)

尝试修改活动的源代码。将“xmlns:local =”clr-namespace:Activity1“更改为xmlns:local =”clr-namespace:Activity1; assembly = Activity1“。

在命名空间引用中包含程序集(使用正确的程序集名称)