|
| 1 | +using Microsoft.EntityFrameworkCore; |
| 2 | +using Xunit; |
| 3 | + |
| 4 | +namespace EntityFrameworkCore.Ydb.FunctionalTests.Query; |
| 5 | + |
| 6 | +public class DecimalParameterYdbTest(DecimalParameterQueryYdbFixture fixture) |
| 7 | + : IClassFixture<DecimalParameterQueryYdbFixture> |
| 8 | +{ |
| 9 | + private DecimalParameterQueryYdbFixture Fixture { get; } = fixture; |
| 10 | + |
| 11 | + [ConditionalFact] |
| 12 | + public async Task Parameter_decimal_uses_default_22_9_and_roundtrips() |
| 13 | + { |
| 14 | + await using var ctx = Fixture.CreateContext(); |
| 15 | + await ctx.Database.EnsureCreatedAsync(); |
| 16 | + |
| 17 | + decimal v = 1.23456789m; |
| 18 | + ctx.Add(new ItemDefault { Price = v }); |
| 19 | + await ctx.SaveChangesAsync(); |
| 20 | + |
| 21 | + var got = await ctx.Set<ItemDefault>().Where(x => x.Price == v).ToListAsync(); |
| 22 | + Assert.Single(got); |
| 23 | + Assert.Equal(v, got[0].Price); |
| 24 | + } |
| 25 | + |
| 26 | + [ConditionalFact] |
| 27 | + public async Task Parameter_decimal_respects_explicit_22_9_and_roundtrips() |
| 28 | + { |
| 29 | + await using var ctx = Fixture.CreateContext(); |
| 30 | + await ctx.Database.EnsureCreatedAsync(); |
| 31 | + |
| 32 | + decimal v = 123.456789012m; |
| 33 | + ctx.Add(new ItemExplicit { Price = v }); |
| 34 | + await ctx.SaveChangesAsync(); |
| 35 | + |
| 36 | + var got = await ctx.Set<ItemExplicit>().Where(x => x.Price == v).ToListAsync(); |
| 37 | + Assert.Single(got); |
| 38 | + Assert.Equal(v, got[0].Price); |
| 39 | + } |
| 40 | + |
| 41 | + [ConditionalFact] |
| 42 | + public async Task Decimal_out_of_range_bubbles_up() |
| 43 | + { |
| 44 | + await using var ctx = Fixture.CreateContext(); |
| 45 | + await ctx.Database.EnsureCreatedAsync(); |
| 46 | + |
| 47 | + var tooBig = new ItemExplicit { Price = 10_000_000_000_000m }; // 14 целых цифр -> вне 22,9 |
| 48 | + ctx.Add(tooBig); |
| 49 | + |
| 50 | + var ex = await Assert.ThrowsAsync<DbUpdateException>(() => ctx.SaveChangesAsync()); |
| 51 | + Assert.Contains("Decimal", ex.InnerException?.Message ?? ""); |
| 52 | + } |
| 53 | +} |
0 commit comments