-
Notifications
You must be signed in to change notification settings - Fork 933
Db side methods #1868
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
fredericDelaporte
merged 3 commits into
nhibernate:master
from
fredericDelaporte:DbSideNowGuidRandom
Mar 22, 2020
Merged
Db side methods #1868
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,152 @@ | ||
//------------------------------------------------------------------------------ | ||
// <auto-generated> | ||
// This code was generated by AsyncGenerator. | ||
// | ||
// Changes to this file may cause incorrect behavior and will be lost if | ||
// the code is regenerated. | ||
// </auto-generated> | ||
//------------------------------------------------------------------------------ | ||
|
||
|
||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using NHibernate.Cfg; | ||
using NHibernate.SqlTypes; | ||
using NUnit.Framework; | ||
using Environment = NHibernate.Cfg.Environment; | ||
using NHibernate.Linq; | ||
|
||
namespace NHibernate.Test.Linq | ||
{ | ||
using System.Threading.Tasks; | ||
[TestFixture(false, false)] | ||
[TestFixture(true, false)] | ||
[TestFixture(false, true)] | ||
public class PreEvaluationTestsAsync : LinqTestCase | ||
{ | ||
private readonly bool LegacyPreEvaluation; | ||
private readonly bool FallbackOnPreEvaluation; | ||
|
||
public PreEvaluationTestsAsync(bool legacy, bool fallback) | ||
{ | ||
LegacyPreEvaluation = legacy; | ||
FallbackOnPreEvaluation = fallback; | ||
} | ||
|
||
protected override void Configure(Configuration configuration) | ||
{ | ||
base.Configure(configuration); | ||
|
||
configuration.SetProperty(Environment.FormatSql, "false"); | ||
configuration.SetProperty(Environment.LinqToHqlLegacyPreEvaluation, LegacyPreEvaluation.ToString()); | ||
configuration.SetProperty(Environment.LinqToHqlFallbackOnPreEvaluation, FallbackOnPreEvaluation.ToString()); | ||
} | ||
|
||
private void RunTest(bool isSupported, Action<SqlLogSpy> test) | ||
{ | ||
using (var spy = new SqlLogSpy()) | ||
{ | ||
try | ||
{ | ||
test(spy); | ||
} | ||
catch (QueryException) | ||
{ | ||
if (!isSupported && !FallbackOnPreEvaluation) | ||
// Expected failure | ||
return; | ||
throw; | ||
} | ||
} | ||
|
||
if (!isSupported && !FallbackOnPreEvaluation) | ||
Assert.Fail("The test should have thrown a QueryException, but has not thrown anything"); | ||
} | ||
|
||
[Test] | ||
public async Task CanQueryByRandomIntAsync() | ||
{ | ||
var isSupported = IsFunctionSupported("random") && IsFunctionSupported("floor"); | ||
var idMin = await (db.Orders.MinAsync(o => o.OrderId)); | ||
RunTest( | ||
isSupported, | ||
spy => | ||
{ | ||
var random = new Random(); | ||
// Dodge a Firebird driver limitation by putting the constants before the order id. | ||
// This driver cast parameters to their types in some cases for avoiding Firebird complaining of not | ||
// knowing the type of the condition. For some reasons the driver considers the casting should not be | ||
// done next to the conditional operator. Having the cast only on one side is enough for avoiding | ||
// Firebird complain, so moving the constants on the left side have been put before the order id, in | ||
// order for these constants to be casted by the driver. | ||
var x = db.Orders.Count(o => -idMin - 1 + o.OrderId < random.Next()); | ||
|
||
Assert.That(x, Is.GreaterThan(0)); | ||
// Next requires support of both floor and rand | ||
AssertFunctionInSql(IsFunctionSupported("floor") ? "random" : "floor", spy); | ||
}); | ||
} | ||
|
||
[Test] | ||
public async Task CanQueryByRandomIntWithMaxAsync() | ||
{ | ||
var isSupported = IsFunctionSupported("random") && IsFunctionSupported("floor"); | ||
var idMin = await (db.Orders.MinAsync(o => o.OrderId)); | ||
RunTest( | ||
isSupported, | ||
spy => | ||
{ | ||
var random = new Random(); | ||
// Dodge a Firebird driver limitation by putting the constants before the order id. | ||
// This driver cast parameters to their types in some cases for avoiding Firebird complaining of not | ||
// knowing the type of the condition. For some reasons the driver considers the casting should not be | ||
// done next to the conditional operator. Having the cast only on one side is enough for avoiding | ||
// Firebird complain, so moving the constants on the left side have been put before the order id, in | ||
// order for these constants to be casted by the driver. | ||
var x = db.Orders.Count(o => -idMin + o.OrderId <= random.Next(10)); | ||
|
||
Assert.That(x, Is.GreaterThan(0).And.LessThan(11)); | ||
// Next requires support of both floor and rand | ||
AssertFunctionInSql(IsFunctionSupported("floor") ? "random" : "floor", spy); | ||
}); | ||
} | ||
|
||
[Test] | ||
public async Task CanQueryByRandomIntWithMinMaxAsync() | ||
{ | ||
var isSupported = IsFunctionSupported("random") && IsFunctionSupported("floor"); | ||
var idMin = await (db.Orders.MinAsync(o => o.OrderId)); | ||
RunTest( | ||
isSupported, | ||
spy => | ||
{ | ||
var random = new Random(); | ||
// Dodge a Firebird driver limitation by putting the constants before the order id. | ||
// This driver cast parameters to their types in some cases for avoiding Firebird complaining of not | ||
// knowing the type of the condition. For some reasons the driver considers the casting should not be | ||
// done next to the conditional operator. Having the cast only on one side is enough for avoiding | ||
// Firebird complain, so moving the constants on the left side have been put before the order id, in | ||
// order for these constants to be casted by the driver. | ||
var x = db.Orders.Count(o => -idMin + o.OrderId < random.Next(1, 10)); | ||
|
||
Assert.That(x, Is.GreaterThan(0).And.LessThan(10)); | ||
// Next requires support of both floor and rand | ||
AssertFunctionInSql(IsFunctionSupported("floor") ? "random" : "floor", spy); | ||
}); | ||
} | ||
|
||
private void AssertFunctionInSql(string functionName, SqlLogSpy spy) | ||
{ | ||
if (!IsFunctionSupported(functionName)) | ||
Assert.Inconclusive($"{functionName} is not supported by the dialect"); | ||
|
||
var function = Dialect.Functions[functionName].Render(new List<object>(), Sfi).ToString(); | ||
|
||
if (LegacyPreEvaluation) | ||
Assert.That(spy.GetWholeLog(), Does.Not.Contain(function)); | ||
else | ||
Assert.That(spy.GetWholeLog(), Does.Contain(function)); | ||
} | ||
} | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.