Skip to content

Commit b94e807

Browse files
David EllingsworthDavid Ellingsworth
authored andcommitted
GH-3530: Add a warning when a driver throws an exception while retrieving a value.
1 parent f8637c7 commit b94e807

File tree

2 files changed

+16
-0
lines changed

2 files changed

+16
-0
lines changed

src/NHibernate.Test/Async/NHSpecificTest/GH3530/Fixture.cs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
using System.Data;
1313
using System.Globalization;
1414
using System.Reflection;
15+
using System.Runtime.ExceptionServices;
1516
using System.Text;
1617
using NHibernate.SqlTypes;
1718
using NUnit.Framework;
@@ -146,12 +147,19 @@ private string GetQualifiedName(string catalog, string schema, string name)
146147
using (var session = OpenSession())
147148
using (var tx = session.BeginTransaction())
148149
{
150+
AppDomain.CurrentDomain.FirstChanceException += OnFirstChanceException;
149151
var entity = await (session.GetAsync<U>(id, cancellationToken));
152+
AppDomain.CurrentDomain.FirstChanceException -= OnFirstChanceException;
150153

151154
assert(expectedValue, entity.DataValue);
152155
}
153156
}
154157

158+
private void OnFirstChanceException(object sender, FirstChanceExceptionEventArgs e)
159+
{
160+
Assert.Warn($"Driver threw a {e.Exception.GetType().Name} exception while retrieving the value.");
161+
}
162+
155163
[Test, TestCaseSource(nameof(GetTestCases))]
156164
public async Task TestNHDateTimeAsync(CultureInfo from, CultureInfo to)
157165
{

src/NHibernate.Test/NHSpecificTest/GH3530/Fixture.cs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
using System.Data;
33
using System.Globalization;
44
using System.Reflection;
5+
using System.Runtime.ExceptionServices;
56
using System.Text;
67
using NHibernate.SqlTypes;
78
using NUnit.Framework;
@@ -134,12 +135,19 @@ private void PerformTest<T, U>(CultureInfo from, CultureInfo to, T expectedValue
134135
using (var session = OpenSession())
135136
using (var tx = session.BeginTransaction())
136137
{
138+
AppDomain.CurrentDomain.FirstChanceException += OnFirstChanceException;
137139
var entity = session.Get<U>(id);
140+
AppDomain.CurrentDomain.FirstChanceException -= OnFirstChanceException;
138141

139142
assert(expectedValue, entity.DataValue);
140143
}
141144
}
142145

146+
private void OnFirstChanceException(object sender, FirstChanceExceptionEventArgs e)
147+
{
148+
Assert.Warn($"Driver threw a {e.Exception.GetType().Name} exception while retrieving the value.");
149+
}
150+
143151
[Test, TestCaseSource(nameof(GetTestCases))]
144152
public void TestNHDateTime(CultureInfo from, CultureInfo to)
145153
{

0 commit comments

Comments
 (0)