예제 #1
0
        public void CanMockReceiveAndSendReply()
        {
            // Arrange
            const int Expected = 123;
            var xamlInjector = new XamlInjector(MockingMessagingActivities + "\\" + Service1Xamlx);

            // Setup the XamlInjector to replace the receive / send activities
            xamlInjector.ReplaceAll(typeof(Receive), typeof(ReceiveStub));
            xamlInjector.ReplaceAll(typeof(SendReply), typeof(SendReplyStub));

            // Access the workflow service Body activity for testing with WorkflowInvoker
            var host = WorkflowInvokerTest.Create(xamlInjector.GetWorkflowService().Body);

            // Setup the extension
            var stubExtension = new MessagingStubExtension();
            stubExtension.EnqueueReceive(this.serviceContractName, "GetData", Expected);
            host.Extensions.Add(stubExtension);

            try
            {
                host.TestActivity();

                // The reply should be "123"
                Assert.AreEqual(Expected.ToString(CultureInfo.InvariantCulture), stubExtension.Messages[1].Content);
            }
            finally
            {
                Trace.WriteLine("*** Messaging Stub Dump");
                stubExtension.Trace();

                Trace.WriteLine("\r\n*** Workflow Tracking Records");
                host.Tracking.Trace();
            }
        }
        public void EducationLevelMastersWhenSentShouldHireWhenHumanApproves()
        {
            const string ExpectedName = "test";
            const int ExpectedId = 123;
            var expectedResponse = string.Format(ServiceResources.JobApplicationProcessing, ExpectedName, ExpectedId);

            var xamlInjector = new XamlInjector("SubmitApplication.xamlx");
            xamlInjector.ReplaceAll(typeof(NotifyApplicant), typeof(MockNotifyApplicant));
            xamlInjector.ReplaceAll(typeof(RequestHumanScreening), typeof(MockRequestHumanScreening));
            xamlInjector.ReplaceAll(typeof(SaveJobApplication), typeof(MockSaveJobApplication));
            xamlInjector.ReplaceAll(typeof(UpdateHireApproved), typeof(MockUpdateHireApproved));
            xamlInjector.ReplaceAll(typeof(Delay), typeof(DelayStub));
            DelayStub.StubDuration = TimeSpan.FromSeconds(5);

            // Host the service
            var address = ServiceTest.GetUniqueEndpointAddress();

            using (var host = WorkflowServiceTestHost.Open(xamlInjector.GetWorkflowService(), address))
            {
                // Setup a proxy to use named pipes
                var proxy = new ApplicationServiceClient(ServiceTest.Pipe, address);

                try
                {
                    // Submit an application
                    var response = proxy.SubmitJobApplication(CreateApplicationRequest());

                    // Check that we got a response message
                    Assert.AreEqual(expectedResponse, response.ResponseText);

                    var result = proxy.HumanScreeningCompleted(new HumanScreeningResult { AppID = ExpectedId, HiringApproved = true });
                    Assert.IsTrue(result.HasValue && result.Value);

                    proxy.Close();

                    // The last thing to happen is for the Workflow Instance to be deleted from
                    // the persistence store.
                    // Wait for this before asserting tracking records
                    Assert.IsTrue(host.WaitForInstanceDeleted());

                    // Close the host
                    host.Close();

                    // Assert
                    // Assert that the Auto Screen Education activity returned EducationPassed = true

                    // Find this tracking record and assert the arguments
                    // 55: Activity [67] "Auto Screen Education" is Closed at 09:05:14.1297
                    // {
                    // Arguments
                    // EducationPassed: True
                    // Education: Masters
                    // }
                    host.Tracking.Assert.ExistsArgValue("Auto Screen Education", ActivityInstanceState.Closed, EducationpassedArgName, true);

                    // Assert that the Request Human Screening activity was invoked

                    // 69: Activity [60] "Request Human Screening" is Closed at 09:05:14.1307
                    // {
                    // Arguments
                    // ApplicationRequest: HRApplicationServices.Contracts.SubmitJobApplicationRequest
                    // RetryCount: 0
                    // ApplicationID: 123
                    // }
                    var requestHumanScreening = host.Tracking.Records.Find(RequestHumanScreeningDisplayName, ActivityInstanceState.Closed);

                    Assert.IsNotNull(requestHumanScreening, "Could not find Request Human Screening");
                    Assert.AreEqual(ExpectedId, requestHumanScreening.GetArgument<int>(ApplicationidArgName), "On first Human Screening Request Applicant ID does not match request");
                    Assert.AreEqual(0, requestHumanScreening.GetArgument<int>(RetrycountArgName), "On first Human Screening Request RetryCount is not zero");

                    // Assert that the Update Hire activity was invoked

                    // Find this activity state record
                    // 109: Activity [45] "Update Hire Approved" is Closed at 09:05:14.1357
                    // {
                    // Arguments
                    // ApplicantID: 123
                    // HireApproved: True
                    // }
                    host.Tracking.Assert.ExistsArgValue(UpdateHireApprovedDisplayName, ActivityInstanceState.Closed, HireApprovedArgName, true);
                    host.Tracking.Assert.ExistsArgValue(UpdateHireApprovedDisplayName, ActivityInstanceState.Closed, ApplicantidArgName, ExpectedId);

                    // Assert that the hire email notification was sent

                    // Find this activity state record
                    // 140: Activity [4] "MockNotifyApplicant" is Closed at 09:05:14.1377
                    // {
                    // Arguments
                    // Cancel: False
                    // Hire: True
                    // Resume: HRApplicationServices.Contracts.ApplicantResume
                    // }
                    var notifyApplicant = host.Tracking.Records.Find("MockNotifyApplicant", ActivityInstanceState.Closed);
                    Assert.IsNotNull(notifyApplicant, "Could not find the MockNotifyApplication activity");
                    Assert.IsTrue(notifyApplicant.GetArgument<bool>("Hire"), "The applicant notify activity did not have argument Hire=true");
                    Assert.AreEqual("test", notifyApplicant.GetArgument<ApplicantResume>("Resume").Name, "The NotifyApplication activity did not have the correct applicant name");
                }
                finally
                {
                    host.Tracking.Trace();
                }
            }
        }
        public void ShouldNotHireEductionLevelNone()
        {
            const string ExpectedName = "test";
            const int ExpectedId = 123;
            var expectedResponse = string.Format(ServiceResources.JobApplicationProcessing, ExpectedName, ExpectedId);

            var xamlInjector = new XamlInjector("SubmitApplication.xamlx");
            xamlInjector.ReplaceAll(typeof(NotifyApplicant), typeof(MockNotifyApplicant));
            xamlInjector.ReplaceAll(typeof(RequestHumanScreening), typeof(MockRequestHumanScreening));
            xamlInjector.ReplaceAll(typeof(SaveJobApplication), typeof(MockSaveJobApplication));
            xamlInjector.ReplaceAll(typeof(UpdateHireApproved), typeof(MockUpdateHireApproved));

            // Host the service
            var address = ServiceTest.GetUniqueEndpointAddress();
            using (var host = WorkflowServiceTestHost.Open(xamlInjector.GetWorkflowService(), address))
            {
                // Setup a proxy to use named pipes
                var proxy = new ApplicationServiceClient(ServiceTest.Pipe, address);

                try
                {
                    // Submit an application
                    var response = proxy.SubmitJobApplication(CreateApplicationRequest("none"));

                    proxy.Close();

                    // The last thing to happen is for the Workflow Instance to be deleted from
                    // the persistence store.
                    // Wait for this before asserting tracking records
                    Assert.IsTrue(host.WaitForInstanceDeleted());

                    // Close the host
                    host.Close();

                    // Assert

                    // Check that we got a response message
                    Assert.AreEqual(expectedResponse, response.ResponseText);

                    host.Tracking.Trace();

                    // Assert that the Auto Screen Education activity returned EducationPassed = false

                    // Find this tracking record and assert the arguments
                    // Activity <Auto Screen Education> state is Closed
                    // {
                    // Arguments
                    // EducationPassed: False
                    // Education: None
                    // }

                    // After the autoscreen the EducationPassed argument should be false
                    var autoScreenEducation = host.Tracking.Records.Find("Auto Screen Education", ActivityInstanceState.Closed);

                    Assert.IsFalse(autoScreenEducation.GetArgument<bool>(EducationpassedArgName));

                    // Assert that the Update No Hire activity was invoked

                    // Find this activity state record
                    // Activity <Update No Hire> state is Closed
                    // {
                    // Arguments
                    // ApplicantID: 123
                    // HireApproved: False
                    // }
                    var updateNoHire = host.Tracking.Records.Find("Update No Hire", ActivityInstanceState.Closed);
                    Assert.IsFalse(updateNoHire.GetArgument<bool>(HireApprovedArgName));

                    // Assert that the no-hire email notification was sent

                    // Find this activity state record
                    // Activity <MockNotifyApplicant> state is Closed
                    // {
                    // Arguments
                    // Hire: False
                    // Resume: HRApplicationServices.Contracts.ApplicantResume
                    // }
                    var notifyApplicant = host.Tracking.Records.Find("MockNotifyApplicant", ActivityInstanceState.Closed);
                    Assert.IsFalse(notifyApplicant.GetArgument<bool>("Hire"));
                }
                catch (Exception)
                {
                    proxy.Abort();
                    throw;
                }
                finally
                {
                    host.Tracking.Trace();
                }
            }
        }
        public void ServiceShouldCancelAfter2Nags()
        {
            const string ExpectedName = "test";
            const int ExpectedId = 123;
            var expectedResponse = string.Format(ServiceResources.JobApplicationProcessing, ExpectedName, ExpectedId);

            var xamlInjector = new XamlInjector("SubmitApplication.xamlx");
            xamlInjector.ReplaceAll(typeof(NotifyApplicant), typeof(MockNotifyApplicant));
            xamlInjector.ReplaceAll(typeof(RequestHumanScreening), typeof(MockRequestHumanScreening));
            xamlInjector.ReplaceAll(typeof(SaveJobApplication), typeof(MockSaveJobApplication));
            xamlInjector.ReplaceAll(typeof(Delay), typeof(DelayStub));
            xamlInjector.ReplaceAll(typeof(UpdateHireApproved), typeof(MockUpdateHireApproved));

            // Host the service
            var address = ServiceTest.GetUniqueEndpointAddress();
            using (var host = WorkflowServiceTestHost.Open(xamlInjector.GetWorkflowService(), address))
            {
                // Setup a proxy to use named pipes
                var proxy = new ApplicationServiceClient(ServiceTest.Pipe, address);

                try
                {
                    var applicationRequest = CreateApplicationRequest();

                    // Submit an application
                    var response = proxy.SubmitJobApplication(applicationRequest);

                    // Check that we got a response message
                    Assert.AreEqual(expectedResponse, response.ResponseText);

                    // Take no further action - application should cancel
                    proxy.Close();

                    // Close the host
                    host.Close();

                    // Assert

                    // Find the first notification to the HR Administrator
                    // 69: Activity [60] "Request Human Screening" is Closed at 07:03:54.4424
                    // {
                    // Arguments
                    // ApplicationRequest: HRApplicationServices.Contracts.SubmitJobApplicationRequest
                    // RetryCount: 0
                    // ApplicationID: 123
                    // }
                    var request1 = host.Tracking.Records.Find(RequestHumanScreeningDisplayName, ActivityInstanceState.Closed);
                    Assert.IsNotNull(request1, "Could not find first request notification");
                    Assert.AreEqual(0, request1.GetArgument<int>(RetrycountArgName), "Retry count was not zero on first request");

                    // Find the second notification to the HR Administrator
                    // 115: Activity [60] "Request Human Screening" is Executing at 07:03:54.4454
                    // {
                    // Arguments
                    // ApplicationRequest: HRApplicationServices.Contracts.SubmitJobApplicationRequest
                    // RetryCount: 1
                    // ApplicationID: 123
                    // }
                    var request2 = host.Tracking.Records.Find(RequestHumanScreeningDisplayName, ActivityInstanceState.Closed, request1.RecordNumber + 1);
                    Assert.IsNotNull(request2, "Could not find second request notification");
                    Assert.AreEqual(1, request2.GetArgument<int>(RetrycountArgName), "Retry count was not one on second request");

                    // Find the cancel notification
                    // 167: Activity [4] "MockNotifyApplicant" is Closed at 07:03:54.4474
                    // {
                    // Arguments
                    // Cancel: True
                    // Hire: False
                    // Resume: HRApplicationServices.Contracts.ApplicantResume
                    // }
                    var notifyApplicant = host.Tracking.Records.Find("MockNotifyApplicant", ActivityInstanceState.Closed);
                    Assert.IsNotNull(notifyApplicant, "Could not find Cancel notification");
                    Assert.IsFalse(notifyApplicant.GetArgument<bool>("Hire"), "Hire argument was not false when the application was canceled");
                    Assert.IsTrue(notifyApplicant.GetArgument<bool>("Cancel"), "Cancel argument was not true");
                }
                finally
                {
                    host.Tracking.Trace();
                }
            }
        }
        public void ShouldCancelAfter2Nags()
        {
            const string expectedName = "test";
            const int expectedId = 123;
            var expectedResponse = string.Format(ServiceResources.JobApplicationProcessing, expectedName, expectedId);

            var xamlInjector = new XamlInjector("SubmitApplication.xamlx");
            xamlInjector.ReplaceAll(typeof(NotifyApplicant), typeof(MockNotifyApplicant));
            xamlInjector.ReplaceAll(typeof(RequestHumanScreening), typeof(MockRequestHumanScreening));
            xamlInjector.ReplaceAll(typeof(SaveJobApplication), typeof(MockSaveJobApplication));
            xamlInjector.ReplaceAll(typeof(Delay), typeof(FakeDelay));
            xamlInjector.ReplaceAll(typeof(UpdateHireApproved), typeof(MockUpdateHireApproved));

            SubmitJobApplicationResponse response = null;

            // Host the service);
            using (var testHost = WorkflowServiceTestHost.Open(xamlInjector.GetWorkflowService(), _serviceAddress))
            {
                // Setup a proxy to use named pipes
                var proxy = new ApplicationServiceClient(_binding, _serviceAddress);

                try
                {
                    // Submit an application
                    response = proxy.SubmitJobApplication(new SubmitJobApplicationRequest
                    {
                        RequestID = Guid.NewGuid(),
                        Resume = new ApplicantResume
                        {
                            Education = "Masters",
                            Email = "*****@*****.**",
                            Name = "test",
                            NumReferences = 0
                        }
                    });

                    // Check that we got a response message
                    Assert.AreEqual(expectedResponse, response.ResponseText);

                    // Take no further action - application should cancel

                    proxy.Close();
                }
                catch (Exception)
                {
                    testHost.Tracking.Trace();
                    proxy.Abort();
                    throw;
                }

                // The last thing to happen is for the Workflow Instance to be deleted from
                // the persistence store.
                // Wait for this before asserting tracking records
                Assert.IsTrue(WorkflowServiceTestHost.WaitForInstanceDeleted());

                // Close the host
                testHost.Close();
                Assert.IsTrue(WorkflowServiceTestHost.WaitForHostClosed());

                // Assert

                testHost.Tracking.Trace();

                // Find the cancel notification
                //Activity <MockNotifyApplicant> state is Closed
                //{
                //    Arguments
                //        Cancel: True
                //        Hire: False
                //        Resume: HRApplicationServices.Contracts.ApplicantResume
                //}

                var notifyApplicant = testHost.Tracking.Records.FindActivityState("MockNotifyApplicant",
                                                                                  ActivityInstanceState.Closed);
                Assert.IsNotNull(notifyApplicant);
                Assert.IsFalse(notifyApplicant.GetArgument<bool>("Hire"));
                Assert.IsTrue(notifyApplicant.GetArgument<bool>("Cancel"));
            }
        }
        public void ShouldHireEducationLevelMasters()
        {
            const string expectedName = "test";
            const int expectedId = 123;
            var expectedResponse = string.Format(ServiceResources.JobApplicationProcessing, expectedName, expectedId);

            var xamlInjector = new XamlInjector("SubmitApplication.xamlx");
            xamlInjector.ReplaceAll(typeof(NotifyApplicant), typeof(MockNotifyApplicant));
            xamlInjector.ReplaceAll(typeof(RequestHumanScreening), typeof(MockRequestHumanScreening));
            xamlInjector.ReplaceAll(typeof(SaveJobApplication), typeof(MockSaveJobApplication));
            xamlInjector.ReplaceAll(typeof(UpdateHireApproved), typeof(MockUpdateHireApproved));

            SubmitJobApplicationResponse response = null;

            // Host the service);
            using (var testHost = WorkflowServiceTestHost.Open(xamlInjector.GetWorkflowService(), _serviceAddress))
            {
                // Setup a proxy to use named pipes
                var proxy = new ApplicationServiceClient(_binding, _serviceAddress);

                try
                {
                    // Submit an application
                    response = proxy.SubmitJobApplication(new SubmitJobApplicationRequest
                                                              {
                                                                  RequestID = Guid.NewGuid(),
                                                                  Resume = new ApplicantResume
                                                                               {
                                                                                   Education = "Masters",
                                                                                   Email = "*****@*****.**",
                                                                                   Name = "test",
                                                                                   NumReferences = 0
                                                                               }
                                                              });

                    // Check that we got a response message
                    Assert.AreEqual(expectedResponse, response.ResponseText);

                    var result =
                        proxy.HumanScreeningCompleted(new HumanScreeningResult { AppID = expectedId, HiringApproved = true });
                    Assert.IsTrue(result.HasValue && result.Value);

                    proxy.Close();
                }
                catch (Exception)
                {
                    //testHost.Tracking.Trace();
                    proxy.Abort();
                    throw;
                }

                // The last thing to happen is for the Workflow Instance to be deleted from
                // the persistence store.
                // Wait for this before asserting tracking records
                Assert.IsTrue(WorkflowServiceTestHost.WaitForInstanceDeleted());

                // Close the host
                testHost.Close();
                Assert.IsTrue(WorkflowServiceTestHost.WaitForHostClosed());

                // Assert

                testHost.Tracking.Trace(1000);

                // Assert that the Auto Screen Education activity returned EducationPassed = false

                // Find this tracking record and assert the arguments
                //Activity <Auto Screen Education> state is Closed
                //{
                //    Arguments
                //        EducationPassed: True
                //        Education: Masters
                //}

                // After the autoscreen the EducationPassed argument should be true
                var autoScreenEducation = testHost.Tracking.Records.FindActivityState("Auto Screen Education",
                                                                                      ActivityInstanceState.Closed);
                Assert.IsTrue(autoScreenEducation.GetArgument<bool>("EducationPassed"));

                // Assert that the Request Human Screening activity was invoked
                //Activity <Request Human Screening> state is Closed
                //{
                //    Arguments
                //        ApplicationRequest: HRApplicationServices.Contracts.SubmitJobApplicationRequest
                //        ApplicationID: 123
                //}

                var requestHumanScreening = testHost.Tracking.Records.FindActivityState("Request Human Screening",
                                                                                        ActivityInstanceState.Closed);

                Assert.IsNotNull(requestHumanScreening, "Could not find Request Human Screening");
                Assert.AreEqual(expectedId, requestHumanScreening.GetArgument<int>("ApplicationID"));

                // Assert that the Update Hire activity was invoked

                // Find this activity state record
                //Activity <Update Hire Approved> state is Executing
                //{
                //    Arguments
                //        ApplicantID: 123
                //        HireApproved: True
                //}

                var updateHire = testHost.Tracking.Records.FindActivityState("Update Hire Approved",
                                                                             ActivityInstanceState.Closed);
                Assert.IsTrue(updateHire.GetArgument<bool>("HireApproved"));
                Assert.AreEqual(expectedId, updateHire.GetArgument<int>("ApplicantID"));

                // Assert that the hire email notification was sent

                // Find this activity state record
                //Activity <MockNotifyApplicant> state is Closed
                //{
                //    Arguments
                //        Hire: True
                //        Resume: HRApplicationServices.Contracts.ApplicantResume
                //}

                //var notifyApplicant = testHost.Tracking.Records.FindActivityState("MockNotifyApplicant",
                //                                                                  ActivityInstanceState.Closed);
                //Assert.IsNotNull(notifyApplicant);
                //Assert.IsTrue(notifyApplicant.GetArgument<bool>("Hire"));
                //Assert.AreEqual("test", notifyApplicant.GetArgument<ApplicantResume>("Resume").Name);
            }
        }
        public void EducationLevelMastersWhenSentShouldHireWhenHumanApproves()
        {
            const string ExpectedName = "test";
            const int ExpectedId = 123;
            var expectedResponse = string.Format(ServiceResources.JobApplicationProcessing, ExpectedName, ExpectedId);

            // XamlInjector will replace activities with Mocks suitable for testing
            var xamlInjector = new XamlInjector("SubmitApplication.xamlx");

            // The first phase builds a set of replacement rules
            xamlInjector.ReplaceAll(typeof(NotifyApplicant), typeof(MockNotifyApplicant));
            xamlInjector.ReplaceAll(typeof(RequestHumanScreening), typeof(MockRequestHumanScreening));
            xamlInjector.ReplaceAll(typeof(SaveJobApplication), typeof(MockSaveJobApplication));
            xamlInjector.ReplaceAll(typeof(UpdateHireApproved), typeof(MockUpdateHireApproved));
            xamlInjector.ReplaceAll(typeof(Delay), typeof(DelayStub));

            // Then we load the service and replace the activities with mocks
            var mockedService = xamlInjector.GetWorkflowService();

            // Setup the DelayStub timeout
            // Keep it short but long enough to receive the second message
            DelayStub.StubDuration = TimeSpan.FromSeconds(1);

            // Host the service
            using (var host = WorkflowServiceTestHost.Open(mockedService, this.serviceAddress))
            {
                // Arrange
                // Setup a proxy to use named pipes
                // Using the proxy generated by a service reference
                var proxy = new ApplicationServiceClient(this.binding, this.serviceAddress);

                try
                {
                    // Act
                    // When the the application is submitted to the service
                    var response = proxy.SubmitJobApplication(CreateApplicationRequest());

                    // Check that we got a response message
                    Assert.AreEqual(expectedResponse, response.ResponseText);

                    // When the Human approves the application
                    var result =
                        proxy.HumanScreeningCompleted(
                            new HumanScreeningResult { AppID = ExpectedId, HiringApproved = true });

                    // Check that the response was accepted
                    Assert.IsTrue(result.HasValue && result.Value);

                    proxy.Close();

                    // Close the host
                    host.Close();
                    Assert.IsTrue(host.WaitForHostClosed());

                    // Assert
                    // Assert that the Auto Screen Education activity returned EducationPassed = true
                    // 55: Activity [67] "Auto Screen Education" is Closed
                    // {
                    // Arguments
                    // EducationPassed: True
                    // Education: Masters
                    // }
                    host.Tracking.Assert.ExistsArgValue(
                        "Auto Screen Education", ActivityInstanceState.Closed, EducationpassedArgName, true);

                    // Assert that the Request Human Screening activity was invoked
                    // 69: Activity [60] "Request Human Screening" is Closed
                    // {
                    // Arguments
                    // ApplicationRequest: HRApplicationServices.Contracts.SubmitJobApplicationRequest
                    // RetryCount: 0
                    // ApplicationID: 123
                    // }
                    var requestHumanScreening = host.Tracking.Records.Find(
                        RequestHumanScreeningDisplayName, ActivityInstanceState.Closed);

                    Assert.IsNotNull(requestHumanScreening, "Could not find Request Human Screening");
                    Assert.AreEqual(
                        ExpectedId,
                        requestHumanScreening.GetArgument<int>(ApplicationidArgName),
                        "On first Human Screening Request Applicant ID does not match request");
                    Assert.AreEqual(
                        0,
                        requestHumanScreening.GetArgument<int>(RetrycountArgName),
                        "On first Human Screening Request RetryCount is not zero");

                    // Assert that the Update Hire activity was invoked
                    // 109: Activity [45] "Update Hire Approved" is Closed
                    // {
                    // Arguments
                    // ApplicantID: 123
                    // HireApproved: True
                    // }
                    host.Tracking.Assert.ExistsArgValue(
                        UpdateHireApprovedDisplayName, ActivityInstanceState.Closed, HireApprovedArgName, true);
                    host.Tracking.Assert.ExistsArgValue(
                        UpdateHireApprovedDisplayName, ActivityInstanceState.Closed, ApplicantidArgName, ExpectedId);

                    // Assert that the hire email notification was sent
                    // 140: Activity [4] "MockNotifyApplicant" is Closed
                    // {
                    // Arguments
                    // Cancel: False
                    // Hire: True
                    // Resume: HRApplicationServices.Contracts.ApplicantResume
                    // }
                    var notifyApplicant = host.Tracking.Records.Find(
                        "MockNotifyApplicant", ActivityInstanceState.Closed);
                    Assert.IsNotNull(notifyApplicant, "Could not find the MockNotifyApplication activity");
                    Assert.IsTrue(
                        notifyApplicant.GetArgument<bool>("Hire"),
                        "The applicant notify activity did not have argument Hire=true");
                    Assert.AreEqual(
                        "test",
                        notifyApplicant.GetArgument<ApplicantResume>("Resume").Name,
                        "The NotifyApplication activity did not have the correct applicant name");
                }
                finally
                {
                    host.Tracking.Trace();
                }
            }
        }
