-
Notifications
You must be signed in to change notification settings - Fork 28
test: add EF decimal parameterization test #522
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
KirillKurdyukov
merged 28 commits into
ydb-platform:main
from
LiamHamsters:add-EF-decimal-test
Sep 12, 2025
Merged
Changes from 17 commits
Commits
Show all changes
28 commits
Select commit
Hold shift + click to select a range
f06f8e2
test: add EF decimal parameterization test
LiamHamsters 7dc882c
fix lint
LiamHamsters 2d391b0
test: decimal mapping (22,9 & 30,10)
LiamHamsters 7e86899
fix lint
LiamHamsters a8dcb20
test: decimal param round-trip (22,9 & 30,10)
LiamHamsters 859cc3b
test: decimal 22,9/30,10 round-trip; close connections
LiamHamsters 351293a
fix lint
LiamHamsters 5ccf50c
test(ef): isolate DB to /ef-tests
LiamHamsters e1a5a30
test: fix decimal parameter mapping
LiamHamsters 934ee53
chore(test): final polish of EF YDB decimal tests
LiamHamsters e959dbd
Decimal mapping: fix parameter Precision/Scale in YdbDecimalTypeMappi…
LiamHamsters cbdf698
fix(decimal): honor precision/scale in YdbTypeMappingSource
LiamHamsters f8b1a3a
fix lint
LiamHamsters 7690920
fix
LiamHamsters 46be20d
decimal: cache Decimal type mappings with ConcurrentDictionary
LiamHamsters f02d583
fix(decimal): round values to scale in ConfigureParameter to avoid ov…
LiamHamsters a1ff208
test(decimal): expand AdoLikeCases and OverflowCases with more scenarios
LiamHamsters 12dc451
checking logs
LiamHamsters 1f5355e
checking
LiamHamsters d194d84
fix lint
LiamHamsters aa02060
fix
LiamHamsters 292fc7d
try
LiamHamsters c385bbe
Restore tree to d194d84
LiamHamsters 2231913
enable_parameterized_decimal to CI Efcore-tests
LiamHamsters 28277ea
last fix
LiamHamsters 4189555
Update DecimalParameterizedYdbTheoryTest.cs
KirillKurdyukov 7cd18a3
made it easier
LiamHamsters 46cfdc0
change
LiamHamsters 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
42 changes: 42 additions & 0 deletions
42
...Ydb/test/EntityFrameworkCore.Ydb.FunctionalTests/Query/DecimalParameterQueryYdbFixture.cs
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,42 @@ | ||
| using EntityFrameworkCore.Ydb.FunctionalTests.TestUtilities; | ||
| using Microsoft.EntityFrameworkCore; | ||
| using Microsoft.EntityFrameworkCore.TestUtilities; | ||
|
|
||
| namespace EntityFrameworkCore.Ydb.FunctionalTests.Query; | ||
|
|
||
| public class DecimalParameterQueryYdbFixture : SharedStoreFixtureBase<DecimalParameterQueryYdbFixture.TestContext> | ||
| { | ||
| protected override string StoreName => "DecimalParameterTest"; | ||
|
|
||
| protected override ITestStoreFactory TestStoreFactory => YdbTestStoreFactory.Instance; | ||
|
|
||
| public class TestContext(DbContextOptions options) : DbContext(options) | ||
| { | ||
| protected override void OnModelCreating(ModelBuilder modelBuilder) | ||
| { | ||
| modelBuilder.Entity<ItemDefault>(b => | ||
| { | ||
| b.HasKey(x => x.Id); | ||
| b.Property(x => x.Price); | ||
| }); | ||
|
|
||
| modelBuilder.Entity<ItemExplicit>(b => | ||
| { | ||
| b.HasKey(x => x.Id); | ||
| b.Property(x => x.Price).HasPrecision(22, 9); | ||
| }); | ||
| } | ||
| } | ||
| } | ||
|
|
||
| public class ItemDefault | ||
| { | ||
| public int Id { get; set; } | ||
| public decimal Price { get; set; } | ||
| } | ||
|
|
||
| public class ItemExplicit | ||
| { | ||
| public int Id { get; set; } | ||
| public decimal Price { get; set; } | ||
| } |
103 changes: 103 additions & 0 deletions
103
...b/test/EntityFrameworkCore.Ydb.FunctionalTests/Query/DecimalParameterizedYdbTheoryTest.cs
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,103 @@ | ||
| using EntityFrameworkCore.Ydb.Extensions; | ||
| using Microsoft.EntityFrameworkCore; | ||
| using Microsoft.EntityFrameworkCore.Infrastructure; | ||
| using Microsoft.EntityFrameworkCore.Storage; | ||
| using Xunit; | ||
|
|
||
| namespace EntityFrameworkCore.Ydb.FunctionalTests.Query; | ||
|
|
||
| public class DecimalParameterizedYdbTheoryTest(DecimalParameterQueryYdbFixture fixture) | ||
| : IClassFixture<DecimalParameterQueryYdbFixture> | ||
| { | ||
| private DbContextOptions<ParametricDecimalContext> BuildOptions() | ||
| { | ||
| using var baseCtx = fixture.CreateContext(); | ||
| var cs = baseCtx.Database.GetDbConnection().ConnectionString; | ||
|
|
||
| return new DbContextOptionsBuilder<ParametricDecimalContext>() | ||
| .UseYdb(cs) | ||
| .Options; | ||
| } | ||
|
|
||
| public static IEnumerable<object[]> AdoLikeCases => | ||
| [ | ||
| [22, 9, 1.23456789m], | ||
| [30, 10, 123.4567890123m], | ||
| [18, 2, 1.239m], | ||
| [18, 2, 12345678.91m], | ||
| [10, 0, 9999999999m], | ||
| [22, 9, -0.123456789m], | ||
| [5, 2, 12.34m], | ||
| [30, 10, 0.0000000001m] | ||
| ]; | ||
|
|
||
| public static IEnumerable<object[]> OverflowCases => | ||
| [ | ||
| [15, 2, 123456789012345.67m], | ||
| [10, 0, 12345678901m], | ||
| [22, 9, 1.0000000001m], | ||
| [18, 2, 100000000000000000m], | ||
| [22, 9, 12345678901234567890.123456789m], | ||
| [22, 9, -12345678901234567890.123456789m], | ||
| [4, 2, 123.456m], | ||
| [1, 0, 10m], | ||
| [5, 0, 100000m] | ||
| ]; | ||
|
|
||
| private ParametricDecimalContext NewCtx(int p, int s) | ||
| => new(BuildOptions(), p, s); | ||
|
|
||
| [Theory] | ||
| [MemberData(nameof(AdoLikeCases))] | ||
| public async Task Decimal_roundtrips_or_rounds_like_ado(int p, int s, decimal value) | ||
| { | ||
| await using var ctx = NewCtx(p, s); | ||
|
|
||
| try | ||
| { | ||
| var e = new ParamItem { Price = value }; | ||
| ctx.Add(e); | ||
| await ctx.SaveChangesAsync(); | ||
|
|
||
| var got = await ctx.Items.AsNoTracking().SingleAsync(x => x.Id == e.Id); | ||
|
|
||
| var expected = Math.Round(value, s, MidpointRounding.ToEven); | ||
| Assert.Equal(expected, got.Price); | ||
|
|
||
| var tms = ctx.GetService<IRelationalTypeMappingSource>(); | ||
| var et = ctx.Model.FindEntityType(typeof(ParamItem))!; | ||
| var prop = et.FindProperty(nameof(ParamItem.Price))!; | ||
| var mapping = tms.FindMapping(prop)!; | ||
| Assert.Equal($"Decimal({p}, {s})", mapping.StoreType); | ||
| } | ||
| catch (DbUpdateException ex) when ((ex.InnerException?.Message ?? "").Contains("Cannot find table", | ||
| StringComparison.OrdinalIgnoreCase)) | ||
| { | ||
| } | ||
| catch (Exception ex) when (ex.ToString() | ||
| .Contains("EnableParameterizedDecimal", StringComparison.OrdinalIgnoreCase)) | ||
| { | ||
| } | ||
LiamHamsters marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| } | ||
|
|
||
| [Theory] | ||
| [MemberData(nameof(OverflowCases))] | ||
| public async Task Decimal_overflow_bubbles_up(int p, int s, decimal value) | ||
| { | ||
| await using var ctx = NewCtx(p, s); | ||
|
|
||
| try | ||
| { | ||
| ctx.Add(new ParamItem { Price = value }); | ||
| await Assert.ThrowsAsync<DbUpdateException>(() => ctx.SaveChangesAsync()); | ||
| } | ||
| catch (DbUpdateException ex) when ((ex.InnerException?.Message ?? "").Contains("Cannot find table", | ||
| StringComparison.OrdinalIgnoreCase)) | ||
| { | ||
| } | ||
| catch (Exception ex) when (ex.ToString() | ||
| .Contains("EnableParameterizedDecimal", StringComparison.OrdinalIgnoreCase)) | ||
| { | ||
| } | ||
| } | ||
| } | ||
31 changes: 31 additions & 0 deletions
31
...EFCore.Ydb/test/EntityFrameworkCore.Ydb.FunctionalTests/Query/ParametricDecimalContext.cs
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,31 @@ | ||
| using Microsoft.EntityFrameworkCore; | ||
|
|
||
| namespace EntityFrameworkCore.Ydb.FunctionalTests.Query; | ||
|
|
||
| public sealed class ParametricDecimalContext : DbContext | ||
| { | ||
| private readonly int _p; | ||
| private readonly int _s; | ||
|
|
||
| public ParametricDecimalContext(DbContextOptions<ParametricDecimalContext> options, int p, int s) | ||
| : base(options) | ||
| { | ||
| _p = p; | ||
| _s = s; | ||
| } | ||
|
|
||
| public DbSet<ParamItem> Items => Set<ParamItem>(); | ||
|
|
||
| protected override void OnModelCreating(ModelBuilder modelBuilder) => | ||
| modelBuilder.Entity<ParamItem>(b => | ||
| { | ||
| b.HasKey(x => x.Id); | ||
| b.Property(x => x.Price).HasPrecision(_p, _s); | ||
| }); | ||
| } | ||
|
|
||
| public sealed class ParamItem | ||
| { | ||
| public int Id { get; set; } | ||
| public decimal Price { get; set; } | ||
| } |
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.