Skip to content

Commit

Permalink
nhibernateGH-3530: Add a warning when a driver throws an exception wh…
Browse files Browse the repository at this point in the history
…ile retrieving a value.
  • Loading branch information
David Ellingsworth authored and David Ellingsworth committed Jun 14, 2024
1 parent f8637c7 commit b94e807
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 0 deletions.
8 changes: 8 additions & 0 deletions src/NHibernate.Test/Async/NHSpecificTest/GH3530/Fixture.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
using System.Data;
using System.Globalization;
using System.Reflection;
using System.Runtime.ExceptionServices;
using System.Text;
using NHibernate.SqlTypes;
using NUnit.Framework;
Expand Down Expand Up @@ -146,12 +147,19 @@ private string GetQualifiedName(string catalog, string schema, string name)
using (var session = OpenSession())
using (var tx = session.BeginTransaction())
{
AppDomain.CurrentDomain.FirstChanceException += OnFirstChanceException;
var entity = await (session.GetAsync<U>(id, cancellationToken));
AppDomain.CurrentDomain.FirstChanceException -= OnFirstChanceException;

assert(expectedValue, entity.DataValue);
}
}

private void OnFirstChanceException(object sender, FirstChanceExceptionEventArgs e)
{
Assert.Warn($"Driver threw a {e.Exception.GetType().Name} exception while retrieving the value.");
}

[Test, TestCaseSource(nameof(GetTestCases))]
public async Task TestNHDateTimeAsync(CultureInfo from, CultureInfo to)
{
Expand Down
8 changes: 8 additions & 0 deletions src/NHibernate.Test/NHSpecificTest/GH3530/Fixture.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
using System.Data;
using System.Globalization;
using System.Reflection;
using System.Runtime.ExceptionServices;
using System.Text;
using NHibernate.SqlTypes;
using NUnit.Framework;
Expand Down Expand Up @@ -134,12 +135,19 @@ private void PerformTest<T, U>(CultureInfo from, CultureInfo to, T expectedValue
using (var session = OpenSession())
using (var tx = session.BeginTransaction())
{
AppDomain.CurrentDomain.FirstChanceException += OnFirstChanceException;
var entity = session.Get<U>(id);
AppDomain.CurrentDomain.FirstChanceException -= OnFirstChanceException;

assert(expectedValue, entity.DataValue);
}
}

private void OnFirstChanceException(object sender, FirstChanceExceptionEventArgs e)
{
Assert.Warn($"Driver threw a {e.Exception.GetType().Name} exception while retrieving the value.");
}

[Test, TestCaseSource(nameof(GetTestCases))]
public void TestNHDateTime(CultureInfo from, CultureInfo to)
{
Expand Down

0 comments on commit b94e807

Please sign in to comment.