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.
Add a new C# console project to the solution called Chapter6.HelloWF.Tests.
Add a reference to System.Activities and Chapter6.HelloWF.
Enter the following using statements in Program.cs:
using System.Activities; using System.Diagnostics;
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); }
3.14.142.131