1: [TestMethod]
2: public void WorkFlowSwitchOnTitle_TitleStartsWithA_SetApprovelField()
3: {
4: using (WorkflowRuntime workflowRuntime = new WorkflowRuntime())
5: {
6:
7: // Create our fake workflow and items
8: var fakeProperties = Isolate.Fake.Instance<SPWorkflowActivationProperties>(Members.ReturnRecursiveFakes);
9: var fakeItem = Isolate.Fake.Instance<SPListItem>(Members.ReturnRecursiveFakes);
10:
11: var fakeField = Isolate.Fake.Instance<SPField>(Members.ReturnRecursiveFakes);
12: fakeField.DefaultValue = false.ToString();
13: Isolate.WhenCalled(() => fakeProperties.Item).WillReturn(fakeItem);
14: // setup the if test
15: Isolate.WhenCalled(() => fakeItem.Title).WillReturn("ABC");
16: Isolate.WhenCalled(() => fakeItem["Approved"]).WillReturn(fakeField);
17:
18: // setup the workflow handling AutoResetEvent waitHandle = new AutoResetEvent(false);
19: workflowRuntime.WorkflowCompleted += delegate(object sender, WorkflowCompletedEventArgs e)
20: {
21: // don't put asserts here as will be in the wrong thread
22: waitHandle.Set();
23: };
24:
25: workflowRuntime.WorkflowTerminated += delegate(object sender, WorkflowTerminatedEventArgs e)
26: {
27: // don't put asserts here as will be in the wrong thread
28: waitHandle.Set();
29: };
30:
31: // when this is called the constructor is called twice
32: // the first time is for validation for the workflow in this appdomain see http://odetocode.com/Blogs/scott/archive/2006/03/30/3192.aspx
33: // then the real construction is run, the problem is this double run means that the Isolate.Swap.NextInstance
34: // fails as it attaches to the first validation create, not the second real one
35: WorkflowInstance instance = workflowRuntime.CreateWorkflow(typeof(SharePointWorkflow.Workflow1));
36:
37: // SO for this reason we only get the swap after the first create has been done
38: Isolate.Swap.NextInstance<SPWorkflowActivationProperties>().With(fakeProperties);
39:
40: // we then recreate the workflow again, this time it has already been validated so
41: // the swap works
42: instance = workflowRuntime.CreateWorkflow(typeof(SharePointWorkflow.Workflow1));
43:
44: instance.Start();
45:
46: waitHandle.WaitOne();
47: // wait for the workflow to complete and then check the method expected were called Isolate.Verify.WasCalledWithExactArguments(() => fakeItem.Update());
48: Isolate.Verify.WasCalledWithExactArguments(() => fakeItem["Approved"] = "True");
49: }
50:
51: }