예제 #8
0
        public void CanSimulateSendFailure()
        {
            // Arrange
            var xamlInjector = new XamlInjector(@"MockingMessagingActivities\ServiceWithSend.xamlx");

            // Setup the XamlInjector to replace the receive / send activities
            xamlInjector.ReplaceAll(typeof(Receive), typeof(ReceiveStub));
            xamlInjector.ReplaceAll(typeof(SendReply), typeof(SendReplyStub));
            xamlInjector.ReplaceAll(typeof(Send), typeof(SendStub));
            xamlInjector.ReplaceAll(typeof(ReceiveReply), typeof(ReceiveReplyStub));

            // Access the workflow service Body activity for testing with WorkflowInvoker
            var host = WorkflowInvokerTest.Create(xamlInjector.GetWorkflowService().Body);

            // Setup the extension
            var stubExtension = new MessagingStubExtension();

            // The first receive will start the process
            stubExtension.EnqueueReceive(this.serviceContractName, "GetData", 123);

            // The first send will result in an exception
            stubExtension.SetImplementation("Send Primary", () => { throw new EndpointNotFoundException(); });

            // The second send should succeed
            // The next receive reply should simulate data from the backup service
            stubExtension.EnqueueReceiveReply(this.serviceContractName, "GetData", BackupResponse);
            host.Extensions.Add(stubExtension);

            try
            {
                host.TestActivity();

                // Assert
                // The final reply is "Backup 123"
                Assert.AreEqual(BackupResponse, stubExtension.Messages[4].Content);
            }
            finally
            {
                Trace.WriteLine("*** Messaging Stub Dump");
                stubExtension.Trace();

                Trace.WriteLine("\r\n*** Workflow Tracking Records");
                host.Tracking.Trace();
            }
        }
