From 11da2157b66a2ad0c9e7ebfb9a5122c67c3cc38a Mon Sep 17 00:00:00 2001 From: Andrey Katz Date: Mon, 13 Nov 2023 15:11:35 +0100 Subject: [PATCH 1/3] test modified to match the right expectations --- ifrs17-template/Test/ReimportTest.ipynb | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/ifrs17-template/Test/ReimportTest.ipynb b/ifrs17-template/Test/ReimportTest.ipynb index cabda5cb..fde2ab1b 100644 --- a/ifrs17-template/Test/ReimportTest.ipynb +++ b/ifrs17-template/Test/ReimportTest.ipynb @@ -205,7 +205,16 @@ { "cell_type": "code", "source": [ - "activity.Status.Should().Be(ActivityLogStatus.Succeeded);" + "activity.Status.Should().Be(ActivityLogStatus.Failed);" + ], + "metadata": {}, + "execution_count": 0, + "outputs": [] + }, + { + "cell_type": "code", + "source": [ + "DataSource.Query()" ], "metadata": {}, "execution_count": 0, From f2160759a1cb5252404660f83b869b0d821ed6e3 Mon Sep 17 00:00:00 2001 From: Andrey Katz Date: Mon, 13 Nov 2023 16:02:07 +0100 Subject: [PATCH 2/3] added the error and error message --- ifrs17/Constants/Validations.ipynb | 2 ++ 1 file changed, 2 insertions(+) diff --git a/ifrs17/Constants/Validations.ipynb b/ifrs17/Constants/Validations.ipynb index 4c8d05b8..84379dd5 100644 --- a/ifrs17/Constants/Validations.ipynb +++ b/ifrs17/Constants/Validations.ipynb @@ -164,6 +164,7 @@ "\n public static readonly Error InvalidInterpolationMethod = new Error(nameof(InvalidInterpolationMethod));", "\n public static readonly Error InvalidEconomicBasisDriver = new Error(nameof(InvalidEconomicBasisDriver));", "\n public static readonly Error InvalidReleasePattern = new Error(nameof(InvalidReleasePattern));", + "\n public static readonly Error OpeningOutsideOfInceptionYear = new Error(nameof(OpeningOutsideOfInceptionYear));", "\n", "\n // Storage Errors", "\n public static readonly Error DataNodeNotFound = new Error(nameof(DataNodeNotFound));", @@ -257,6 +258,7 @@ "\n (nameof(InvalidInterpolationMethod), 1) => $\"Invalid InterpolationMethod parameter for Data Node {s[0]}.\",", "\n (nameof(InvalidEconomicBasisDriver), 1) => $\"Invalid EconomicBasisDriver parameter for Data Node {s[0]}.\",", "\n (nameof(InvalidReleasePattern), 1) => $\"Invalid ReleasePattern parameters for Data Node {s[0]}.\",", + "\n (nameof(OpeningOutsideOfInceptionYear), 3) => $\"Provided opening for reporting node {s[0]} in {s[1]} while the mode was incepted in {s[2]}.\", ", "\n ", "\n // Storage", "\n (nameof(DataNodeNotFound), 1) => $\"DataNode {s[0]} not found.\",", From 2f866fb51fdb8a9629b133684ed8b7aad1af002c Mon Sep 17 00:00:00 2001 From: Andrey Katz Date: Mon, 13 Nov 2023 17:48:28 +0100 Subject: [PATCH 3/3] working solution with a test --- ifrs17-template/Test/ReimportTest.ipynb | 29 +++++++++++++++++++++++-- ifrs17/Constants/Validations.ipynb | 2 +- ifrs17/Import/Importers.ipynb | 10 +++++++-- 3 files changed, 36 insertions(+), 5 deletions(-) diff --git a/ifrs17-template/Test/ReimportTest.ipynb b/ifrs17-template/Test/ReimportTest.ipynb index fde2ab1b..69420b3e 100644 --- a/ifrs17-template/Test/ReimportTest.ipynb +++ b/ifrs17-template/Test/ReimportTest.ipynb @@ -205,7 +205,29 @@ { "cell_type": "code", "source": [ - "activity.Status.Should().Be(ActivityLogStatus.Failed);" + "activity.Status.Should().Be(ActivityLogStatus.Succeeded);" + ], + "metadata": {}, + "execution_count": 0, + "outputs": [] + }, + { + "cell_type": "markdown", + "source": [ + "## Check that Import into Data Source Fails " + ], + "metadata": {}, + "execution_count": 0, + "outputs": [] + }, + { + "cell_type": "code", + "source": [ + "var activity = await Import.FromString(openings)", + "\n .WithFormat(ImportFormats.Opening)", + "\n .WithTarget(DataSource)", + "\n .ExecuteAsync();", + "\nactivity" ], "metadata": {}, "execution_count": 0, @@ -214,7 +236,10 @@ { "cell_type": "code", "source": [ - "DataSource.Query()" + "var expectedMessage = Error.OpeningOutsideOfInceptionYear.GetMessage(\"DT1.1\", \"2021\", \"2020\");", + "\nactivity.Status.Should().Be(ActivityLogStatus.Failed);", + "\nactivity.Errors.Count().Should().Be(1);", + "\nactivity.Errors.FirstOrDefault().ToString().Contains(expectedMessage).Should().Be(true);" ], "metadata": {}, "execution_count": 0, diff --git a/ifrs17/Constants/Validations.ipynb b/ifrs17/Constants/Validations.ipynb index 84379dd5..cc14510a 100644 --- a/ifrs17/Constants/Validations.ipynb +++ b/ifrs17/Constants/Validations.ipynb @@ -258,7 +258,7 @@ "\n (nameof(InvalidInterpolationMethod), 1) => $\"Invalid InterpolationMethod parameter for Data Node {s[0]}.\",", "\n (nameof(InvalidEconomicBasisDriver), 1) => $\"Invalid EconomicBasisDriver parameter for Data Node {s[0]}.\",", "\n (nameof(InvalidReleasePattern), 1) => $\"Invalid ReleasePattern parameters for Data Node {s[0]}.\",", - "\n (nameof(OpeningOutsideOfInceptionYear), 3) => $\"Provided opening for reporting node {s[0]} in {s[1]} while the mode was incepted in {s[2]}.\", ", + "\n (nameof(OpeningOutsideOfInceptionYear), 3) => $\"Provided opening for data node {s[0]} in year {s[1]}, however this data node was incepted in {s[2]}.\", ", "\n ", "\n // Storage", "\n (nameof(DataNodeNotFound), 1) => $\"DataNode {s[0]} not found.\",", diff --git a/ifrs17/Import/Importers.ipynb b/ifrs17/Import/Importers.ipynb index ee7f8240..7c6c5278 100644 --- a/ifrs17/Import/Importers.ipynb +++ b/ifrs17/Import/Importers.ipynb @@ -496,9 +496,15 @@ "\n ", "\n var dataNodesImported = table.Rows.Select(x => x.Field(nameof(RawVariable.DataNode))).ToHashSet();", "\n var dataNodesDefined = await targetDataSource.Query().Where(x => dataNodesImported.Contains(x.SystemName)).ToArrayAsync();", - "\n var dataNodeStatesDefined = await targetDataSource.Query().Select(x => x.DataNode).ToArrayAsync();", + "\n var dataNodeStatesDefined = await targetDataSource.Query().Select(x => new {DataNode = x.DataNode, InceptionYear = x.Year}).ToArrayAsync();", + "\n if (tableName == ImportFormats.Opening){", + "\n var dataNodesWithWrongOpeningYear = dataNodeStatesDefined.Where(x => dataNodesImported.Contains(x.DataNode) && x.InceptionYear != args.Year);", + "\n if (dataNodesWithWrongOpeningYear.Any()) ", + "\n foreach(var element in dataNodesWithWrongOpeningYear) ", + "\n ApplicationMessage.Log(Error.OpeningOutsideOfInceptionYear, element.DataNode, args.Year.ToString(), element.InceptionYear.ToString());", + "\n }", "\n var dataNodeParametersDefined = await targetDataSource.Query().Select(x => x.DataNode).ToArrayAsync(); ", - "\n var dataNodeStatesUndefined = dataNodesImported.Where(x => x != null && !dataNodeStatesDefined.Contains(x)).ToHashSet();", + "\n var dataNodeStatesUndefined = dataNodesImported.Where(x => x != null && !dataNodeStatesDefined.Select(x => x.DataNode).Contains(x)).ToHashSet();", "\n var dataNodeSingleParametersUndefined = dataNodesImported.Where(x => x != null &&", "\n !dataNodeParametersDefined.Contains(x) && ", "\n dataNodesDefined.SingleOrDefault(y => y.SystemName == x) is GroupOfInsuranceContract).ToHashSet();",