Skip to content

Commit 859cc3b

Browse files
committed
test: decimal 22,9/30,10 round-trip; close connections
1 parent a8dcb20 commit 859cc3b

File tree

1 file changed

+58
-31
lines changed

1 file changed

+58
-31
lines changed

src/EFCore.Ydb/test/EntityFrameworkCore.Ydb.FunctionalTests/Query/DecimalParameterYdbTest.cs

Lines changed: 58 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -15,43 +15,64 @@ public class DecimalParameterYdbTest(DecimalParameterQueryYdbFixture fixture)
1515
public async Task Parameter_decimal_uses_default_22_9_and_roundtrips()
1616
{
1717
await using var ctx = Fixture.CreateContext();
18-
await ctx.Database.EnsureCreatedAsync();
18+
try
19+
{
20+
await ctx.Database.EnsureCreatedAsync();
1921

20-
var v = 1.23456789m;
21-
ctx.Add(new ItemDefault { Price = v });
22-
await ctx.SaveChangesAsync();
22+
var v = 1.23456789m;
23+
ctx.Add(new ItemDefault { Price = v });
24+
await ctx.SaveChangesAsync();
2325

24-
var got = await ctx.Set<ItemDefault>().Where(x => x.Price == v).ToListAsync();
25-
Assert.Single(got);
26-
Assert.Equal(v, got[0].Price);
26+
var got = await ctx.Set<ItemDefault>().Where(x => x.Price == v).ToListAsync();
27+
Assert.Single(got);
28+
Assert.Equal(v, got[0].Price);
29+
}
30+
finally
31+
{
32+
await ctx.Database.CloseConnectionAsync();
33+
}
2734
}
2835

2936
[ConditionalFact]
3037
public async Task Parameter_decimal_respects_explicit_22_9_and_roundtrips()
3138
{
3239
await using var ctx = Fixture.CreateContext();
33-
await ctx.Database.EnsureCreatedAsync();
40+
try
41+
{
42+
await ctx.Database.EnsureCreatedAsync();
3443

35-
var v = 123.456789012m;
36-
ctx.Add(new ItemExplicit { Price = v });
37-
await ctx.SaveChangesAsync();
44+
var v = 123.456789012m;
45+
ctx.Add(new ItemExplicit { Price = v });
46+
await ctx.SaveChangesAsync();
3847

39-
var got = await ctx.Set<ItemExplicit>().Where(x => x.Price == v).ToListAsync();
40-
Assert.Single(got);
41-
Assert.Equal(v, got[0].Price);
48+
var got = await ctx.Set<ItemExplicit>().Where(x => x.Price == v).ToListAsync();
49+
Assert.Single(got);
50+
Assert.Equal(v, got[0].Price);
51+
}
52+
finally
53+
{
54+
await ctx.Database.CloseConnectionAsync();
55+
}
4256
}
4357

4458
[ConditionalFact]
4559
public async Task Decimal_out_of_range_bubbles_up()
4660
{
4761
await using var ctx = Fixture.CreateContext();
48-
await ctx.Database.EnsureCreatedAsync();
62+
try
63+
{
64+
await ctx.Database.EnsureCreatedAsync();
4965

50-
var tooBig = new ItemExplicit { Price = 10_000_000_000_000m };
51-
ctx.Add(tooBig);
66+
var tooBig = new ItemExplicit { Price = 10_000_000_000_000m };
67+
ctx.Add(tooBig);
5268

53-
var ex = await Assert.ThrowsAsync<DbUpdateException>(() => ctx.SaveChangesAsync());
54-
Assert.Contains("Decimal", ex.InnerException?.Message ?? "");
69+
var ex = await Assert.ThrowsAsync<DbUpdateException>(() => ctx.SaveChangesAsync());
70+
Assert.Contains("Decimal", ex.InnerException?.Message ?? "");
71+
}
72+
finally
73+
{
74+
await ctx.Database.CloseConnectionAsync();
75+
}
5576
}
5677

5778
[Fact]
@@ -94,21 +115,27 @@ public async Task Parameter_decimal_respects_custom_30_10_and_roundtrips_if_supp
94115

95116
try
96117
{
97-
await ctx.Database.EnsureCreatedAsync();
118+
try
119+
{
120+
await ctx.Database.EnsureCreatedAsync();
121+
}
122+
catch (Exception ex) when (ex.ToString().Contains("EnableParameterizedDecimal", StringComparison.OrdinalIgnoreCase))
123+
{
124+
return;
125+
}
126+
127+
var v = 123.4567890123m;
128+
ctx.Add(new MappingEntity { Price = v });
129+
await ctx.SaveChangesAsync();
130+
131+
var got = await ctx.Set<MappingEntity>().Where(x => x.Price == v).ToListAsync();
132+
Assert.Single(got);
133+
Assert.Equal(v, got[0].Price);
98134
}
99-
catch (Exception ex) when (ex.ToString()
100-
.Contains("EnableParameterizedDecimal", StringComparison.OrdinalIgnoreCase))
135+
finally
101136
{
102-
return;
137+
await ctx.Database.CloseConnectionAsync();
103138
}
104-
105-
var v = 123.4567890123m;
106-
ctx.Add(new MappingEntity { Price = v });
107-
await ctx.SaveChangesAsync();
108-
109-
var got = await ctx.Set<MappingEntity>().Where(x => x.Price == v).ToListAsync();
110-
Assert.Single(got);
111-
Assert.Equal(v, got[0].Price);
112139
}
113140

114141
private sealed class MappingOnlyContext(DbContextOptions<MappingOnlyContext> options) : DbContext(options)

0 commit comments

Comments
 (0)