Пример #1
0
        //public ValidatedResponse<IAdjustmentLetters> Map(CreateBatchAdjustmentLettersRequest request)
        //{
        //    var result = new IAdjustmentLetters();
        //    return ValidatedResponse<IAdjustmentLetters>.Success(result);
        //}

        private ValidatedResponse <IAdjustmentLetters> Failure(string failureMessage)
        {
            return(ValidatedResponse <IAdjustmentLetters> .Failure(new List <ValidationResult>
            {
                new ValidationResult(failureMessage)
            }));
        }
 public static ValidatedResponse <T> Failure <T>(string failureMessage)
 {
     return(ValidatedResponse <T> .Failure(
                new List <ValidationResult>
     {
         new ValidationResult(failureMessage)
     }));
 }
Пример #3
0
        private ValidatedResponse <AdjLetterBatch> GetTestData_SuccessfulValidatedRespAdjLetterBatch()
        {
            var batch = new AdjLetterBatch
            {
                JobIdentifier     = "1234",
                ProcessingDate    = new DateTime(2015, 1, 1),
                JobFolderLocation = "c:\\test"
            };

            batch.Letters.Add(GetTestData_Letter());

            return(ValidatedResponse <AdjLetterBatch> .Success(batch));
        }
Пример #4
0
        public ValidatedResponse <string> GetJobPath(string jobIdentifier)
        {
            if (string.IsNullOrEmpty(jobIdentifier))
            {
                return(ValidatedResponseHelper.Failure <string>("jobIdentifier cannot be null or empty"));
            }

            var rootLocation = config.BitLockerLocation;

            if (!fileSystem.Directory.Exists(rootLocation))
            {
                ValidatedResponseHelper.Failure <string>("Cannot find bitlocker folder location {0}", rootLocation);
            }

            var jobLocation = CreateFolderIfNotExists(rootLocation, jobIdentifier);

            return(ValidatedResponse <string> .Success(jobLocation));
        }
Пример #5
0
        public async Task WhenProcessorProcessAsyncIsCalled_ThenSaveDocumentAndPublishIsCalled()
        {
            var processor         = new AdjustmentLettersRequestProcessor(container.Object, exchange.Object, requestSplitter.Object, letterGenerator.Object, fileWriter.Object, pathHelper.Object, fileReader.Object, aspose.Object, refDb.Object);
            var cancellationToken = new CancellationToken();
            var message           = GetTestData_BatchRequest();

            processor.Message = message;
            requestSplitter.Setup(x => x.Map(It.IsAny <CreateBatchAdjustmentLettersRequest>())).Returns(GetTestData_SuccessfulValidatedRespAdjLetterBatch);
            pathHelper.Setup(x => x.GetJobPath(It.IsAny <string>())).Returns(ValidatedResponse <string> .Success("c:\\ImAFakePath"));
            refDb.Setup(x => x.GetAllBranches()).Returns(new List <Branch>()
            {
                GetTestData_Branch()
            });
            letterGenerator.Setup(x => x.GeneratePdfFromTemplate(It.IsAny <VoucherInformation>(), It.IsAny <string>())).Returns(new Document());

            await processor.ProcessAsync(cancellationToken, "", string.Empty);

            exchange.Verify(x => x.PublishAsync(It.IsAny <CreateBatchAdjustmentLettersResponse>(), It.IsAny <string>(), It.IsAny <string>()), Times.Once);
            letterGenerator.Verify(x => x.GeneratePdfFromTemplate(It.IsAny <VoucherInformation>(), It.IsAny <string>()), Times.Once);
            letterGenerator.Verify(x => x.AddVoucherImage(It.IsAny <string>(), It.IsAny <Document>(), It.IsAny <AdjustmentLetter>(), It.IsAny <IFileReader>()), Times.Once);
            aspose.Verify(x => x.SaveDocument(It.IsAny <Document>(), It.IsAny <string>()), Times.Once);
            aspose.Verify(x => x.AddPageNumbers(It.IsAny <string>()), Times.Once);
        }