예제 #9
0
        public void CanMockTwoReceiveAndSendReplyWithParameters()
        {
            // Arrange
            var xamlInjector = new XamlInjector(@"MockingMessagingActivities\Service2Parameters.xamlx");

            // Setup the XamlInjector to replace the receive / send activities
            xamlInjector.ReplaceAll(typeof(Receive), typeof(ReceiveStub));
            xamlInjector.ReplaceAll(typeof(SendReply), typeof(SendReplyStub));

            // Access the workflow service Body activity for testing with WorkflowInvoker
            var host = WorkflowInvokerTest.Create(xamlInjector.GetWorkflowService().Body);

            // Setup the extension
            var stubExtension = new MessagingStubExtension();

            // Setup the first message
            dynamic parameterValues1 = new WorkflowArguments();
            parameterValues1.value1 = 5;
            parameterValues1.value2 = 4;
            stubExtension.EnqueueReceive(this.serviceContractName, "GetData", parameterValues1);

            // Setup the second message
            dynamic parameterValues2 = new WorkflowArguments();
            parameterValues2.value1 = 6;
            parameterValues2.value2 = 3;
            stubExtension.EnqueueReceive(this.serviceContractName, "GetData2", parameterValues2);

            host.Extensions.Add(stubExtension);

            try
            {
                host.TestActivity();

                // Assert
                // The first reply parameter "data1" is "5"
                Assert.AreEqual("5", stubExtension.Messages[1].Parameter("data1"));

                // The first reply parameter "data1" is "4"
                Assert.AreEqual("4", stubExtension.Messages[1].Parameter("data2"));

                // The second reply parameter "data1" is "7"
                Assert.AreEqual("7", stubExtension.Messages[3].Parameter("data1"));

                // The second reply parameter "data1" is "5"
                Assert.AreEqual("5", stubExtension.Messages[3].Parameter("data2"));
            }
            finally
            {
                Trace.WriteLine("*** Messaging Stub Dump");
                stubExtension.Trace();

                Trace.WriteLine("\r\n*** Workflow Tracking Records");
                host.Tracking.Trace();
            }
        }
