|
|
|
using DS.Module.Core;
|
|
|
|
using DS.Module.Core.Extensions;
|
|
|
|
using DS.WMS.Core.Sys.Entity;
|
|
|
|
using DS.WMS.Core.Sys.Interface;
|
|
|
|
using Microsoft.Extensions.DependencyInjection;
|
|
|
|
using SqlSugar;
|
|
|
|
using Xunit;
|
|
|
|
|
|
|
|
namespace Ds.WMS.Test;
|
|
|
|
|
|
|
|
public class UnitTest1
|
|
|
|
{
|
|
|
|
private readonly IServiceProvider _serviceProvider;
|
|
|
|
private readonly ISqlSugarClient db;
|
|
|
|
// private readonly ICommonService _commonService;
|
|
|
|
public UnitTest1(IServiceProvider serviceProvider)
|
|
|
|
{
|
|
|
|
_serviceProvider = serviceProvider;
|
|
|
|
db = _serviceProvider.GetRequiredService<ISqlSugarClient>();
|
|
|
|
// _commonService = _serviceProvider.GetRequiredService<ICommonService>();
|
|
|
|
}
|
|
|
|
|
|
|
|
[Fact]
|
|
|
|
public void Test1()
|
|
|
|
{
|
|
|
|
var temp = EntityUtil.getEntity("SysUser");
|
|
|
|
Assert.True(true);
|
|
|
|
}
|
|
|
|
|
|
|
|
[Fact]
|
|
|
|
public void GetEntity()
|
|
|
|
{
|
|
|
|
var info = db.Queryable<object>().AS("sys_user").Where("Id=@Id", new { Id = 1745261353939111936 }).First();
|
|
|
|
|
|
|
|
Assert.True(info.IsNotNull());
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
[Fact]
|
|
|
|
public void ConstTest()
|
|
|
|
{
|
|
|
|
ConstUtil.GetConstantField();
|
|
|
|
Assert.True(true);
|
|
|
|
}
|
|
|
|
[Fact]
|
|
|
|
public void DataRuleTest()
|
|
|
|
{
|
|
|
|
// var query = _commonService.GetDataRuleFilter<SysUser>();
|
|
|
|
|
|
|
|
var query = GetDataRuleFilter<SysUser>();
|
|
|
|
Assert.True(true);
|
|
|
|
}
|
|
|
|
public ISugarQueryable<T> GetDataRuleFilter<T>()
|
|
|
|
{
|
|
|
|
// var userInfo = db.Queryable<SysUser>().First(x => x.Id == long.Parse(user.UserId));
|
|
|
|
// if (userInfo.UserType == 0)
|
|
|
|
// {
|
|
|
|
// return db.Queryable<T>(); //超级管理员特权
|
|
|
|
// }
|
|
|
|
|
|
|
|
var moduleName = typeof(T).Name;
|
|
|
|
// var rule = db.Queryable<SysDataRule>().First(u => u.PermissionName == moduleName);
|
|
|
|
// if (rule == null) return db.Queryable<T>(); //没有设置数据规则,那么视为该资源允许被任何主体查看
|
|
|
|
return db.Queryable<T>();
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|