Skip to content

Commit 2d391b0

Browse files
committed
test: decimal mapping (22,9 & 30,10)
1 parent 7dc882c commit 2d391b0

File tree

1 file changed

+46
-1
lines changed

1 file changed

+46
-1
lines changed

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

Lines changed: 46 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
1+
using EntityFrameworkCore.Ydb.Extensions;
12
using Microsoft.EntityFrameworkCore;
3+
using Microsoft.EntityFrameworkCore.Infrastructure;
4+
using Microsoft.EntityFrameworkCore.Storage;
25
using Xunit;
36

47
namespace EntityFrameworkCore.Ydb.FunctionalTests.Query;
@@ -44,10 +47,52 @@ public async Task Decimal_out_of_range_bubbles_up()
4447
await using var ctx = Fixture.CreateContext();
4548
await ctx.Database.EnsureCreatedAsync();
4649

47-
var tooBig = new ItemExplicit { Price = 10_000_000_000_000m }; // 14 целых цифр -> вне 22,9
50+
var tooBig = new ItemExplicit { Price = 10_000_000_000_000m };
4851
ctx.Add(tooBig);
4952

5053
var ex = await Assert.ThrowsAsync<DbUpdateException>(() => ctx.SaveChangesAsync());
5154
Assert.Contains("Decimal", ex.InnerException?.Message ?? "");
5255
}
56+
57+
[Fact]
58+
public void Type_mapping_default_decimal_is_22_9()
59+
{
60+
using var ctx = Fixture.CreateContext();
61+
var tms = ctx.GetService<IRelationalTypeMappingSource>();
62+
var mapping = tms.FindMapping(typeof(decimal))!;
63+
Assert.Equal("Decimal(22, 9)", mapping.StoreType);
64+
}
65+
66+
[Fact]
67+
public void Type_mapping_custom_decimal_is_30_10()
68+
{
69+
var opts = new DbContextOptionsBuilder<MappingOnlyContext>()
70+
.UseYdb("")
71+
.Options;
72+
73+
using var ctx = new MappingOnlyContext(opts);
74+
var tms = ctx.GetService<IRelationalTypeMappingSource>();
75+
76+
var et = ctx.Model.FindEntityType(typeof(MappingEntity))!;
77+
var prop = et.FindProperty(nameof(MappingEntity.Price))!;
78+
var mapping = tms.FindMapping(prop)!;
79+
80+
Assert.Equal("Decimal(30, 10)", mapping.StoreType);
81+
}
82+
83+
private sealed class MappingOnlyContext(DbContextOptions<MappingOnlyContext> options) : DbContext(options)
84+
{
85+
protected override void OnModelCreating(ModelBuilder b)
86+
=> b.Entity<MappingEntity>(e =>
87+
{
88+
e.HasKey(x => x.Id);
89+
e.Property(x => x.Price).HasPrecision(30, 10);
90+
});
91+
}
92+
93+
private sealed class MappingEntity
94+
{
95+
public int Id { get; set; }
96+
public decimal Price { get; set; }
97+
}
5398
}

0 commit comments

Comments
 (0)