예제 #10
0
        public void CanMockTwoReceiveAndSendReply()
        {
            // Arrange
            var xamlInjector = new XamlInjector(@"MockingMessagingActivities\Service2.xamlx");

            // Setup the XamlInjector to replace the receive / send activities
            xamlInjector.ReplaceAll(typeof(Receive), typeof(ReceiveStub));
            xamlInjector.ReplaceAll(typeof(SendReply), typeof(SendReplyStub));

            // Access the workflow service Body activity for testing with WorkflowInvoker
            var host = WorkflowInvokerTest.Create(xamlInjector.GetWorkflowService().Body);

            // Setup the extension
            var stubExtension = new MessagingStubExtension();
            stubExtension.EnqueueReceive(this.serviceContractName, "GetData", 5);
            stubExtension.EnqueueReceive(this.serviceContractName, "GetData2", 6);
            host.Extensions.Add(stubExtension);

            try
            {
                host.TestActivity();

                // Assert
                // The first reply is "5"
                Assert.AreEqual("5", stubExtension.Messages[1].Content);

                // The second reply is "8"
                Assert.AreEqual("8", stubExtension.Messages[3].Content);
            }
            finally
            {
                Trace.WriteLine("*** Messaging Stub Dump");
                stubExtension.Trace();

                Trace.WriteLine("\r\n*** Workflow Tracking Records");
                host.Tracking.Trace();
            }
        }
