Skip to content

Commit e1a5a30

Browse files
committed
test: fix decimal parameter mapping
1 parent 5ccf50c commit e1a5a30

File tree

2 files changed

+26
-37
lines changed

2 files changed

+26
-37
lines changed
Lines changed: 25 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -1,60 +1,49 @@
11
using EntityFrameworkCore.Ydb.FunctionalTests.TestUtilities;
2-
using EntityFrameworkCore.Ydb.Extensions;
32
using Microsoft.EntityFrameworkCore;
4-
using Microsoft.EntityFrameworkCore.Diagnostics;
53
using Microsoft.EntityFrameworkCore.TestUtilities;
64

75
namespace EntityFrameworkCore.Ydb.FunctionalTests.Query;
86

9-
public class DecimalParameterQueryYdbFixture
10-
: SharedStoreFixtureBase<DecimalParameterQueryYdbFixture.DecimalContext>
7+
public class DecimalParameterQueryYdbFixture : SharedStoreFixtureBase<DecimalParameterQueryYdbFixture.TestContext>
118
{
12-
private static DbCommandInterceptor? CurrentInterceptor => null;
9+
protected override string StoreName => "DecimalParameterTest";
1310

14-
protected override string StoreName => "DecimalParameter";
1511
protected override ITestStoreFactory TestStoreFactory => YdbTestStoreFactory.Instance;
1612

17-
public override DbContextOptionsBuilder AddOptions(DbContextOptionsBuilder builder)
13+
public class TestContext : DbContext
1814
{
19-
var b = base.AddOptions(builder);
20-
b.UseYdb(GetConnString());
21-
if (CurrentInterceptor is not null)
22-
b.AddInterceptors(CurrentInterceptor);
23-
return b;
24-
}
25-
26-
protected override void OnModelCreating(ModelBuilder b, DbContext ctx)
27-
{
28-
b.Entity<ItemDefault>(e => e.HasKey(x => x.Id));
29-
30-
b.Entity<ItemExplicit>(e =>
15+
public TestContext(DbContextOptions options) : base(options)
3116
{
32-
e.HasKey(x => x.Id);
33-
e.Property(x => x.Price).HasPrecision(22, 9);
34-
});
35-
}
17+
}
3618

37-
private static string GetConnString()
38-
{
39-
var cs = Environment.GetEnvironmentVariable("YDB_EF_CONN");
40-
if (!string.IsNullOrWhiteSpace(cs)) return cs;
19+
public DbSet<ItemDefault> ItemsDefault => Set<ItemDefault>();
20+
public DbSet<ItemExplicit> ItemsExplicit => Set<ItemExplicit>();
4121

42-
var endpoint = Environment.GetEnvironmentVariable("YDB_ENDPOINT") ?? "grpc://localhost:2136";
43-
var database = Environment.GetEnvironmentVariable("YDB_DATABASE") ?? "/ef-tests";
44-
return $"{endpoint};database={database}";
22+
protected override void OnModelCreating(ModelBuilder modelBuilder)
23+
{
24+
modelBuilder.Entity<ItemDefault>(b =>
25+
{
26+
b.HasKey(x => x.Id);
27+
b.Property(x => x.Price);
28+
});
29+
30+
modelBuilder.Entity<ItemExplicit>(b =>
31+
{
32+
b.HasKey(x => x.Id);
33+
b.Property(x => x.Price).HasPrecision(22, 9);
34+
});
35+
}
4536
}
46-
47-
public class DecimalContext(DbContextOptions options) : DbContext(options);
4837
}
4938

5039
public class ItemDefault
5140
{
52-
public int Id { get; init; }
53-
public decimal Price { get; init; }
41+
public int Id { get; set; }
42+
public decimal Price { get; set; }
5443
}
5544

5645
public class ItemExplicit
5746
{
58-
public int Id { get; init; }
59-
public decimal Price { get; init; }
47+
public int Id { get; set; }
48+
public decimal Price { get; set; }
6049
}

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ public void Type_mapping_default_decimal_is_22_9()
8888
public void Type_mapping_custom_decimal_is_30_10()
8989
{
9090
var opts = new DbContextOptionsBuilder<MappingOnlyContext>()
91-
.UseYdb("")
91+
.UseYdb("Host=localhost;Database=/local")
9292
.Options;
9393

9494
using var ctx = new MappingOnlyContext(opts);

0 commit comments

Comments
 (0)