6.7. Invoking Workflows

WF4 offers the ability to invoke individual activities without using the workflow runtime. This could be used for scenarios such as unit testing. However, as many workflows will run for a long time, this won't be useful in all instances.

We will now invoke the workflow we created previously and check that requesting ten tickets returns the variable BookingSuccessful set to false. Note that in reality you would write this as a unit test with a framework such as NUnit, but we are just covering the principles here.

  1. Add a new C# console project to the solution called Chapter6.HelloWF.Tests.

  2. Add a reference to System.Activities and Chapter6.HelloWF.

  3. Enter the following using statements in Program.cs:

    using System.Activities;
    using System.Diagnostics;

  4. Enter the following code in Program.cs:

    static void Main(string[] args)
    {
        Dictionary<string, object> Arguments = new Dictionary<string, object>();
        Arguments.Add("FilmName", "Terminator");
        Arguments.Add("ShowingDate", System.DateTime.Now.ToString());
        Arguments.Add("NumberOfTickets", 10);
    
        IDictionary<string, object> Output = new Dictionary<string, object>();
    
        Output = WorkflowInvoker.Invoke(new Chapter6.HelloWF.Workflow1(), Arguments);
    
        Debug.Assert((bool)Output["BookingSuccessful"] == false);
    }

NOTE

When using the Invoke() method, the activity is guaranteed to be performed on the invoking thread and will time out after 60 seconds (unless you change this default—an overload in the Invoke() method).

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.141.37.10