Skip to content

Commit 3ea12c5

Browse files
CopilotPavelBalrwmcintosh
authored
Fix TableFormula error message to show existing Y value (#2778)
* Initial plan * Fix TableFormula error message to show existing Y value Co-authored-by: PavelBal <25903040+PavelBal@users.noreply.github.com> * Improve test assertion to ensure exception is thrown Co-authored-by: PavelBal <25903040+PavelBal@users.noreply.github.com> * Use existing constructor with existingPoint instead of adding new overload Co-authored-by: rwmcintosh <261477+rwmcintosh@users.noreply.github.com> * refactor the test to make it compile and work. * add a comment in the test. --------- Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com> Co-authored-by: PavelBal <25903040+PavelBal@users.noreply.github.com> Co-authored-by: rwmcintosh <261477+rwmcintosh@users.noreply.github.com>
1 parent 4c2368c commit 3ea12c5

File tree

2 files changed

+25
-1
lines changed

2 files changed

+25
-1
lines changed

src/OSPSuite.Core/Domain/Formulas/TableFormula.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -224,7 +224,7 @@ public virtual int AddPoint(ValuePoint point)
224224
if (existingPoint.Y == point.Y)
225225
return index;
226226

227-
throw new ValuePointAlreadyExistsForPointException(point);
227+
throw new ValuePointAlreadyExistsForPointException(existingPoint);
228228
}
229229

230230
//does not exist

tests/OSPSuite.Core.Tests/Domain/TableFormulaSpecs.cs

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
using System;
12
using System.Linq;
23
using FakeItEasy;
34
using OSPSuite.BDDHelper;
@@ -143,6 +144,29 @@ public void should_throw_an_exception()
143144
{
144145
The.Action(() => sut.AddPoint(2, 30)).ShouldThrowAn<ValuePointAlreadyExistsForPointException>();
145146
}
147+
148+
[Observation]
149+
public void should_throw_an_exception_with_the_existing_y_value_in_the_message()
150+
{
151+
Exception exception = null;
152+
The.Action(() =>
153+
{
154+
try
155+
{
156+
sut.AddPoint(2, 30);
157+
}
158+
catch (Exception e)
159+
{
160+
// capture the message to verify that the new coordinate is used.
161+
exception = e;
162+
throw;
163+
}
164+
165+
}).ShouldThrowAn<ValuePointAlreadyExistsForPointException>();
166+
167+
exception.Message.Contains("x=2").ShouldBeTrue();
168+
exception.Message.Contains("y=20").ShouldBeTrue(); // The existing Y value, not the new one (30)
169+
}
146170
}
147171

148172
public class When_clearing_all_points_from_a_table_formula : concern_for_TableFormula

0 commit comments

Comments
 (0)