From 8ddfda3201aa1bc71833ffaad539fed89fd28580 Mon Sep 17 00:00:00 2001 From: gmij Date: Wed, 20 Apr 2022 08:47:07 +0800 Subject: [PATCH] UnitTest Fixed. (#202) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * fixed. 修复CUD模块中自动生成的SQL语句,在Oracle下提示ORA-00933命令未正确结束的错误。原因是SQL语句结束处,加了分号。 * fixed. 当使用CUD模块,没有xml配置项时,会导致缓存无法开启。移除对SqlMaps的缓存配置项检查。 * 移除注释的代码。 * 动态插入时,自动生成Statement配置信息。 * fixed. CUD,在执行时,把Statement加入到内存中,已能和缓存产生完整交互。 added. 添加的CUD默认Statement.SqlId,用于FlushOnExecutes * 1. 优化CUDStatement的默认名称的引用 2. 添加CUDCacheAttribute,把默认的CUD操作设置为刷新缓存。 * 优化Statement的使用。 * add. CUD statement build * commit unit test * 优化sql生成过程 * 完善insert和update的语法构成方式。 * fix. insert and update CUD invalid. * 移除过期的代码。 * add. DyRepository缓存加载 * fixed. CUD模块和动态仓储模块同时启用时,动态仓储上设置同名Statement时,缓存不生效。 * fix. 调通部分单元测试。修改数据库初始化脚本及部分测试模型 * 优化sql in语法的匹配表达式 * fixed. 完善DeleteMany的代码。并通过单元测试 * 完善单元测试用例 * 完善单元测试 * 完善单元测试 * 完善测试需求 * 完善单元测试 * fixed. InsertReturnId and DeleteMany statement Build method errors. * fixed. test unit bugs. * 变更数据源。 --- src/SmartSql.Test.Unit/CUD/CUDTest.cs | 8 ++ .../Deserializer/EntityDeserializerTest.cs | 4 +- .../Reflection/EntityMetaDataCacheTypeTest.cs | 2 +- src/SmartSql.Test.Unit/init-db.sql | 76 ++++++++++++++----- src/SmartSql/CUD/CUDSqlGenerator.cs | 4 +- 5 files changed, 70 insertions(+), 24 deletions(-) diff --git a/src/SmartSql.Test.Unit/CUD/CUDTest.cs b/src/SmartSql.Test.Unit/CUD/CUDTest.cs index e669c11f..5e3f7185 100644 --- a/src/SmartSql.Test.Unit/CUD/CUDTest.cs +++ b/src/SmartSql.Test.Unit/CUD/CUDTest.cs @@ -24,6 +24,14 @@ public void Get() Assert.NotNull(entity); } + [Fact] + public void GetWithPropertyTrack() + { + AllPrimitive insertEntity = InsertReturnIdImpl(out long id); + var entity = SqlMapper.GetById(id, true); + Assert.NotNull(entity); + } + [Fact] public void Insert() { diff --git a/src/SmartSql.Test.Unit/Deserializer/EntityDeserializerTest.cs b/src/SmartSql.Test.Unit/Deserializer/EntityDeserializerTest.cs index baea69ca..cc223763 100644 --- a/src/SmartSql.Test.Unit/Deserializer/EntityDeserializerTest.cs +++ b/src/SmartSql.Test.Unit/Deserializer/EntityDeserializerTest.cs @@ -24,7 +24,7 @@ public void QuerySingle() var entity = SqlMapper.QuerySingle(new RequestContext { Scope = nameof(AllPrimitive), - SqlId = "GetEntity", + SqlId = "GetById", Request = new { Id = id } }); Assert.Equal(id, entity.Id); @@ -58,7 +58,7 @@ public async Task QuerySingleAsync() var entity = await SqlMapper.QuerySingleAsync(new RequestContext { Scope = nameof(AllPrimitive), - SqlId = "GetEntity", + SqlId = "GetById", Request = new { Id = id } }); Assert.Equal(id, entity.Id); diff --git a/src/SmartSql.Test.Unit/Reflection/EntityMetaDataCacheTypeTest.cs b/src/SmartSql.Test.Unit/Reflection/EntityMetaDataCacheTypeTest.cs index 24b5d9ea..705823c0 100644 --- a/src/SmartSql.Test.Unit/Reflection/EntityMetaDataCacheTypeTest.cs +++ b/src/SmartSql.Test.Unit/Reflection/EntityMetaDataCacheTypeTest.cs @@ -10,6 +10,6 @@ public class EntityMetaDataCacheTypeTest public void GetTableName() { var tableName = EntityMetaDataCacheType.GetTableName(typeof(AllPrimitive)); - Assert.Equal("AllPrimitive", tableName); + Assert.Equal("T_AllPrimitive", tableName); } } \ No newline at end of file diff --git a/src/SmartSql.Test.Unit/init-db.sql b/src/SmartSql.Test.Unit/init-db.sql index bfbc89c2..1d74c419 100644 --- a/src/SmartSql.Test.Unit/init-db.sql +++ b/src/SmartSql.Test.Unit/init-db.sql @@ -1,11 +1,13 @@ -create database if not exists SmartSqlStarterDB; -use SmartSqlStarterDB; +create database SmartSqlTestDB; -create table if not exists T_AllPrimitive +use SmartSqlTestDB; + +create table T_AllPrimitive ( - Id bigint not null AUTO_INCREMENT primary key, - Boolean boolean not null, - `Char` char(1) not null, + Id bigint auto_increment + primary key, + Boolean tinyint(1) not null, + `Char` char not null, Int16 mediumint not null, Int32 int not null, Int64 bigint not null, @@ -16,17 +18,53 @@ create table if not exists T_AllPrimitive Guid char(36) not null, TimeSpan time not null, NumericalEnum tinyint(1) not null, - NullableBoolean boolean, - NullableChar char(1), - NullableInt16 mediumint, - NullableInt32 int, - NullableInt64 bigint, - NullableSingle float, - NullableDecimal decimal, - NullableDateTime datetime, - NullableGuid char(32), - NullableTimeSpan time, - NullableNumericalEnum tinyint(1), - NullableString varchar(100) -) engine = InnoDB; + NullableBoolean tinyint(1) null, + NullableChar char null, + NullableInt16 mediumint null, + NullableInt32 int null, + NullableInt64 bigint null, + NullableSingle float null, + NullableDecimal decimal null, + NullableDateTime datetime null, + NullableGuid char(36) null, + NullableTimeSpan time null, + NullableNumericalEnum tinyint(1) null, + NullableString varchar(100) null +) engine = InnoDb +; + +create table t_column_annotation_entity +( + id bigint auto_increment + primary key, + name varchar(100) not null, + extend_data longtext collate utf8mb4_bin not null, + constraint extend_data + check (json_valid(`extend_data`)) +) engine = InnoDb +; + +create table T_User +( + Id bigint auto_increment + primary key, + UserName varchar(50) not null, + Status tinyint(2) not null +); + +create table T_UserExtendedInfo +( + UserId bigint auto_increment + primary key, + Data json not null +); + + +# Create PROCEDURE SP_Query(out Total int) +# +# BEGIN +# Select Count(*) into Total From T_AllPrimitive T; +# SELECT T.* From T_AllPrimitive T limit 10; +# END +# ; diff --git a/src/SmartSql/CUD/CUDSqlGenerator.cs b/src/SmartSql/CUD/CUDSqlGenerator.cs index bd052030..af542417 100644 --- a/src/SmartSql/CUD/CUDSqlGenerator.cs +++ b/src/SmartSql/CUD/CUDSqlGenerator.cs @@ -83,7 +83,7 @@ public Statement BuildDeleteById(GeneratorParams gParams) public Statement BuildDeleteMany(GeneratorParams gParams) { - var sql = $"Delete From {gParams.TableName} Where {gParams.PkCol.Name} In {FormatParameterName(_provider, gParams.PkCol.Name)}"; + var sql = $"Delete From {gParams.TableName} Where {gParams.PkCol.Name} In {FormatParameterName(_provider, gParams.PkCol.Name + "s")}"; return BuildStatement(CUDStatementName.DeleteMany, sql, gParams.Map); } @@ -113,7 +113,7 @@ public Statement BuildInsertReturnId(GeneratorParams arg) } else { - statement.SqlTags.Add(new SqlText($"; {_provider.SelectAutoIncrement};", _provider.ParameterPrefix)); + statement.SqlTags.Add(new SqlText($"{_provider.SelectAutoIncrement}", _provider.ParameterPrefix)); } return statement;