Пример #1
0
        private void SendHumanScreenComplete(bool hire)
        {
            ApplicationServiceClient proxy = new ApplicationServiceClient();
            try
            {
                // Create the result
                HumanScreeningResult result = new HumanScreeningResult()
                {
                    AppID = Convert.ToInt32(LabelAppID.Text),
                    HiringApproved = hire,
                };

                // Wrap it in a request
                HumanScreeningCompletedRequest request =
                new HumanScreeningCompletedRequest(result);

                // Call the workflow service
                proxy.HumanScreeningCompleted(result);

                proxy.Close();
            }
            catch (Exception)
            {
                proxy.Abort();
                throw;
            }
        }
        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 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();
                }
            }
        }