예제 #11
0
        public void CanMockReceiveAndSendReplyWithParameters()
        {
            // Arrange
            const int Value1 = 123;
            const int Value2 = 456;
            var xamlInjector = new XamlInjector(@"MockingMessagingActivities\Service1Parameters.xamlx");

            // Setup the XamlInjector to replace the receive / send activities
            xamlInjector.ReplaceAll(typeof(Receive), typeof(ReceiveStub));
            xamlInjector.ReplaceAll(typeof(SendReply), typeof(SendReplyStub));

            // Access the workflow service Body activity for testing with WorkflowInvoker
            var host = WorkflowInvokerTest.Create(xamlInjector.GetWorkflowService().Body);

            // Setup the extension
            dynamic arguments = new WorkflowArguments();
            arguments.value1 = Value1;
            arguments.value2 = Value2;

            var stubExtension = new MessagingStubExtension();
            stubExtension.EnqueueReceive(this.serviceContractName, "GetData", arguments);
            host.Extensions.Add(stubExtension);

            try
            {
                host.TestActivity();

                // The first reply message parameter data1 should be "123"
                Assert.AreEqual(Value1.ToString(CultureInfo.InvariantCulture), stubExtension.Messages[1].Parameter("data1"));

                // The first reply message parameter data2 should be "456"
                Assert.AreEqual(Value2.ToString(CultureInfo.InvariantCulture), stubExtension.Messages[1].Parameter("data2"));
            }
            finally
            {
                Trace.WriteLine("*** Messaging Stub Dump");
                stubExtension.Trace();

                Trace.WriteLine("\r\n*** Workflow Tracking Records");
                host.Tracking.Trace();
            }
        }