mirror of
https://gitee.com/dotnetchina/SqlSugar.git
synced 2025-04-30 12:47:57 +08:00
Add unit test
This commit is contained in:
parent
aa86c8439c
commit
746a24b88e
@ -0,0 +1,33 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace SqlSugarTest
|
||||
{
|
||||
|
||||
public interface IDeleted
|
||||
{
|
||||
/// <summary>
|
||||
/// 默认假删除
|
||||
/// </summary>
|
||||
//[FakeDelete(true)] // 设置假删除的值
|
||||
bool IsDeleted { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 删除用户ID
|
||||
/// </summary>
|
||||
long? DeletedUserId { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 删除用户名称
|
||||
/// </summary>
|
||||
string DeletedUserName { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 删除时间
|
||||
/// </summary>
|
||||
DateTimeOffset? DeletedTime { get; set; }
|
||||
}
|
||||
}
|
@ -0,0 +1,51 @@
|
||||
using SqlSugar;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace SqlSugarTest
|
||||
{
|
||||
|
||||
[SugarTable("Special", TableDescription = "专题", IsDisabledDelete = true)]
|
||||
public class Special : IDeleted
|
||||
{
|
||||
/// <summary>
|
||||
/// 非自增ID
|
||||
/// </summary>
|
||||
[SugarColumn(ColumnDescription = "ID", IsPrimaryKey = true)]
|
||||
public long Id { get; set; }
|
||||
/// <summary>
|
||||
/// 名称
|
||||
/// </summary>
|
||||
[SugarColumn(ColumnDescription = "名称")]
|
||||
public string Name { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 默认假删除
|
||||
/// </summary>
|
||||
[System.Text.Json.Serialization.JsonIgnore]
|
||||
[Newtonsoft.Json.JsonIgnore]
|
||||
[SugarColumn(ColumnDescription = "默认假删除", DefaultValue = "false")]
|
||||
public bool IsDeleted { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 删除用户ID
|
||||
/// </summary>
|
||||
[SugarColumn(ColumnDescription = "删除用户ID", IsOnlyIgnoreInsert = true, IsNullable = true)]
|
||||
public long? DeletedUserId { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 删除用户
|
||||
/// </summary>
|
||||
[SugarColumn(ColumnDescription = "删除用户", IsNullable = true, IsOnlyIgnoreInsert = true)]
|
||||
public string? DeletedUserName { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 删除时间
|
||||
/// </summary>
|
||||
[SugarColumn(ColumnDescription = "删除时间", IsOnlyIgnoreInsert = true, IsNullable = true)]
|
||||
public DateTimeOffset? DeletedTime { get; set; }
|
||||
}
|
||||
}
|
37
Src/Asp.NetCore2/SqliteTest/UnitTest/UnitBizDelete.cs
Normal file
37
Src/Asp.NetCore2/SqliteTest/UnitTest/UnitBizDelete.cs
Normal file
@ -0,0 +1,37 @@
|
||||
using SqlSugar;
|
||||
using SqlSugarTest;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Text;
|
||||
|
||||
namespace OrmTest
|
||||
{
|
||||
internal class UnitBizDelete
|
||||
{
|
||||
public static void Init()
|
||||
{
|
||||
var _db = NewUnitTest.Db;
|
||||
_db.CurrentConnectionConfig.MoreSettings = new ConnMoreSettings
|
||||
{
|
||||
|
||||
IsAutoDeleteQueryFilter = true,//启用删除查询过滤器
|
||||
IsAutoUpdateQueryFilter = true//启用更新查询过滤器 (表达式更新,如果是实体方式更新建议先查询在更新)
|
||||
};
|
||||
_db.CodeFirst.InitTables(typeof(Special));//创建表
|
||||
var entityType = typeof(Special);
|
||||
|
||||
_db.QueryFilter.AddTableFilter<Special>(it => it.IsDeleted == false);
|
||||
//新增数据
|
||||
var special = new Special();
|
||||
special.Id = SnowFlakeSingle.Instance.NextId();
|
||||
special.Name = "测试的哦";
|
||||
_db.Insertable(special).ExecuteCommand();
|
||||
|
||||
//假删除数据
|
||||
_db.Deleteable<Special>().In(special.Id)
|
||||
.IsLogic()
|
||||
.ExecuteCommand("IsDeleted", true, "DeletedTime", "DeletedUserName", "admin");
|
||||
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user