From d788bd0fd4a2b265e18f2f52f9b84d8e125f8fb2 Mon Sep 17 00:00:00 2001 From: Kevin Joy Date: Mon, 20 Jan 2025 16:11:09 +0000 Subject: [PATCH] Change or statecode --- .../EWCWalesImport/EwcWalesInductionImportData.cs | 4 +++- .../Jobs/EWCWalesImport/InductionImporter.cs | 11 ++++++++--- .../Jobs/EWCWalesImport/QtsImporter.cs | 7 ++++++- .../EwcWalesImport/EwcWalesInductionImportData.cs | 4 +++- .../Jobs/EwcWalesImport/InductionImporter.cs | 11 ++++++++--- .../Jobs/EwcWalesImport/QtsImporter.cs | 7 ++++++- .../Jobs/EwcWalesImportJobTests.cs | 6 +++--- 7 files changed, 37 insertions(+), 13 deletions(-) diff --git a/TeachingRecordSystem/src/TeachingRecordSystem.Core/Jobs/EWCWalesImport/EwcWalesInductionImportData.cs b/TeachingRecordSystem/src/TeachingRecordSystem.Core/Jobs/EWCWalesImport/EwcWalesInductionImportData.cs index e7aa90edd..517a5cd05 100644 --- a/TeachingRecordSystem/src/TeachingRecordSystem.Core/Jobs/EWCWalesImport/EwcWalesInductionImportData.cs +++ b/TeachingRecordSystem/src/TeachingRecordSystem.Core/Jobs/EWCWalesImport/EwcWalesInductionImportData.cs @@ -1,4 +1,7 @@ +using CsvHelper.Configuration; +using CsvHelper; using CsvHelper.Configuration.Attributes; +using CsvHelper.TypeConversion; namespace TeachingRecordSystem.Core.Jobs.EWCWalesImport; @@ -35,4 +38,3 @@ public record EwcWalesInductionImportData public required string InductionStatusName { get; set; } } - diff --git a/TeachingRecordSystem/src/TeachingRecordSystem.Core/Jobs/EWCWalesImport/InductionImporter.cs b/TeachingRecordSystem/src/TeachingRecordSystem.Core/Jobs/EWCWalesImport/InductionImporter.cs index 92d6aeadf..13d95bca0 100644 --- a/TeachingRecordSystem/src/TeachingRecordSystem.Core/Jobs/EWCWalesImport/InductionImporter.cs +++ b/TeachingRecordSystem/src/TeachingRecordSystem.Core/Jobs/EWCWalesImport/InductionImporter.cs @@ -1,6 +1,7 @@ using System.Globalization; using System.Text; using CsvHelper; +using CsvHelper.Configuration; using Microsoft.Extensions.Logging; using Microsoft.Xrm.Sdk; using Microsoft.Xrm.Sdk.Query; @@ -26,7 +27,11 @@ public InductionImporter(ICrmQueryDispatcher crmQueryDispatcher, ILogger ImportAsync(StreamReader csvReaderStream, string fileName) { - using (var csv = new CsvReader(csvReaderStream, CultureInfo.InvariantCulture)) + var csvConfig = new CsvConfiguration(CultureInfo.InvariantCulture) + { + TrimOptions = TrimOptions.Trim + }; + using (var csv = new CsvReader(csvReaderStream, csvConfig)) { var integrationJob = new CreateIntegrationTransactionQuery() { @@ -164,7 +169,7 @@ public async Task ImportAsync(StreamReader csvReaderStrea //increase failurecount if row is processable or if there are validation failures //else increase success counter - if (validationFailures.ValidationFailures.Any() || validationFailures.Errors.Any()) + if (validationFailures.Errors.Any()) { failureRowCount++; } @@ -186,7 +191,7 @@ public async Task ImportAsync(StreamReader csvReaderStrea InductionPeriodId = inductionPeriodId, DuplicateStatus = null, FailureMessage = itrFailureMessage.ToString(), - StatusCode = string.IsNullOrEmpty(itrFailureMessage.ToString()) ? dfeta_integrationtransactionrecord_StatusCode.Success : dfeta_integrationtransactionrecord_StatusCode.Fail, + StatusCode = validationFailures.Errors.Count == 0 ? dfeta_integrationtransactionrecord_StatusCode.Success : dfeta_integrationtransactionrecord_StatusCode.Fail, RowData = ConvertToCSVString(row), FileName = fileName }; diff --git a/TeachingRecordSystem/src/TeachingRecordSystem.Core/Jobs/EWCWalesImport/QtsImporter.cs b/TeachingRecordSystem/src/TeachingRecordSystem.Core/Jobs/EWCWalesImport/QtsImporter.cs index de861fea6..132403217 100644 --- a/TeachingRecordSystem/src/TeachingRecordSystem.Core/Jobs/EWCWalesImport/QtsImporter.cs +++ b/TeachingRecordSystem/src/TeachingRecordSystem.Core/Jobs/EWCWalesImport/QtsImporter.cs @@ -1,6 +1,7 @@ using System.Globalization; using System.Text; using CsvHelper; +using CsvHelper.Configuration; using Microsoft.Extensions.Logging; using Microsoft.Xrm.Sdk.Query; using TeachingRecordSystem.Core.DataStore.Postgres; @@ -27,7 +28,11 @@ public QtsImporter(ICrmQueryDispatcher crmQueryDispatcher, ILogger ImportAsync(StreamReader csvReaderStream, string fileName) { - using var csv = new CsvReader(csvReaderStream, CultureInfo.InvariantCulture); + var csvConfig = new CsvConfiguration(CultureInfo.InvariantCulture) + { + TrimOptions = TrimOptions.Trim + }; + using var csv = new CsvReader(csvReaderStream, csvConfig); var records = csv.GetRecords().ToList(); var totalRowCount = 0; var successCount = 0; diff --git a/TeachingRecordSystem/src/TeachingRecordSystem.Core/Jobs/EwcWalesImport/EwcWalesInductionImportData.cs b/TeachingRecordSystem/src/TeachingRecordSystem.Core/Jobs/EwcWalesImport/EwcWalesInductionImportData.cs index e7aa90edd..517a5cd05 100644 --- a/TeachingRecordSystem/src/TeachingRecordSystem.Core/Jobs/EwcWalesImport/EwcWalesInductionImportData.cs +++ b/TeachingRecordSystem/src/TeachingRecordSystem.Core/Jobs/EwcWalesImport/EwcWalesInductionImportData.cs @@ -1,4 +1,7 @@ +using CsvHelper.Configuration; +using CsvHelper; using CsvHelper.Configuration.Attributes; +using CsvHelper.TypeConversion; namespace TeachingRecordSystem.Core.Jobs.EWCWalesImport; @@ -35,4 +38,3 @@ public record EwcWalesInductionImportData public required string InductionStatusName { get; set; } } - diff --git a/TeachingRecordSystem/src/TeachingRecordSystem.Core/Jobs/EwcWalesImport/InductionImporter.cs b/TeachingRecordSystem/src/TeachingRecordSystem.Core/Jobs/EwcWalesImport/InductionImporter.cs index 92d6aeadf..13d95bca0 100644 --- a/TeachingRecordSystem/src/TeachingRecordSystem.Core/Jobs/EwcWalesImport/InductionImporter.cs +++ b/TeachingRecordSystem/src/TeachingRecordSystem.Core/Jobs/EwcWalesImport/InductionImporter.cs @@ -1,6 +1,7 @@ using System.Globalization; using System.Text; using CsvHelper; +using CsvHelper.Configuration; using Microsoft.Extensions.Logging; using Microsoft.Xrm.Sdk; using Microsoft.Xrm.Sdk.Query; @@ -26,7 +27,11 @@ public InductionImporter(ICrmQueryDispatcher crmQueryDispatcher, ILogger ImportAsync(StreamReader csvReaderStream, string fileName) { - using (var csv = new CsvReader(csvReaderStream, CultureInfo.InvariantCulture)) + var csvConfig = new CsvConfiguration(CultureInfo.InvariantCulture) + { + TrimOptions = TrimOptions.Trim + }; + using (var csv = new CsvReader(csvReaderStream, csvConfig)) { var integrationJob = new CreateIntegrationTransactionQuery() { @@ -164,7 +169,7 @@ public async Task ImportAsync(StreamReader csvReaderStrea //increase failurecount if row is processable or if there are validation failures //else increase success counter - if (validationFailures.ValidationFailures.Any() || validationFailures.Errors.Any()) + if (validationFailures.Errors.Any()) { failureRowCount++; } @@ -186,7 +191,7 @@ public async Task ImportAsync(StreamReader csvReaderStrea InductionPeriodId = inductionPeriodId, DuplicateStatus = null, FailureMessage = itrFailureMessage.ToString(), - StatusCode = string.IsNullOrEmpty(itrFailureMessage.ToString()) ? dfeta_integrationtransactionrecord_StatusCode.Success : dfeta_integrationtransactionrecord_StatusCode.Fail, + StatusCode = validationFailures.Errors.Count == 0 ? dfeta_integrationtransactionrecord_StatusCode.Success : dfeta_integrationtransactionrecord_StatusCode.Fail, RowData = ConvertToCSVString(row), FileName = fileName }; diff --git a/TeachingRecordSystem/src/TeachingRecordSystem.Core/Jobs/EwcWalesImport/QtsImporter.cs b/TeachingRecordSystem/src/TeachingRecordSystem.Core/Jobs/EwcWalesImport/QtsImporter.cs index de861fea6..132403217 100644 --- a/TeachingRecordSystem/src/TeachingRecordSystem.Core/Jobs/EwcWalesImport/QtsImporter.cs +++ b/TeachingRecordSystem/src/TeachingRecordSystem.Core/Jobs/EwcWalesImport/QtsImporter.cs @@ -1,6 +1,7 @@ using System.Globalization; using System.Text; using CsvHelper; +using CsvHelper.Configuration; using Microsoft.Extensions.Logging; using Microsoft.Xrm.Sdk.Query; using TeachingRecordSystem.Core.DataStore.Postgres; @@ -27,7 +28,11 @@ public QtsImporter(ICrmQueryDispatcher crmQueryDispatcher, ILogger ImportAsync(StreamReader csvReaderStream, string fileName) { - using var csv = new CsvReader(csvReaderStream, CultureInfo.InvariantCulture); + var csvConfig = new CsvConfiguration(CultureInfo.InvariantCulture) + { + TrimOptions = TrimOptions.Trim + }; + using var csv = new CsvReader(csvReaderStream, csvConfig); var records = csv.GetRecords().ToList(); var totalRowCount = 0; var successCount = 0; diff --git a/TeachingRecordSystem/tests/TeachingRecordSystem.Core.Tests/Jobs/EwcWalesImportJobTests.cs b/TeachingRecordSystem/tests/TeachingRecordSystem.Core.Tests/Jobs/EwcWalesImportJobTests.cs index fe2fef0f2..1a8ef5d11 100644 --- a/TeachingRecordSystem/tests/TeachingRecordSystem.Core.Tests/Jobs/EwcWalesImportJobTests.cs +++ b/TeachingRecordSystem/tests/TeachingRecordSystem.Core.Tests/Jobs/EwcWalesImportJobTests.cs @@ -444,9 +444,9 @@ public async Task EwcWalesImportJobInduction_WithInvalidEmployerCode_ReturnsExpe { // Arrange var expectedTotalRowCount = 1; - var expectedSuccessCount = 0; + var expectedSuccessCount = 1; var expectedDuplicateRowCount = 0; - var expectedFailureRowCount = 1; + var expectedFailureRowCount = 0; var person = await TestData.CreatePersonAsync(x => x.WithTrn()); var trn1 = person.Trn; var inductionStartDate = new DateTime(2024, 05, 01); @@ -470,7 +470,7 @@ public async Task EwcWalesImportJobInduction_WithInvalidEmployerCode_ReturnsExpe item1 => { Assert.Contains($"Organisation with Induction Body Code {invalidEmployeCode} was not found.", item1.dfeta_FailureMessage); - Assert.Equal(dfeta_integrationtransactionrecord_StatusCode.Fail, item1.StatusCode); + Assert.Equal(dfeta_integrationtransactionrecord_StatusCode.Success, item1.StatusCode); }); Assert.NotNull(induction); Assert.Equal(expectedTotalRowCount, integrationTransaction.dfeta_TotalCount);