/// <summary> /// Method to generate message and store file /// </summary> /// <param name="inputPath">Input path</param> /// <param name="outputPath">output path</param> /// <param name="templatePath">template file path</param> /// <returns></returns> public string BuildRenewalMessage(string inputPath, string outputPath, string templatePath) { int success = 0; int unsuccess = 0; //Fetching customer records var customers = _customerRepository.GetCustomers(inputPath); var templateData = File.ReadAllText(templatePath, Encoding.GetEncoding("iso-8859-1")); //Generating letter for each customer Parallel.ForEach(customers, (customer) => { try { if (_customerValidator.IsValidated(customer)) { _logger.LogInformation($"{customer.FirstName} {customer.Surname} Customer validated."); var customerModel = new CustomerModel(customer); var _outputPath = $"{outputPath}\\{customerModel.Customer.ID}_{customerModel.Customer.FirstName}.txt"; if (!File.Exists(_outputPath)) { //Creating message using template and storing. Return true if succeeded else false if (_messageBuilder.BuildMessage(customerModel: customerModel, outputPath: _outputPath, templateData: templateData)) { success++; _logger.LogInformation($"{customer.FirstName} {customer.Surname} Customer message generated."); } } else { unsuccess++; _logger.LogInformation($"{customer.FirstName} {customer.Surname} Customer Files already exists."); } } else { _logger.LogWarning($"Customer validation failed."); } } catch (Exception e) { _logger.LogError($"Error in customer service: {e.Message}"); } }); if (unsuccess == 0) { return($"{success} renewal letter generated."); } else { return($"{success} renewal letter generated. {unsuccess} files already exists."); } }
public void CustomerValidator_NullReferenceException_Test() { var validator = new CustomerValidator(); Assert.IsFalse(validator.IsValidated(null)); }