Skip to content

Commit 3757ff6

Browse files
Forgotten async generation of truncate test
1 parent d2e8cc3 commit 3757ff6

File tree

1 file changed

+59
-0
lines changed

1 file changed

+59
-0
lines changed

src/NHibernate.Test/Async/Hql/HQLFunctions.cs

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -579,6 +579,65 @@ public async Task RoundAsync()
579579
}
580580
}
581581

582+
[Test]
583+
public async Task TruncateAsync()
584+
{
585+
AssumeFunctionSupported("truncate");
586+
587+
using (var s = OpenSession())
588+
{
589+
var a1 = new Animal("a1", 1.87f);
590+
await (s.SaveAsync(a1));
591+
var m1 = new MaterialResource("m1", "18", MaterialResource.MaterialState.Available) { Cost = 51.76m };
592+
await (s.SaveAsync(m1));
593+
await (s.FlushAsync());
594+
}
595+
using (var s = OpenSession())
596+
{
597+
var roundF = await (s.CreateQuery("select truncate(a.BodyWeight) from Animal a").UniqueResultAsync<float>());
598+
Assert.That(roundF, Is.EqualTo(1), "Selecting truncate(double) failed.");
599+
var countF =
600+
await (s
601+
.CreateQuery("select count(*) from Animal a where truncate(a.BodyWeight) = :c")
602+
.SetInt32("c", 1)
603+
.UniqueResultAsync<long>());
604+
Assert.That(countF, Is.EqualTo(1), "Filtering truncate(double) failed.");
605+
606+
roundF = await (s.CreateQuery("select truncate(a.BodyWeight, 1) from Animal a").UniqueResultAsync<float>());
607+
Assert.That(roundF, Is.EqualTo(1.8f).Within(0.01f), "Selecting truncate(double, 1) failed.");
608+
countF =
609+
await (s
610+
.CreateQuery("select count(*) from Animal a where truncate(a.BodyWeight, 1) between :c1 and :c2")
611+
.SetDouble("c1", 1.79)
612+
.SetDouble("c2", 1.81)
613+
.UniqueResultAsync<long>());
614+
Assert.That(countF, Is.EqualTo(1), "Filtering truncate(double, 1) failed.");
615+
616+
var roundD = await (s.CreateQuery("select truncate(m.Cost) from MaterialResource m").UniqueResultAsync<decimal?>());
617+
Assert.That(roundD, Is.EqualTo(51), "Selecting truncate(decimal) failed.");
618+
var count =
619+
await (s
620+
.CreateQuery("select count(*) from MaterialResource m where truncate(m.Cost) = :c")
621+
.SetInt32("c", 51)
622+
.UniqueResultAsync<long>());
623+
Assert.That(count, Is.EqualTo(1), "Filtering truncate(decimal) failed.");
624+
625+
roundD = await (s.CreateQuery("select truncate(m.Cost, 1) from MaterialResource m").UniqueResultAsync<decimal?>());
626+
Assert.That(roundD, Is.EqualTo(51.7m), "Selecting truncate(decimal, 1) failed.");
627+
628+
if (TestDialect.HasBrokenDecimalType)
629+
// SQLite fails the equality test due to using double instead, wich requires a tolerance.
630+
return;
631+
632+
count =
633+
await (s
634+
.CreateQuery("select count(*) from MaterialResource m where truncate(m.Cost, 1) = :c")
635+
.SetDecimal("c", 51.7m)
636+
.UniqueResultAsync<long>());
637+
Assert.That(count, Is.EqualTo(1), "Filtering truncate(decimal, 1) failed.");
638+
}
639+
}
640+
582641
[Test]
583642
public async Task ModAsync()
584643
{

0 commit comments

Comments
 (0)