Skip to content

Commit 419753e

Browse files
committed
Add Ecng_ prefix to all test DB table names and wire Entity attribute in SchemaRegistry
- SchemaRegistry.CreateFromReflection now reads [Entity] attribute for TableName and NoCache - All integration test tables renamed with Ecng_ prefix for consistent naming
1 parent f5f0e5e commit 419753e

9 files changed

+35
-26
lines changed

Data.ORM/SchemaRegistry.cs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ public static Schema Get(Type entityType)
3535

3636
private static Schema CreateFromReflection(Type entityType)
3737
{
38+
var entityAttr = entityType.GetCustomAttribute<EntityAttribute>();
3839
var columns = new List<SchemaColumn>();
3940
SchemaColumn identity = null;
4041
var loadProps = new List<(PropertyInfo prop, bool isClass)>();
@@ -80,7 +81,8 @@ private static Schema CreateFromReflection(Type entityType)
8081

8182
return new()
8283
{
83-
TableName = entityType.Name,
84+
TableName = entityAttr?.Name.IsEmpty() == false ? entityAttr.Name : entityType.Name,
85+
NoCache = entityAttr?.NoCache ?? false,
8486
EntityType = entityType,
8587
Identity = identity,
8688
Columns = columns,

Tests/Data/AdoIntegrationTests.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ public abstract class AdoIntegrationTestsBase : BaseTestClass
1919
protected abstract DbProviderFactory Factory { get; }
2020
protected abstract string GetConnectionString();
2121

22-
private const string TableName = "AdoTestItems";
22+
private const string TableName = "Ecng_AdoTestItems";
2323

2424
private static readonly Dictionary<string, Type> _columns = new()
2525
{

Tests/Data/ComparisonOperatorIntegrationTests.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ namespace Ecng.Tests.Data;
1616
public class ComparisonOperatorIntegrationTests : BaseTestClass
1717
{
1818
private const string ProviderName = DatabaseProviderRegistry.SQLite;
19-
private const string TableName = "comp_op_test";
19+
private const string TableName = "Ecng_CompOpTest";
2020

2121
private static SqliteConnection _keepAlive;
2222
private static IDatabaseConnection _connection;
@@ -28,13 +28,13 @@ public static void ClassInit(TestContext context)
2828
SQLiteDialect.Register(SqliteFactory.Instance);
2929

3030
// Keep-alive connection to prevent in-memory DB from being destroyed
31-
_keepAlive = new SqliteConnection("Data Source=comp_op_test;Mode=Memory;Cache=Shared");
31+
_keepAlive = new SqliteConnection("Data Source=Ecng_CompOpTest;Mode=Memory;Cache=Shared");
3232
_keepAlive.Open();
3333

3434
var pair = new DatabaseConnectionPair
3535
{
3636
Provider = ProviderName,
37-
ConnectionString = "Data Source=comp_op_test;Mode=Memory;Cache=Shared",
37+
ConnectionString = "Data Source=Ecng_CompOpTest;Mode=Memory;Cache=Shared",
3838
};
3939

4040
_connection = AdoDatabaseProvider.Instance.CreateConnection(pair);

Tests/Data/DatabaseTableIntegrationTests.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ namespace Ecng.Tests.Data;
1717
[DoNotParallelize]
1818
public class DatabaseTableIntegrationTests : BaseTestClass
1919
{
20-
private const string _testTableName = "ecng_table_test";
20+
private const string _testTableName = "Ecng_TableTest";
2121
private static string _sqliteDbPath;
2222

2323
[ClassInitialize]
@@ -576,7 +576,7 @@ public async Task Table_Upsert_InsertAndUpdate_Success(string providerName)
576576
{
577577
SkipIfSqlServerOnNet6(providerName);
578578

579-
var upsertTableName = "upsert_test";
579+
var upsertTableName = "Ecng_UpsertTest";
580580
var provider = AdoDatabaseProvider.Instance;
581581
using var connection = provider.CreateConnection(GetConnectionPair(providerName));
582582
var table = provider.GetTable(connection, upsertTableName);

Tests/Data/EntityGeneratorTests.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ public void EntityAttribute_Name()
1212
{
1313
var schema = SchemaRegistry.Get(typeof(GenTestOrderEntity));
1414

15-
schema.TableName.AssertEqual("Orders");
15+
schema.TableName.AssertEqual("Ecng_Orders");
1616
}
1717

1818
[TestMethod]

Tests/Data/GeneratorTestEntities.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,14 +19,14 @@ public virtual void Save(SettingsStorage storage) { }
1919
public virtual void InitLists(IStorage db) { }
2020
}
2121

22-
[Entity(Name = "Orders", NoCache = true)]
22+
[Entity(Name = "Ecng_Orders", NoCache = true)]
2323
public partial class GenTestOrderEntity : GenTestBaseEntity
2424
{
2525
public string Symbol { get; set; }
2626
public decimal Price { get; set; }
2727
}
2828

29-
[Entity(Name = "Products")]
29+
[Entity(Name = "Ecng_Products")]
3030
public partial class GenTestProductEntity : GenTestBaseEntity
3131
{
3232
public string Title { get; set; }

Tests/Data/InnerSchemaTests.cs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -190,7 +190,7 @@ public static void ClassInit(TestContext context)
190190

191191
SchemaRegistry.Register(new Schema
192192
{
193-
TableName = "TestOrderWithAddress",
193+
TableName = "Ecng_OrderWithAddress",
194194
EntityType = typeof(TestOrderWithAddress),
195195
Identity = new SchemaColumn { Name = "Id", ClrType = typeof(long) },
196196
Columns =
@@ -206,7 +206,7 @@ public static void ClassInit(TestContext context)
206206
conn.Open();
207207
using var cmd = conn.CreateCommand();
208208
cmd.CommandText = """
209-
CREATE TABLE "TestOrderWithAddress" (
209+
CREATE TABLE "Ecng_OrderWithAddress" (
210210
"Id" INTEGER PRIMARY KEY,
211211
"OrderName" TEXT,
212212
"ShippingAddressStreet" TEXT,
@@ -361,7 +361,7 @@ public static void ClassInit(TestContext context)
361361
// Register TestCountry — standalone entity
362362
SchemaRegistry.Register(new Schema
363363
{
364-
TableName = "TestCountry",
364+
TableName = "Ecng_Country",
365365
EntityType = typeof(TestCountry),
366366
Identity = new SchemaColumn { Name = "Id", ClrType = typeof(long) },
367367
Columns =
@@ -374,7 +374,7 @@ public static void ClassInit(TestContext context)
374374
// Register TestOrderWithAddressEx — entity with multi-level inner schema + RelationSingle
375375
SchemaRegistry.Register(new Schema
376376
{
377-
TableName = "TestOrderWithAddressEx",
377+
TableName = "Ecng_OrderWithAddressEx",
378378
EntityType = typeof(TestOrderWithAddressEx),
379379
Identity = new SchemaColumn { Name = "Id", ClrType = typeof(long) },
380380
Columns =
@@ -393,11 +393,11 @@ public static void ClassInit(TestContext context)
393393
conn.Open();
394394
using var cmd = conn.CreateCommand();
395395
cmd.CommandText = """
396-
CREATE TABLE "TestCountry" (
396+
CREATE TABLE "Ecng_Country" (
397397
"Id" INTEGER PRIMARY KEY,
398398
"Name" TEXT
399399
);
400-
CREATE TABLE "TestOrderWithAddressEx" (
400+
CREATE TABLE "Ecng_OrderWithAddressEx" (
401401
"Id" INTEGER PRIMARY KEY,
402402
"OrderName" TEXT,
403403
"ShippingAddressStreet" TEXT,

Tests/Data/OrmIntegrationTests.cs

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -78,13 +78,13 @@ public void TestInit()
7878
using var conn = new SqlConnection(_connectionString);
7979
conn.Open();
8080

81-
Execute(conn, "DELETE FROM [TestItemCategory]");
82-
Execute(conn, "DELETE FROM [TestItem]");
83-
Execute(conn, "DELETE FROM [TestCategory]");
84-
Execute(conn, "DELETE FROM [TestTask]");
85-
Execute(conn, "DELETE FROM [TestPerson]");
86-
Execute(conn, "DELETE FROM [TestNodeChild]");
87-
Execute(conn, "DELETE FROM [TestNode]");
81+
Execute(conn, "DELETE FROM [Ecng_TestItemCategory]");
82+
Execute(conn, "DELETE FROM [Ecng_TestItem]");
83+
Execute(conn, "DELETE FROM [Ecng_TestCategory]");
84+
Execute(conn, "DELETE FROM [Ecng_TestTask]");
85+
Execute(conn, "DELETE FROM [Ecng_TestPerson]");
86+
Execute(conn, "DELETE FROM [Ecng_TestNodeChild]");
87+
Execute(conn, "DELETE FROM [Ecng_TestNode]");
8888

8989
Storage.ClearCacheAsync(CancellationToken).AsTask().Wait();
9090
}
@@ -1800,9 +1800,9 @@ public async Task RelationSingle_FkWithZeroId()
18001800
using (var conn = new SqlConnection(_connectionString))
18011801
{
18021802
conn.Open();
1803-
Execute(conn, "SET IDENTITY_INSERT [TestPerson] ON");
1804-
Execute(conn, "INSERT INTO [TestPerson] (Id, Name) VALUES (0, 'ZeroRoot')");
1805-
Execute(conn, "SET IDENTITY_INSERT [TestPerson] OFF");
1803+
Execute(conn, "SET IDENTITY_INSERT [Ecng_TestPerson] ON");
1804+
Execute(conn, "INSERT INTO [Ecng_TestPerson] (Id, Name) VALUES (0, 'ZeroRoot')");
1805+
Execute(conn, "SET IDENTITY_INSERT [Ecng_TestPerson] OFF");
18061806
}
18071807

18081808
// Insert a task referencing Person Id=0

Tests/Data/OrmTestEntities.cs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ namespace Ecng.Tests.Data;
55
using Ecng.Data.Sql;
66
using Ecng.Serialization;
77

8+
[Entity(Name = "Ecng_TestItem")]
89
public class TestItem : IDbPersistable
910
{
1011
public long Id { get; set; }
@@ -41,6 +42,7 @@ public ValueTask LoadAsync(SettingsStorage storage, IStorage db, CancellationTok
4142
}
4243
}
4344

45+
[Entity(Name = "Ecng_TestCategory")]
4446
public class TestCategory : IDbPersistable
4547
{
4648
public long Id { get; set; }
@@ -65,6 +67,7 @@ public ValueTask LoadAsync(SettingsStorage storage, IStorage db, CancellationTok
6567
}
6668
}
6769

70+
[Entity(Name = "Ecng_TestItemCategory")]
6871
public class TestItemCategory : IDbPersistable
6972
{
7073
public long Id { get; set; }
@@ -92,6 +95,7 @@ public async ValueTask LoadAsync(SettingsStorage storage, IStorage db, Cancellat
9295
}
9396
}
9497

98+
[Entity(Name = "Ecng_TestPerson")]
9599
public class TestPerson : IDbPersistable
96100
{
97101
public long Id { get; set; }
@@ -123,6 +127,7 @@ public void InitLists(IStorage db)
123127
}
124128
}
125129

130+
[Entity(Name = "Ecng_TestTask")]
126131
public class TestTask : IDbPersistable
127132
{
128133
public long Id { get; set; }
@@ -239,6 +244,7 @@ public void Save(SettingsStorage storage) { }
239244
/// Self-referencing tree node for testing multi-level RelationMany nesting.
240245
/// Mirrors the Client → ClientGroup → Client pattern in the web app.
241246
/// </summary>
247+
[Entity(Name = "Ecng_TestNode")]
242248
public class TestNode : IDbPersistable
243249
{
244250
public long Id { get; set; }
@@ -271,6 +277,7 @@ public void InitLists(IStorage db)
271277
/// Junction entity linking a parent TestNode to a child TestNode.
272278
/// Mirrors ClientGroup (Client FK + Group FK).
273279
/// </summary>
280+
[Entity(Name = "Ecng_TestNodeChild")]
274281
public class TestNodeChild : IDbPersistable
275282
{
276283
public long Id { get; set; }

0 commit comments

Comments
 (0)