Skip to content

Commit

Permalink
UnitTest Fixed. (#202)
Browse files Browse the repository at this point in the history
* 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.

* 变更数据源。
  • Loading branch information
gmij committed Apr 20, 2022
1 parent a4a7ebe commit 8ddfda3
Show file tree
Hide file tree
Showing 5 changed files with 70 additions and 24 deletions.
8 changes: 8 additions & 0 deletions src/SmartSql.Test.Unit/CUD/CUDTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,14 @@ public void Get()
Assert.NotNull(entity);
}

[Fact]
public void GetWithPropertyTrack()
{
AllPrimitive insertEntity = InsertReturnIdImpl(out long id);
var entity = SqlMapper.GetById<AllPrimitive, long>(id, true);
Assert.NotNull(entity);
}

[Fact]
public void Insert()
{
Expand Down
4 changes: 2 additions & 2 deletions src/SmartSql.Test.Unit/Deserializer/EntityDeserializerTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ public void QuerySingle()
var entity = SqlMapper.QuerySingle<AllPrimitive>(new RequestContext
{
Scope = nameof(AllPrimitive),
SqlId = "GetEntity",
SqlId = "GetById",
Request = new { Id = id }
});
Assert.Equal(id, entity.Id);
Expand Down Expand Up @@ -58,7 +58,7 @@ public async Task QuerySingleAsync()
var entity = await SqlMapper.QuerySingleAsync<AllPrimitive>(new RequestContext
{
Scope = nameof(AllPrimitive),
SqlId = "GetEntity",
SqlId = "GetById",
Request = new { Id = id }
});
Assert.Equal(id, entity.Id);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
76 changes: 57 additions & 19 deletions src/SmartSql.Test.Unit/init-db.sql
Original file line number Diff line number Diff line change
@@ -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,
Expand All @@ -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
# ;
4 changes: 2 additions & 2 deletions src/SmartSql/CUD/CUDSqlGenerator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

Expand Down Expand Up @@ -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;
Expand Down

0 comments on commit 8ddfda3

Please sign in to comment.