Skip to content

Commit 544e6ab

Browse files
committed
IssueJira0786: Tests optimized to support both SqlServer and PostgreSql
1 parent 5e6a645 commit 544e6ab

3 files changed

Lines changed: 130 additions & 63 deletions

File tree

Orm/Xtensive.Orm.Tests/Issues/IssueJira0786_SqlServerAggregatesProblem/AggregatesProblemTestBase.cs

Lines changed: 23 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// Copyright (C) 2020 Xtensive LLC.
1+
// Copyright (C) 2020-2024 Xtensive LLC.
22
// This code is distributed under MIT license terms.
33
// See the License.txt file in the project root for more information.
44
// Created by: Alexey Kulakov
@@ -15,9 +15,12 @@ namespace Xtensive.Orm.Tests.Issues.IssueJira0786_SqlServerAggregatesProblem
1515
{
1616
public abstract class AggregatesProblemTestBase : AutoBuildTest
1717
{
18-
protected const decimal FloatValueAccuracy = 0.000001m;
19-
protected const decimal DoubleValueAccuracy = 0.00000000000001m;
20-
protected const decimal DecimalValueAccuracy = 0.00000000000000001m;
18+
private bool refillDatabase = false;
19+
20+
protected decimal FloatValueAccuracy { get; private set; } = 0.000001m;
21+
protected decimal DoubleValueAccuracy { get; private set; } = 0.00000000000001m;
22+
protected decimal DecimalValueAccuracy { get; private set; } = 0.00000000000000001m;
23+
2124

2225
protected override Domain BuildDomain(DomainConfiguration configuration)
2326
{
@@ -31,6 +34,7 @@ protected override Domain BuildDomain(DomainConfiguration configuration)
3134
throw;
3235
}
3336

37+
refillDatabase = true;
3438
var secondTryConfig = configuration.Clone();
3539
secondTryConfig.UpgradeMode = DomainUpgradeMode.Recreate;
3640
return base.BuildDomain(secondTryConfig);
@@ -44,13 +48,24 @@ protected override DomainConfiguration BuildConfiguration()
4448
return configuration;
4549
}
4650

47-
protected override void CheckRequirements()
48-
{
49-
Require.ProviderIs(StorageProvider.SqlServer | StorageProvider.PostgreSql);
50-
}
51+
protected override void CheckRequirements() => Require.ProviderIs(StorageProvider.SqlServer | StorageProvider.PostgreSql);
5152

5253
protected override void PopulateData()
5354
{
55+
if (StorageProviderInfo.Instance.CheckProviderIs(StorageProvider.PostgreSql)) {
56+
// We have to change some scales of result values of average in SQL
57+
// because PostgreSQL does not provide ways to read raw value and reduce it
58+
// to fit into .NET decimal value, as we reduce scale for values in MS SQL Server provider.
59+
60+
FloatValueAccuracy = 0.00001m;
61+
DoubleValueAccuracy = 0.00001m;
62+
DecimalValueAccuracy = 0.00001m;
63+
}
64+
65+
if (!refillDatabase)
66+
return;
67+
68+
5469
using (var session = Domain.OpenSession())
5570
using (var tx = session.OpenTransaction()) {
5671
_ = new TestEntity() {

Orm/Xtensive.Orm.Tests/Issues/IssueJira0786_SqlServerAggregatesProblem/AverageProcessingTest.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// Copyright (C) 2020 Xtensive LLC.
1+
// Copyright (C) 2020-2024 Xtensive LLC.
22
// This code is distributed under MIT license terms.
33
// See the License.txt file in the project root for more information.
44
// Created by: Alexey Kulakov
@@ -1614,7 +1614,7 @@ public void DoubleFieldExpressionTest02()
16141614
using (var tx = session.OpenTransaction()) {
16151615
var queryableResult = session.Query.All<TestEntity>().Average(i => (decimal) i.DoubleValue1 * i.DecimalValue);
16161616
var enumerableResult = session.Query.All<TestEntity>().AsEnumerable().Average(i => (decimal) i.DoubleValue1 * i.DecimalValue);
1617-
Assert.That(Math.Abs(queryableResult - decimal.Round(enumerableResult, 19)), Is.LessThan(DoubleValueAccuracy));
1617+
Assert.That(Math.Abs(queryableResult - enumerableResult), Is.LessThan(DoubleValueAccuracy));
16181618
}
16191619
}
16201620

@@ -1625,7 +1625,7 @@ public void DecimalFieldExpressionTest()
16251625
using (var tx = session.OpenTransaction()) {
16261626
var queryableResult = session.Query.All<TestEntity>().Average(i => i.DecimalValue * i.DecimalValue);
16271627
var enumerableResult = session.Query.All<TestEntity>().AsEnumerable().Average(i => i.DecimalValue * i.DecimalValue);
1628-
Assert.That(Math.Abs(queryableResult - decimal.Round(enumerableResult, 19)), Is.LessThan(DecimalValueAccuracy));
1628+
Assert.That(Math.Abs(queryableResult - enumerableResult), Is.LessThan(DecimalValueAccuracy));
16291629
}
16301630
}
16311631

@@ -3011,7 +3011,7 @@ public void NullableDoubleFieldExpressionTest02()
30113011
using (var tx = session.OpenTransaction()) {
30123012
var queryableResult = session.Query.All<TestEntity>().Average(i => (decimal?) i.NullableDoubleValue1 * i.NullableDecimalValue);
30133013
var enumerableResult = session.Query.All<TestEntity>().AsEnumerable().Average(i => (decimal?) i.NullableDoubleValue1 * i.NullableDecimalValue);
3014-
Assert.That(Math.Abs(queryableResult.Value - decimal.Round(enumerableResult.Value, 19)), Is.LessThan(DoubleValueAccuracy));
3014+
Assert.That(Math.Abs(queryableResult.Value - enumerableResult.Value), Is.LessThan(DoubleValueAccuracy));
30153015
}
30163016
}
30173017

0 commit comments

Comments
 (0)