public void Pipeline_CC_Workflow_Should_Fail_And_Notify_Customer_When_CC_AuthFails()
        {
            Order order = GetTestOrder();

            using (WorkflowRuntime workflowRuntime = new WorkflowRuntime()) {
                AutoResetEvent waitHandle = new AutoResetEvent(false);
                workflowRuntime.WorkflowCompleted  += delegate(object sender, WorkflowCompletedEventArgs e) { waitHandle.Set(); };
                workflowRuntime.WorkflowTerminated += delegate(object sender, WorkflowTerminatedEventArgs e) {
                    Debug.WriteLine(e.Exception.Message);
                    waitHandle.Set();
                };

                var parameters = GetParams(order);

                //reset the payment service to throw
                parameters["PaymentServiceInterface"] = new ThrowPaymentService();

                WorkflowInstance instance = workflowRuntime.CreateWorkflow(
                    typeof(Commerce.Pipelines.SubmitOrderWorkflow), parameters);

                try {
                    instance.Start();
                    waitHandle.WaitOne();
                } catch {
                }

                //execution should be finished
                //check the mailers
                TestMailerService mailer = _mailerService as TestMailerService;
                Assert.IsTrue(mailer.SentMail.Count > 0);

                //the first email should be to the customer
                Assert.AreEqual(MailerType.CustomerOrderReceived, mailer.SentMail[0].MailType);
                Assert.AreEqual(MailerType.CustomerPaymentAuthFailed, mailer.SentMail[1].MailType);
            }
        }
        public void Pipeline_CC_Workflow_Should_Fail_And_Notify_Customer_When_CC_AuthFails() {

            Order order = GetTestOrder();

            using (WorkflowRuntime workflowRuntime = new WorkflowRuntime()) {
                AutoResetEvent waitHandle = new AutoResetEvent(false);
                workflowRuntime.WorkflowCompleted += delegate(object sender, WorkflowCompletedEventArgs e) { waitHandle.Set(); };
                workflowRuntime.WorkflowTerminated += delegate(object sender, WorkflowTerminatedEventArgs e) {
                    Debug.WriteLine(e.Exception.Message);
                    waitHandle.Set();
                };

                var parameters = GetParams(order);

                //reset the payment service to throw
                parameters["PaymentServiceInterface"] = new ThrowPaymentService();

                WorkflowInstance instance = workflowRuntime.CreateWorkflow(
                    typeof(Commerce.Pipelines.SubmitOrderWorkflow), parameters);

                try {
                    instance.Start();
                    waitHandle.WaitOne();
                } catch {

                }

                //execution should be finished
                //check the mailers
                TestMailerService mailer = _mailerService as TestMailerService;
                Assert.IsTrue(mailer.SentMail.Count > 0);

                //the first email should be to the customer
                Assert.AreEqual(MailerType.CustomerOrderReceived, mailer.SentMail[0].MailType);
                Assert.AreEqual(MailerType.CustomerPaymentAuthFailed, mailer.SentMail[1].MailType);

            }
        }