Search code examples
unit-testingworkflowworkflow-foundation-4mstest

Creating Code-Activity unit test while using GetExtension


How do I create unit test with context based on integration component?

I have identified problem as the Extension is trying to resolve implementation and returning error message:

"Object reference not set to an instance of an object."

My class:

 public sealed class GetListOfServiceIdsToProcess
{
   public InOutArgument<IArguments> Arguments { get; set; }

    protected override void Execute(CodeActivityContext context)
    {

        // I am recieving my error exception here
        context.GetExtension<lib.Extension.MyExtenstion>();

        var targetIds= (List<int>)Settings.Get("targetIds");

        var wfa = this.Arguments.Get(context);
        wfa.ListTargetIds = targetIds;

        Arguments.Set(context, wfa);            
    }
}

My Test so far:

I have problem with implementation of the test as far i could get it:

    /// <summary>
    ///A test for Execute
    ///</summary>
    [TestMethod()]
    public void ExecuteTest()
    {
        // create Isettings mock to return collection of service ids

        var expected = new List<int>() { 30, 20 };

        var wfaInput = new TestWorkFlow();

        var serviceIdList = new GetListOfServiceIdsToProcess();
        var wfParam = new Dictionary<string, object>();
        wfParam.Add("WorkFlowArguments", wfaInput);

        var results = WorkflowInvoker.Invoke(serviceIdList, wfParam);
        var wfaResult = (IWorkFlowArguments)results["WorkFlowArguments"];

        Assert.AreEqual(expected, wfaResult.ListOfServiceIdsToProcess);
    }

Solution

  • I have run through multiple options and the problem what I have is MS Workflow. I have extracted all logic away from workflow code activity into separate class and this class has been put under tests.

    This is the best I could do for this. As I have base classes, that are injected, but I could not easily implement what I needed.

    Thank you all for help anyway.