Skip to content

Commit 1c54d74

Browse files
committed
Fix tests
1 parent d03e068 commit 1c54d74

File tree

4 files changed

+10
-3
lines changed

4 files changed

+10
-3
lines changed

src/NHibernate.Test/Async/Linq/ParameterTests.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -320,7 +320,7 @@ public async Task CompareFloatingPointParametersAndColumnsAsync()
320320
totalParameters,
321321
sql =>
322322
{
323-
Assert.That(sql, Does.Not.Contain("cast"));
323+
Assert.That(sql, pair.Value == "Decimal" && Dialect is SQLiteDialect ? Does.Contain("cast") : Does.Not.Contain("cast"));
324324
Assert.That(GetTotalOccurrences(sql, $"Type: {pair.Value}"), Is.EqualTo(totalParameters));
325325
}));
326326
}

src/NHibernate.Test/Linq/ParameterTests.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -308,7 +308,7 @@ public void CompareFloatingPointParametersAndColumns()
308308
totalParameters,
309309
sql =>
310310
{
311-
Assert.That(sql, Does.Not.Contain("cast"));
311+
Assert.That(sql, pair.Value == "Decimal" && Dialect is SQLiteDialect ? Does.Contain("cast") : Does.Not.Contain("cast"));
312312
Assert.That(GetTotalOccurrences(sql, $"Type: {pair.Value}"), Is.EqualTo(totalParameters));
313313
});
314314
}

src/NHibernate.Test/TestCase.cs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -525,6 +525,10 @@ protected void ClearQueryPlanCache()
525525
var forPartsOfMethod = ReflectHelper.GetMethodDefinition(() => Substitute.ForPartsOf<object>());
526526
var substitute = (Dialect.Dialect) forPartsOfMethod.MakeGenericMethod(origDialect.GetType())
527527
.Invoke(null, new object[] { new object[0] });
528+
var typeNamesField = typeof(Dialect.Dialect).GetField("_typeNames", BindingFlags.Instance | BindingFlags.NonPublic);
529+
530+
// Copy the type names as the constructor is not called
531+
typeNamesField.SetValue(substitute, typeNamesField.GetValue(origDialect));
528532

529533
dialectProperty.SetValue(Sfi.Settings, substitute);
530534

src/NHibernate/Linq/Visitors/HqlGeneratorExpressionVisitor.cs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -581,7 +581,10 @@ protected HqlTreeNode VisitConstantExpression(ConstantExpression expression)
581581
_parameters.RequiredHqlParameters.Add(new NamedParameterDescriptor(namedParameter.Name, null, false));
582582
var parameter = _hqlTreeBuilder.Parameter(namedParameter.Name).AsExpression();
583583

584-
return HqlIdent.SupportsType(expression.Type)
584+
// SQLite driver binds decimal parameters to text, which can cause unexpected results in arithmetic operations.
585+
// As TransparentCast is overriden only for SQLite, we use it to add an explicit cast for decimal parameters to
586+
// reduce issues with arithmetic operations.
587+
return expression.Type.UnwrapIfNullable() == typeof(decimal)
585588
? _hqlTreeBuilder.TransparentCast(parameter, expression.Type)
586589
: parameter;
587590
}

0 commit comments

Comments
 (0)