public void ValidatesAttachmentExistTest() { // Arrange _mockApplicationService.Setup(m => m.GetApplicationById(It.IsAny <Guid>())).Returns(new ApplicationSubmission() { Id = "CE7F5AA5-6832-43FE-BAE1-80D14CD8F663" }); var application = _mockApplicationService.Object.GetApplicationById(new Guid("CE7F5AA5-6832-43FE-BAE1-80D14CD8F663")); Dictionary <string, Attachment> attachments = new Dictionary <string, Attachment>() { { "Test", new Attachment() { Id = "CE7F5AA5-6832-33FE-BAE1-80D14CD8F233", OriginalFileName = "test.pdf" } } }; _mockAttachmentService.Setup(mock => mock.GetApplicationAttachments(ref application)).Returns(attachments); // Act ApplicationDocumentHelper applicationDocumentHelper = new ApplicationDocumentHelper(_mockApplicationService.Object, _mockAttachmentService.Object, _mockResponseService.Object); var applicationAttachmentsData = applicationDocumentHelper.FindAllApplicationAttachmentsNotExistInFileSystem(application); // Assert Assert.AreEqual(applicationAttachmentsData.Count, 0); }
public void ApplicationDataTest_Invalid() { _mockApplicationService.Setup(mock => mock.GetApplicationById(It.IsAny <Guid>())).Returns((ApplicationSubmission)null); string testFilePath = Path.GetFullPath(Path.Combine(AppDomain.CurrentDomain.BaseDirectory, @"..\..\TestFiles")); var applicationViewTemplatePath = Path.Combine(testFilePath, "Section14cApplicationPdfView.html"); ApplicationDocumentHelper applicationDocumentHelper = new ApplicationDocumentHelper(_mockApplicationService.Object, _mockAttachmentService.Object); var applicationAttachmentsData = applicationDocumentHelper.ApplicationData(new Guid("CE7F5AA5-6832-43FE-BAE1-80D14CD8F663"), applicationViewTemplatePath); }
public async Task <IHttpActionResult> GetApplicationDocument(Guid applicationId) { byte[] buffer = null; try { // Get Application Template var applicationTemplatesPath = System.Web.Hosting.HostingEnvironment.MapPath(@"~/App_Data/HtmlTemplates"); var templatefiles = Directory.GetFiles(applicationTemplatesPath, "*.html").OrderBy(f => new FileInfo(f).Name).ToList(); ApplicationDocumentHelper applicationDocumentHelper = new ApplicationDocumentHelper(_applicationService, _attachmentService, _responseService); var applicationAttachmentsData = applicationDocumentHelper.ApplicationData(applicationId, templatefiles); /* * PDF API call was not working. Commented the below block of code and replaced by calling Concatenate() method. * TODO: Replace EMail API call too. * * // Calling Concatenate Web API * var baseUri = new Uri(AppSettings.Get<string>("PdfApiBaseUrl")); * var httpClientConnectionLeaseTimeout = AppSettings.Get<int>("HttpClientConnectionLeaseTimeout"); * // Get Http Client * var httpClientInstance = MyHttpClient; * httpClientInstance.DefaultRequestHeaders.Clear(); * httpClientInstance.DefaultRequestHeaders.ConnectionClose = false; * httpClientInstance.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/pdf")); * if (httpClientInstance.BaseAddress != baseUri) * httpClientInstance.BaseAddress = baseUri; * ServicePointManager.FindServicePoint(baseUri).ConnectionLeaseTimeout = httpClientConnectionLeaseTimeout; * * // Call Document Management Web API * var pdfGenerationResponse = await httpClientInstance.PostAsJsonAsync<List<PDFContentData>>("/api/documentmanagement/Concatenate", applicationAttachmentsData); * // Get return value from API call * buffer = await pdfGenerationResponse.Content.ReadAsAsync<byte[]>(); */ var pdfGenerationResponse = Concatenate(applicationAttachmentsData); // Get return value from API call var contentResult = pdfGenerationResponse as OkNegotiatedContentResult <byte[]>; buffer = contentResult.Content; if (buffer == null) { InternalServerError("Concatenate Pdf failed"); } } catch (Exception ex) { if (ex is ObjectNotFoundException || ex is FileNotFoundException) { NotFound("Not found"); } InternalServerError(ex.Message); } // This will return the pdf file byte array return(Ok(buffer)); }
public void ApplicationDataTest_Invalid() { _mockApplicationService.Setup(mock => mock.GetApplicationById(It.IsAny <Guid>())).Returns((ApplicationSubmission)null); var applicationViewTemplatePath = Path.Combine(testFilePath, "Section14cApplicationPdfView.html"); ApplicationDocumentHelper applicationDocumentHelper = new ApplicationDocumentHelper(_mockApplicationService.Object, _mockAttachmentService.Object, _mockResponseService.Object); var applicationAttachmentsData = applicationDocumentHelper.ApplicationData(new Guid("CE7F5AA5-6832-43FE-BAE1-80D14CD8F663"), new List <string>() { applicationViewTemplatePath }); }
public async Task <IHttpActionResult> GetApplicationDocument(Guid applicationId) { byte[] buffer = null; try { // Get Application Template var applicationViewTemplatePath = System.Web.Hosting.HostingEnvironment.MapPath(@"~/App_Data/Section14cApplicationPdfView.html"); ApplicationDocumentHelper applicationDocumentHelper = new ApplicationDocumentHelper(_applicationService, _attachmentService); var applicationAttachmentsData = applicationDocumentHelper.ApplicationData(applicationId, applicationViewTemplatePath); // Calling Concatenate Web API var baseUri = new Uri(AppSettings.Get <string>("PdfApiBaseUrl")); var httpClientConnectionLeaseTimeout = AppSettings.Get <int>("HttpClientConnectionLeaseTimeout"); // Get Http Client var httpClientInstance = MyHttpClient; httpClientInstance.DefaultRequestHeaders.Clear(); httpClientInstance.DefaultRequestHeaders.ConnectionClose = false; httpClientInstance.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/pdf")); if (httpClientInstance.BaseAddress != baseUri) { httpClientInstance.BaseAddress = baseUri; } ServicePointManager.FindServicePoint(baseUri).ConnectionLeaseTimeout = httpClientConnectionLeaseTimeout; // Call Document Management Web API var pdfGenerationResponse = await httpClientInstance.PostAsJsonAsync <List <PDFContentData> >("/api/documentmanagement/Concatenate", applicationAttachmentsData); // Get return value from API call buffer = await pdfGenerationResponse.Content.ReadAsAsync <byte[]>(); if (buffer == null) { InternalServerError("Concatenate Pdf failed"); } } catch (Exception ex) { if (ex is ObjectNotFoundException || ex is FileNotFoundException) { NotFound("Not found"); } InternalServerError(ex.Message); } // This will return the pdf file byte array return(Ok(buffer)); }
public void ApplicationDataTest() { // Setup ApplicationSubmission testApplication = new ApplicationSubmission(); List <Attachment> attachments = new List <Attachment>(); List <PDFContentData> pdfContentList = new List <PDFContentData>(); _mockApplicationService.Setup(mock => mock.GetApplicationById(It.IsAny <Guid>())).Returns(testApplication); _mockAttachmentService.Setup(mock => mock.GetApplicationFormViewContent(testApplication, It.IsAny <string>())).Returns("This is some HTML that is filled in"); _mockAttachmentService.Setup(mock => mock.GetApplicationAttachments(testApplication)).Returns(attachments); _mockAttachmentService.Setup(mock => mock.PrepareApplicationContentsForPdfConcatenation(attachments, It.IsAny <string>())).Returns(pdfContentList); // Execute string testFilePath = Path.GetFullPath(Path.Combine(AppDomain.CurrentDomain.BaseDirectory, @"..\..\TestFiles")); var applicationViewTemplatePath = Path.Combine(testFilePath, "Section14cApplicationPdfView.html"); ApplicationDocumentHelper applicationDocumentHelper = new ApplicationDocumentHelper(_mockApplicationService.Object, _mockAttachmentService.Object); var applicationAttachmentsData = applicationDocumentHelper.ApplicationData(new Guid("CE7F5AA5-6832-43FE-BAE1-80D14CD8F666"), applicationViewTemplatePath); // Assert _mockAttachmentService.Verify(mock => mock.PrepareApplicationContentsForPdfConcatenation(attachments, "This is some HTML that is filled in"), Times.Once()); Assert.AreEqual(pdfContentList, applicationAttachmentsData, "returns the expected data"); }
public async Task <IHttpActionResult> Submit([FromBody] ApplicationSubmission submission) { var results = _applicationSubmissionValidator.Validate(submission); if (!results.IsValid) { BadRequest(results.Errors.ToString()); } var account = new AccountController(_employerService, _organizationService, _identityService); account.UserManager = UserManager; var userInfo = account.GetUserInfo(); _applicationService.ProcessModel(submission); // make sure user has permission to submit application var hasPermission = _identityService.HasSavePermission(userInfo, submission.Id); if (!hasPermission) { Unauthorized("Unauthorized"); } // Find all the attachments that are not in the file system ApplicationDocumentHelper applicationDocumentHelper = new ApplicationDocumentHelper(_applicationService, _attachmentService, _responseService); var getMissingAttachment = applicationDocumentHelper.FindAllApplicationAttachmentsNotExistInFileSystem(submission); if (getMissingAttachment != null && getMissingAttachment.Count > 0) { // Create file not found message // Alert user that one or more attachments are not exist in the file system var responseMessage = Request.CreateResponse(HttpStatusCode.NotFound); responseMessage.Content = new ObjectContent <List <VerifyAttachmentViewModel> >(getMissingAttachment, GlobalConfiguration.Configuration.Formatters.JsonFormatter); return(ResponseMessage(responseMessage)); } var user = UserManager.Users.SingleOrDefault(s => s.Id == userInfo.UserId); var org = user.Organizations.FirstOrDefault(x => x.ApplicationId == submission.Id); if (org.ApplicationStatusId == StatusIds.InProgress) { await _applicationService.SubmitApplicationAsync(submission); // Update Organization Status org.ApplicationStatusId = StatusIds.Submitted; user.Organizations.Select(x => x.Employer).ToList(); await UserManager.UpdateAsync(user); } // remove the associated application save _saveService.Remove(submission.Id); var response = await GetApplicationDocument(new Guid(submission.Id)); // Get return value from API call var contentResult = response as OkNegotiatedContentResult <byte[]>; var returnValue = contentResult.Content; if (returnValue == null) { InternalServerError("Get concatenate Pdf failed"); } // Calling Email Web API var baseUri = new Uri(AppSettings.Get <string>("EmailApiBaseUrl")); var httpClientConnectionLeaseTimeout = AppSettings.Get <int>("HttpClientConnectionLeaseTimeout"); // Get Http Client var httpClientInstance = MyHttpClient; httpClientInstance.DefaultRequestHeaders.Clear(); httpClientInstance.DefaultRequestHeaders.ConnectionClose = false; httpClientInstance.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json")); if (httpClientInstance.BaseAddress != baseUri) { httpClientInstance.BaseAddress = baseUri; } ServicePointManager.FindServicePoint(baseUri).ConnectionLeaseTimeout = httpClientConnectionLeaseTimeout; // Get Email Contents var certificationTeamEmailTemplatePath = System.Web.Hosting.HostingEnvironment.MapPath(@"~/App_Data/CertificationTeamEmailTemplate.txt"); var certificationTeamEmailTemplateString = File.ReadAllText(certificationTeamEmailTemplatePath); var employerEmailTemplatePath = System.Web.Hosting.HostingEnvironment.MapPath(@"~/App_Data/EmployerEmailTemplate.txt"); var employerEmailTemplateString = File.ReadAllText(employerEmailTemplatePath); var emailContents = _emailService.PrepareApplicationEmailContents(submission, certificationTeamEmailTemplateString, employerEmailTemplateString, EmailReceiver.Both); var pdfName = string.Format("14c_Application_{0}_{1}_{2}.pdf", submission.Employer.PhysicalAddress.State, DateTime.Now.ToString("yyyy-MM-dd"), Regex.Replace(submission.Employer.LegalName, @"\s+", "-")); // Call Document Management Web API foreach (var content in emailContents) { content.Value.Attachments = new Dictionary <string, byte[]>() { { pdfName, returnValue } }; await httpClientInstance.PostAsJsonAsync <EmailContent>("/api/email/sendemail", content.Value); } return(Ok()); }
public void ApplicationDataTest() { // Setup ApplicationSubmission testApplication = new ApplicationSubmission(); var wioaworker = new List <WIOAWorker>() { new WIOAWorker() { WIOAWorkerVerifiedId = 1 } }; var wIOA = new WIOA() { WIOAWorkers = wioaworker }; testApplication.WIOA = wIOA; var workSites = new List <WorkSite>() { new WorkSite() { WorkSiteTypeId = 1, Employees = new List <Employee>() { new Employee() } } }; testApplication.WorkSites = workSites; var applicationSubmissionEstablishmentTypes = new List <ApplicationSubmissionEstablishmentType>() { new ApplicationSubmissionEstablishmentType() { EstablishmentTypeId = 1 } }; testApplication.EstablishmentType = applicationSubmissionEstablishmentTypes; var employerInfoProvidingFacilitiesDeductionTypes = new List <EmployerInfoProvidingFacilitiesDeductionType>() { new EmployerInfoProvidingFacilitiesDeductionType() { ProvidingFacilitiesDeductionType = new Response() { Display = "Test" } } }; testApplication.Employer = new EmployerInfo() { ProvidingFacilitiesDeductionType = employerInfoProvidingFacilitiesDeductionTypes }; Dictionary <string, Attachment> attachments = new Dictionary <string, Attachment>(); List <PDFContentData> pdfContentList = new List <PDFContentData>(); Response response = new Response(); _mockApplicationService.Setup(mock => mock.GetApplicationById(It.IsAny <Guid>())).Returns(testApplication); _mockAttachmentService.Setup(mock => mock.GetApplicationFormViewContent(testApplication, It.IsAny <string>())).Returns("This is some HTML that is filled in"); _mockAttachmentService.Setup(mock => mock.GetApplicationAttachments(ref testApplication)).Returns(attachments); _mockAttachmentService.Setup(mock => mock.PrepareApplicationContentsForPdfConcatenation(attachments, It.IsAny <List <string> >())).Returns(pdfContentList); _mockResponseService.Setup(mock => mock.GetResponseById(It.IsAny <string>())).Returns(response); // Execute var applicationViewTemplatePath = Path.Combine(testFilePath, "Section14cApplicationPdfView.html"); ApplicationDocumentHelper applicationDocumentHelper = new ApplicationDocumentHelper(_mockApplicationService.Object, _mockAttachmentService.Object, _mockResponseService.Object); var applicationAttachmentsData = applicationDocumentHelper.ApplicationData(new Guid("CE7F5AA5-6832-43FE-BAE1-80D14CD8F666"), new List <string>() { applicationViewTemplatePath }); // Assert _mockAttachmentService.Verify(mock => mock.PrepareApplicationContentsForPdfConcatenation(attachments, new List <string>() { "This is some HTML that is filled in" }), Times.Once()); Assert.AreEqual(pdfContentList, applicationAttachmentsData, "returns the expected data"); }