locked
Creating an Activity Instance for WorkflowInvoker RRS feed

  • Question

  •  

    I want to create an Activity to run through a TestMethod, but the following Fails

     

    IObjectScope scope = RTODataLayer.Private.ObjectScopeProvider1.GetNewObjectScope();
    
    RTODataLayer.RequestedDate date = WorkflowInvoker.Invoke(new CreateRequestedDate() { Scope = scope, Active = true, FromDate = DateTime.Now.AddDays(10), ToDate = DateTime.Now.AddDays(15), RequestID = request.RequestID, TypeID = 1, WorkingDays = 5 });
    
    
    
    Error    142    Cannot implicitly convert type 'Telerik.OpenAccess.IObjectScope' to 'System.Activities.InArgument<Telerik.OpenAccess.IObjectScope>'    D:\websites\workflow\RTO.UnitTests\RTO.Testing\Workflows\Approval.cs    19    106    RTO.Testing

    How do I pass in the scope object?...in my actual master XAML file I maintain the scope in the workflow, but I want to test the individual components.

     

     

     

    Thursday, September 23, 2010 6:52 PM

Answers

  • Hi Steve,

    WorkflowInvoker uses a dictionary of arguments to pass the values of Inarguments to the workflow it invokes. What you pass in as the first parameter is the workflow definition. It can be a tree of activities, or it can be a single activity. If that single activity has in arguments (that typically would be bound if it was being used inside a workflow), you create a dictionary of arguments and pass them just like you would if you were invoking a whole workflow.

    Here is an example of WorkflowInvoker invoking a single WriteLine activity (that typically would be used inside a workflow and its text argument bound to something inside the workflow)

    Activity wf = new WriteLine();
    
    Dictionary<string, object> inputs = new Dictionary<string, object>();
    inputs.Add("Text", "Hello World.");
    
    WorkflowInvoker.Invoke(wf, inputs);
    

    Ron Jacobs, Developer Evangelist for WF/WCF/AppFabric, has a presentation on unit testing workflow here:

    http://channel9.msdn.com/shows/Endpoint/endpointtv-Unit-Testing-Workflows/

    He also talks about Unit Testing workflow services here:

    http://blogs.msdn.com/b/rjacobs/archive/2010/09/13/how-to-unit-test-a-workflowservice.aspx

    (Not sure if that one applies to you but including it for completeness)

    There is a lot of other neat stuff on Ron's blog and EndPoint.tv if you haven't checked it out yet.

    Thanks

    Steve Danielson [Microsoft]
    This posting is provided "AS IS" with no warranties, and confers no rights.
    Use of included script samples are subject to the terms specified at http://www.microsoft.com/info/cpyright.htm

     

     

    • Marked as answer by stevemedportal Friday, September 24, 2010 5:24 PM
    Friday, September 24, 2010 5:21 PM

All replies

  • Hi Steve,

    WorkflowInvoker uses a dictionary of arguments to pass the values of Inarguments to the workflow it invokes. What you pass in as the first parameter is the workflow definition. It can be a tree of activities, or it can be a single activity. If that single activity has in arguments (that typically would be bound if it was being used inside a workflow), you create a dictionary of arguments and pass them just like you would if you were invoking a whole workflow.

    Here is an example of WorkflowInvoker invoking a single WriteLine activity (that typically would be used inside a workflow and its text argument bound to something inside the workflow)

    Activity wf = new WriteLine();
    
    Dictionary<string, object> inputs = new Dictionary<string, object>();
    inputs.Add("Text", "Hello World.");
    
    WorkflowInvoker.Invoke(wf, inputs);
    

    Ron Jacobs, Developer Evangelist for WF/WCF/AppFabric, has a presentation on unit testing workflow here:

    http://channel9.msdn.com/shows/Endpoint/endpointtv-Unit-Testing-Workflows/

    He also talks about Unit Testing workflow services here:

    http://blogs.msdn.com/b/rjacobs/archive/2010/09/13/how-to-unit-test-a-workflowservice.aspx

    (Not sure if that one applies to you but including it for completeness)

    There is a lot of other neat stuff on Ron's blog and EndPoint.tv if you haven't checked it out yet.

    Thanks

    Steve Danielson [Microsoft]
    This posting is provided "AS IS" with no warranties, and confers no rights.
    Use of included script samples are subject to the terms specified at http://www.microsoft.com/info/cpyright.htm

     

     

    • Marked as answer by stevemedportal Friday, September 24, 2010 5:24 PM
    Friday, September 24, 2010 5:21 PM
  • Thanks for the reply Steve, yeah I guess that was a bit of a brain fart :) 

     

    I was hoping I guess I could quickly pass in arg objects without needing the dictionary

    I do love me some Ron Jacobs (not in that way ;)  I think I've seen most endpoint.tv videos multiple times...it's really cool stuff!


    Steve

    Friday, September 24, 2010 5:24 PM