protected void ButtonApplyClick(object sender, EventArgs e) { var request = new SubmitJobApplicationRequest { Resume = new ApplicantResume { Name = txtName.Text, Email = txtEmail.Text, Education = ddEducation.Text, }, RequestID = Guid.NewGuid() }; var proxy = new ApplicationServiceClient(); var response = proxy.SubmitJobApplication(request); Session["SubmitAppResponse"] = response; Response.Redirect("SubmitAppResponse.aspx"); }
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(); } } }