Пример #6
0
        public ValidatedResponse <AdjLetterBatch> Map(CreateBatchAdjustmentLettersRequest request)
        {
            if (string.IsNullOrEmpty(request.jobIdentifier))
            {
                Log.Error("MessageToBatchConverter:Map, Request does not contain a jobIdentifier.");
                return(this.Failure("Request does not contain a jobIdentifier"));
            }

            var batch = new AdjLetterBatch();

            batch.JobFolderLocation = this.pathHelper.GetJobPath(request.jobIdentifier.Replace("/", "\\")).Result;
            batch.JobIdentifier     = request.jobIdentifier;
            batch.ProcessingDate    = request.processingDate;
            batch.PdfZipFilename    = string.Format(this.config.PdfZipFilename, this.config.Environment, request.processingDate.ToString(ReportConstants.DateTimeFormat));

            if (request.voucherInformation.Any())
            {
                var voucherGroup = request.voucherInformation.GroupBy(x => new { x.voucherProcess.transactionLinkNumber, x.voucherBatch.scannedBatchNumber });

                var index = 1;
                foreach (var group in voucherGroup)
                {
                    if (!group.Any(g => g.voucherProcess.adjustedFlag))
                    {
                        return(this.Failure(string.Format("No adjusted Voucher found for {@batchNumber}, {@TransLinkNo}",
                                                          group.First().voucherBatch.scannedBatchNumber,
                                                          group.First().voucherProcess.transactionLinkNumber)));
                    }
                    else
                    {
                        foreach (var adjustedVoucher in group.Where(vi => vi.voucherProcess.adjustedFlag))
                        {
                            var matchedCustomerDetails = request.outputMetadata.FirstOrDefault(t => t.customer.Any
                                                                                                   (g => g.accountNumber == adjustedVoucher.voucher.accountNumber &&
                                                                                                   g.bsb == adjustedVoucher.voucher.bsbNumber));

                            var filenamePrefix = "nbsb";

                            if (matchedCustomerDetails != null)
                            {
                                filenamePrefix = matchedCustomerDetails.outputFilenamePrefix;
                            }
                            else
                            {
                                Log.Warning("WARNING: {@bsb} and {@accountNumber} did not match with the reference data, Letter will be generated using" + filenamePrefix + " prefix.",
                                            adjustedVoucher.voucher.bsbNumber,
                                            adjustedVoucher.voucher.accountNumber);
                            }

                            var newLetter = new AdjustmentLetter
                            {
                                AdjustedVoucher = adjustedVoucher,
                                JobIdentifier   = request.jobIdentifier,
                                ProcessingDate  = request.processingDate,
                                PdfFilename     =
                                    string.Format("{0}_{1}.pdf", filenamePrefix, index.ToString().PadLeft(4, '0'))
                            };

                            batch.Letters.Add(newLetter);

                            newLetter.Vouchers.AddRange(group.ToList());

                            index++;
                        }
                    }
                }
            }
            else
            {
                Log.Error("[MessageToBatchConverter:Map], No vouchers found.");
                return(this.Failure("No vouchers found"));
            }

            return(ValidatedResponse <AdjLetterBatch> .Success(batch));
        }
Пример #7
0
 private ValidatedResponse <AdjLetterBatch> Failure(string failureMessage)
 {
     return(ValidatedResponse <AdjLetterBatch> .Failure(new List <ValidationResult> {
         new ValidationResult(failureMessage)
     }));
 }
Пример #8
0
 private ValidatedResponse <ILetterGenerator> Failure(string failureMessage)
 {
     return(ValidatedResponse <ILetterGenerator> .Failure(new List <ValidationResult> {
         new ValidationResult(failureMessage)
     }));
 }
Пример #9
0
        public ValidatedResponse <ILetterGenerator> Map(IAdjustmentLetters vifFileInfo)
        {
            var result = new LetterGenerator();

            return(ValidatedResponse <ILetterGenerator> .Success(result));
        }