mirror of
https://gitee.com/dotnetchina/OpenAuth.Net.git
synced 2026-06-26 22:33:09 +08:00
转移.net core 3.1,为.NET 5做准备
This commit is contained in:
60
OpenAuth.App/Test/TestAccessObjs.cs
Normal file
60
OpenAuth.App/Test/TestAccessObjs.cs
Normal file
@@ -0,0 +1,60 @@
|
||||
using System;
|
||||
using Infrastructure;
|
||||
using Infrastructure.Cache;
|
||||
using Microsoft.AspNetCore.Http;
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
using Moq;
|
||||
using NUnit.Framework;
|
||||
using OpenAuth.App.Request;
|
||||
using OpenAuth.App.SSO;
|
||||
using OpenAuth.Repository.Domain;
|
||||
|
||||
namespace OpenAuth.App.Test
|
||||
{
|
||||
/// <summary>
|
||||
/// 测试分配权限
|
||||
/// </summary>
|
||||
class TestAccessObjs :TestBase
|
||||
{
|
||||
public override ServiceCollection GetService()
|
||||
{
|
||||
var services = new ServiceCollection();
|
||||
|
||||
var cachemock = new Mock<ICacheContext>();
|
||||
cachemock.Setup(x => x.Get<UserAuthSession>("tokentest"))
|
||||
.Returns(new UserAuthSession { Account = "System" });
|
||||
services.AddScoped(x => cachemock.Object);
|
||||
|
||||
var httpContextAccessorMock = new Mock<IHttpContextAccessor>();
|
||||
httpContextAccessorMock.Setup(x => x.HttpContext.Request.Query[Define.TOKEN_NAME])
|
||||
.Returns("tokentest");
|
||||
|
||||
services.AddScoped(x => httpContextAccessorMock.Object);
|
||||
|
||||
return services;
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void AssignOrgUsers()
|
||||
{
|
||||
var app = _autofacServiceProvider.GetService<RevelanceManagerApp>();
|
||||
var userApp = _autofacServiceProvider.GetService<UserManagerApp>();
|
||||
|
||||
app.AssignOrgUsers(new AssignOrgUsers
|
||||
{
|
||||
OrgId = "8e31553c-cab8-4eb3-90b5-5f8ff1d21801",
|
||||
UserIds = new []{"96f63f9d-e8c8-4258-963e-3327ed7d6f56"}
|
||||
});
|
||||
|
||||
var result = userApp.Load(new QueryUserListReq
|
||||
{
|
||||
orgId = "8e31553c-cab8-4eb3-90b5-5f8ff1d21801",
|
||||
page = 1,
|
||||
limit = 10
|
||||
});
|
||||
|
||||
Console.WriteLine(JsonHelper.Instance.Serialize(result));
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
50
OpenAuth.App/Test/TestBase.cs
Normal file
50
OpenAuth.App/Test/TestBase.cs
Normal file
@@ -0,0 +1,50 @@
|
||||
using Autofac.Extensions.DependencyInjection;
|
||||
using Infrastructure.Cache;
|
||||
using Infrastructure.Extensions.AutofacManager;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
using Microsoft.Extensions.Options;
|
||||
using Moq;
|
||||
using NUnit.Framework;
|
||||
using OpenAuth.App.SSO;
|
||||
using OpenAuth.Repository;
|
||||
|
||||
namespace OpenAuth.App.Test
|
||||
{
|
||||
public class TestBase
|
||||
{
|
||||
protected AutofacServiceProvider _autofacServiceProvider;
|
||||
|
||||
[SetUp]
|
||||
public void Init()
|
||||
{
|
||||
var serviceCollection = GetService();
|
||||
serviceCollection.AddMemoryCache();
|
||||
serviceCollection.AddOptions();
|
||||
|
||||
var optionMock = new Mock<IOptions<AppSetting>>();
|
||||
optionMock.Setup(x => x.Value).Returns(new AppSetting { DbType = Define.DBTYPE_MYSQL});
|
||||
serviceCollection.AddScoped(x => optionMock.Object);
|
||||
|
||||
// 测试my sql
|
||||
serviceCollection.AddDbContext<OpenAuthDBContext>(options =>
|
||||
options.UseMySql("server=127.0.0.1;user id=root;database=openauthdb;password=000000"));
|
||||
|
||||
// serviceCollection.AddDbContext<OpenAuthDBContext>(options =>
|
||||
// options.UseSqlServer("Data Source=.;Initial Catalog=OpenAuthDB;User=sa;Password=000000;Integrated Security=True"));
|
||||
|
||||
var container = AutofacExt.InitForTest(serviceCollection);
|
||||
_autofacServiceProvider = new AutofacServiceProvider(container);
|
||||
AutofacContainerModule.ConfigServiceProvider(_autofacServiceProvider);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 测试框架默认只注入了缓存Cache,配置Option;
|
||||
/// 如果在测试的过程中需要模拟登录用户,cookie等信息,需要重写该方法,可以参考TestFlow的写法
|
||||
/// </summary>
|
||||
public virtual ServiceCollection GetService()
|
||||
{
|
||||
return new ServiceCollection();
|
||||
}
|
||||
}
|
||||
}
|
||||
123
OpenAuth.App/Test/TestBuilder.cs
Normal file
123
OpenAuth.App/Test/TestBuilder.cs
Normal file
@@ -0,0 +1,123 @@
|
||||
using System.IO;
|
||||
using System.Net.Http;
|
||||
using System.Reflection;
|
||||
using Infrastructure.Cache;
|
||||
using Infrastructure.Provider;
|
||||
using Microsoft.AspNetCore.Http;
|
||||
using NUnit.Framework;
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
using Microsoft.Extensions.DependencyInjection.Extensions;
|
||||
using Microsoft.Extensions.Hosting;
|
||||
using Moq;
|
||||
using OpenAuth.App.Request;
|
||||
using OpenAuth.App.SSO;
|
||||
using HttpContext = Infrastructure.Utilities.HttpContext;
|
||||
|
||||
namespace OpenAuth.App.Test
|
||||
{
|
||||
[TestFixture]
|
||||
public class TestBuilder :TestBase
|
||||
{
|
||||
//测试流程需要模拟登录用户
|
||||
public override ServiceCollection GetService()
|
||||
{
|
||||
var services = new ServiceCollection();
|
||||
|
||||
var cachemock = new Mock<ICacheContext>();
|
||||
cachemock.Setup(x => x.Get<UserAuthSession>("tokentest")).Returns(new UserAuthSession { Account = "test3" });
|
||||
services.AddScoped(x => cachemock.Object);
|
||||
|
||||
//模拟服务端httpContext
|
||||
var httpContextAccessorMock = new Mock<IHttpContextAccessor>();
|
||||
httpContextAccessorMock.Setup(x => x.HttpContext.Request.Query[Define.TOKEN_NAME]).Returns("tokentest");
|
||||
services.AddScoped(x => httpContextAccessorMock.Object);
|
||||
|
||||
//模拟httpclientfactory
|
||||
var mockHttpFac = new Mock<IHttpClientFactory>();
|
||||
services.AddScoped(x => mockHttpFac.Object);
|
||||
|
||||
//模拟路径
|
||||
var path = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location)
|
||||
.Replace("\\OpenAuth.App\\bin\\Debug\\netcoreapp3.1","");
|
||||
var mockPathProvider = new Mock<IPathProvider>();
|
||||
mockPathProvider.Setup(x => x.MapPath("",false)).Returns(path);
|
||||
services.AddScoped(x => mockHttpFac.Object);
|
||||
|
||||
var host = new Mock<IHostEnvironment>();
|
||||
host.Setup(x => x.ContentRootPath).Returns(Path.Combine(path, "OpenAuth.WebApi"));
|
||||
services.AddScoped(x => host.Object);
|
||||
return services;
|
||||
}
|
||||
|
||||
|
||||
[Test]
|
||||
public void add()
|
||||
{
|
||||
var app = _autofacServiceProvider.GetService<BuilderTableApp>();
|
||||
app.Add(new AddOrUpdateBuilderTableReq()
|
||||
{
|
||||
TableName = "Stock",
|
||||
Comment = "这是一个普通的应用管理生成模版",
|
||||
ClassName = "Stock",
|
||||
Namespace = "OpenAuth.Repository.Domain",
|
||||
ModuleCode = "StockApp",
|
||||
ModuleName = "仓储管理"
|
||||
});
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void CreateEntity()
|
||||
{
|
||||
var app = _autofacServiceProvider.GetService<BuilderTableApp>();
|
||||
// var id = app.Add(new AddOrUpdateBuilderTableReq()
|
||||
// {
|
||||
// TableName = "application",
|
||||
// Comment = "这是一个普通的应用管理生成模版",
|
||||
// ClassName = "Application",
|
||||
// Folder = "Application",
|
||||
// ModuleCode = "Application",
|
||||
// ModuleName = "模块管理"
|
||||
// });
|
||||
|
||||
app.CreateEntity(new CreateEntityReq
|
||||
{
|
||||
Id = "98dcbefb-8460-421f-b513-71618228a631"
|
||||
});
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void CheckModule()
|
||||
{
|
||||
var app = _autofacServiceProvider.GetService<BuilderTableApp>();
|
||||
app.CheckExistsModule("Application");
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void CreateBusiness()
|
||||
{
|
||||
var app = _autofacServiceProvider.GetService<BuilderTableApp>();
|
||||
|
||||
app.CreateBusiness(new CreateBusiReq
|
||||
{
|
||||
Id = "f4464610-8c5c-441f-8825-13d6073e4385"
|
||||
});
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void CreateVue()
|
||||
{
|
||||
var app = _autofacServiceProvider.GetService<BuilderTableApp>();
|
||||
|
||||
app.CreateVue(new CreateVueReq()
|
||||
{
|
||||
Id = "f4464610-8c5c-441f-8825-13d6073e4385",
|
||||
VueProjRootPath = "D:\\OpenAuth.Pro\\Client"
|
||||
});
|
||||
app.CreateVueApi(new CreateVueReq()
|
||||
{
|
||||
Id = "f4464610-8c5c-441f-8825-13d6073e4385",
|
||||
VueProjRootPath = "D:\\OpenAuth.Pro\\Client"
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
59
OpenAuth.App/Test/TestCategory.cs
Normal file
59
OpenAuth.App/Test/TestCategory.cs
Normal file
@@ -0,0 +1,59 @@
|
||||
using System;
|
||||
using Infrastructure;
|
||||
using Infrastructure.Cache;
|
||||
using Microsoft.AspNetCore.Http;
|
||||
using NUnit.Framework;
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
using Moq;
|
||||
using OpenAuth.App.Request;
|
||||
using OpenAuth.App.SSO;
|
||||
|
||||
namespace OpenAuth.App.Test
|
||||
{
|
||||
public class TestCategory :TestBase
|
||||
{
|
||||
//测试流程需要模拟登录用户
|
||||
public override ServiceCollection GetService()
|
||||
{
|
||||
var services = new ServiceCollection();
|
||||
|
||||
var cachemock = new Mock<ICacheContext>();
|
||||
cachemock.Setup(x => x.Get<UserAuthSession>("tokentest")).Returns(new UserAuthSession { Account = "test" });
|
||||
services.AddScoped(x => cachemock.Object);
|
||||
|
||||
var httpContextAccessorMock = new Mock<IHttpContextAccessor>();
|
||||
httpContextAccessorMock.Setup(x => x.HttpContext.Request.Query[Define.TOKEN_NAME]).Returns("tokentest");
|
||||
|
||||
services.AddScoped(x => httpContextAccessorMock.Object);
|
||||
|
||||
return services;
|
||||
}
|
||||
|
||||
|
||||
[Test]
|
||||
public void TestLoadCategories()
|
||||
{
|
||||
var app = _autofacServiceProvider.GetService<CategoryApp>();
|
||||
var result = app.Load(new QueryCategoryListReq
|
||||
{
|
||||
limit = 10,
|
||||
page = 1
|
||||
});
|
||||
Console.WriteLine(JsonHelper.Instance.Serialize(result));
|
||||
}
|
||||
|
||||
|
||||
[Test]
|
||||
public void TestAssign()
|
||||
{
|
||||
var app = _autofacServiceProvider.GetService<RevelanceManagerApp>();
|
||||
|
||||
app.AssignData(new AssignDataReq
|
||||
{
|
||||
ModuleCode = "Category",
|
||||
RoleId = "09ee2ffa-7463-4938-ae0b-1cb4e80c7c13", //管理员
|
||||
Properties = new []{"Id", "Name" }
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
96
OpenAuth.App/Test/TestDataPrivilege.cs
Normal file
96
OpenAuth.App/Test/TestDataPrivilege.cs
Normal file
@@ -0,0 +1,96 @@
|
||||
using System;
|
||||
using Infrastructure;
|
||||
using Infrastructure.Cache;
|
||||
using Microsoft.AspNetCore.Http;
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
using Moq;
|
||||
using NUnit.Framework;
|
||||
using OpenAuth.App.Interface;
|
||||
using OpenAuth.App.Request;
|
||||
using OpenAuth.App.SSO;
|
||||
|
||||
namespace OpenAuth.App.Test
|
||||
{
|
||||
class TestDataPrivilege :TestBase
|
||||
{
|
||||
public override ServiceCollection GetService()
|
||||
{
|
||||
var services = new ServiceCollection();
|
||||
|
||||
var cachemock = new Mock<ICacheContext>();
|
||||
cachemock.Setup(x => x.Get<UserAuthSession>("tokentest")).Returns(new UserAuthSession { Account = "Systems" });
|
||||
services.AddScoped(x => cachemock.Object);
|
||||
|
||||
var httpContextAccessorMock = new Mock<IHttpContextAccessor>();
|
||||
httpContextAccessorMock.Setup(x => x.HttpContext.Request.Query[Define.TOKEN_NAME]).Returns("tokentest");
|
||||
|
||||
services.AddScoped(x => httpContextAccessorMock.Object);
|
||||
|
||||
return services;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 测试资源列表的权限控制
|
||||
/// </summary>
|
||||
[Test]
|
||||
public void LoadData()
|
||||
{
|
||||
var app = _autofacServiceProvider.GetService<ResourceApp>();
|
||||
var result = app.Load(new QueryResourcesReq());
|
||||
Console.WriteLine(JsonHelper.Instance.Serialize(result));
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void TestAdd()
|
||||
{
|
||||
var auth = _autofacServiceProvider.GetService<IAuth>();
|
||||
var app = _autofacServiceProvider.GetService<DataPrivilegeRuleApp>();
|
||||
//该测试解析为:针对资源列表,【管理员】可以看到所有,角色为【神】或【测试】的只能看到自己创建的
|
||||
var filterGroup = new FilterGroup
|
||||
{
|
||||
Operation = "or"
|
||||
};
|
||||
filterGroup.Filters = new[]
|
||||
{
|
||||
new Filter //角色为【管理员】的,可以看到所有
|
||||
{
|
||||
Key = "{loginRole}",
|
||||
Contrast = "contains",
|
||||
Value = "09ee2ffa-7463-4938-ae0b-1cb4e80c7c13" //管理员
|
||||
}
|
||||
};
|
||||
filterGroup.Children = new[]
|
||||
{
|
||||
new FilterGroup //登录用户角色包含【测试】或包含【神】的,只能看到自己的
|
||||
{
|
||||
Operation = "and",
|
||||
Filters = new Filter[]
|
||||
{
|
||||
new Filter
|
||||
{
|
||||
Key = "CreateUserId",
|
||||
Contrast = "==",
|
||||
Value = "{loginUser}",
|
||||
Text = "{当前登录用户}"
|
||||
},
|
||||
new Filter
|
||||
{
|
||||
Key = "{loginRole}",
|
||||
Contrast = "intersect",
|
||||
Value = "0a7ebd0c-78d6-4fbc-8fbe-6fc25c3a932d,77e6d0c3-f9e1-4933-92c3-c1c6eef75593" //测试,神
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
app.Clear();
|
||||
app.Add(new AddOrUpdateDataPriviReq
|
||||
{
|
||||
SourceCode = "Resource",
|
||||
Description = "资源数据规则",
|
||||
PrivilegeRules = JsonHelper.Instance.Serialize(filterGroup)
|
||||
});
|
||||
Console.WriteLine(JsonHelper.Instance.Serialize(filterGroup));
|
||||
}
|
||||
}
|
||||
}
|
||||
41
OpenAuth.App/Test/TestDbExtension.cs
Normal file
41
OpenAuth.App/Test/TestDbExtension.cs
Normal file
@@ -0,0 +1,41 @@
|
||||
using System;
|
||||
using Infrastructure;
|
||||
using log4net;
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
using NUnit.Framework;
|
||||
|
||||
namespace OpenAuth.App.Test
|
||||
{
|
||||
class TestDbExtension :TestBase
|
||||
{
|
||||
private ILog log = LogManager.GetLogger(typeof(TestDbExtension));
|
||||
|
||||
[Test]
|
||||
public void TestGetProperties()
|
||||
{
|
||||
|
||||
var app = _autofacServiceProvider.GetService<DbExtension>();
|
||||
|
||||
var result = app.GetProperties("Category");
|
||||
Console.WriteLine(JsonHelper.Instance.Serialize(result));
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void GetDbEntityNames()
|
||||
{
|
||||
var app = _autofacServiceProvider.GetService<DbExtension>();
|
||||
|
||||
var result = app.GetDbEntityNames();
|
||||
Console.WriteLine(JsonHelper.Instance.Serialize(result));
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void TestGetTables()
|
||||
{
|
||||
var app = _autofacServiceProvider.GetService<DbExtension>();
|
||||
|
||||
var result = app.GetDbTableStructure("application");
|
||||
Console.WriteLine(JsonHelper.Instance.Serialize(result));
|
||||
}
|
||||
}
|
||||
}
|
||||
48
OpenAuth.App/Test/TestFlow.cs
Normal file
48
OpenAuth.App/Test/TestFlow.cs
Normal file
@@ -0,0 +1,48 @@
|
||||
using System.Net.Http;
|
||||
using Infrastructure.Cache;
|
||||
using Microsoft.AspNetCore.Http;
|
||||
using NUnit.Framework;
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
using Moq;
|
||||
using OpenAuth.App.Request;
|
||||
using OpenAuth.App.SSO;
|
||||
|
||||
namespace OpenAuth.App.Test
|
||||
{
|
||||
[TestFixture]
|
||||
public class TestFlow :TestBase
|
||||
{
|
||||
//测试流程需要模拟登录用户
|
||||
public override ServiceCollection GetService()
|
||||
{
|
||||
var services = new ServiceCollection();
|
||||
|
||||
var cachemock = new Mock<ICacheContext>();
|
||||
cachemock.Setup(x => x.Get<UserAuthSession>("tokentest")).Returns(new UserAuthSession { Account = "test3" });
|
||||
services.AddScoped(x => cachemock.Object);
|
||||
|
||||
//模拟服务端httpContext
|
||||
var httpContextAccessorMock = new Mock<IHttpContextAccessor>();
|
||||
httpContextAccessorMock.Setup(x => x.HttpContext.Request.Query[Define.TOKEN_NAME]).Returns("tokentest");
|
||||
services.AddScoped(x => httpContextAccessorMock.Object);
|
||||
|
||||
//模拟httpclientfactory
|
||||
var mockHttpFac = new Mock<IHttpClientFactory>();
|
||||
services.AddScoped(x => mockHttpFac.Object);
|
||||
|
||||
return services;
|
||||
}
|
||||
|
||||
|
||||
[Test]
|
||||
public void Verificate()
|
||||
{
|
||||
var app = _autofacServiceProvider.GetService<FlowInstanceApp>();
|
||||
app.Verification(new VerificationReq
|
||||
{
|
||||
FlowInstanceId = "76c72db4-d6c8-4734-856e-b6ffee08314a",
|
||||
VerificationFinally = "1"
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
45
OpenAuth.App/Test/TestForm.cs
Normal file
45
OpenAuth.App/Test/TestForm.cs
Normal file
@@ -0,0 +1,45 @@
|
||||
using System;
|
||||
using Infrastructure;
|
||||
using Infrastructure.Cache;
|
||||
using Microsoft.AspNetCore.Http;
|
||||
using NUnit.Framework;
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
using Moq;
|
||||
using OpenAuth.App.Request;
|
||||
using OpenAuth.App.SSO;
|
||||
|
||||
namespace OpenAuth.App.Test
|
||||
{
|
||||
[TestFixture]
|
||||
public class TestForm :TestBase
|
||||
{
|
||||
public override ServiceCollection GetService()
|
||||
{
|
||||
var services = new ServiceCollection();
|
||||
|
||||
var cachemock = new Mock<ICacheContext>();
|
||||
cachemock.Setup(x => x.Get<UserAuthSession>("tokentest")).Returns(new UserAuthSession { Account = "admin" });
|
||||
services.AddScoped(x => cachemock.Object);
|
||||
|
||||
var httpContextAccessorMock = new Mock<IHttpContextAccessor>();
|
||||
httpContextAccessorMock.Setup(x => x.HttpContext.Request.Query[Define.TOKEN_NAME]).Returns("tokentest");
|
||||
|
||||
services.AddScoped(x => httpContextAccessorMock.Object);
|
||||
|
||||
return services;
|
||||
}
|
||||
|
||||
|
||||
[Test]
|
||||
public void Load()
|
||||
{
|
||||
var app = _autofacServiceProvider.GetService<FormApp>();
|
||||
var result = app.Load(new QueryFormListReq
|
||||
{
|
||||
page = 1,
|
||||
limit = 10
|
||||
});
|
||||
Console.WriteLine(JsonHelper.Instance.Serialize(result));
|
||||
}
|
||||
}
|
||||
}
|
||||
40
OpenAuth.App/Test/TestFrmLeaveReq.cs
Normal file
40
OpenAuth.App/Test/TestFrmLeaveReq.cs
Normal file
@@ -0,0 +1,40 @@
|
||||
using Infrastructure.Cache;
|
||||
using Microsoft.AspNetCore.Http;
|
||||
using NUnit.Framework;
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
using Moq;
|
||||
using OpenAuth.App.SSO;
|
||||
|
||||
namespace OpenAuth.App.Test
|
||||
{
|
||||
public class TestFrmLeaveReq : TestBase
|
||||
{
|
||||
//测试流程需要模拟登录用户
|
||||
public override ServiceCollection GetService()
|
||||
{
|
||||
var services = new ServiceCollection();
|
||||
|
||||
var cachemock = new Mock<ICacheContext>();
|
||||
cachemock.Setup(x => x.Get<UserAuthSession>("tokentest")).Returns(new UserAuthSession { Account = "test" });
|
||||
services.AddScoped(x => cachemock.Object);
|
||||
|
||||
var httpContextAccessorMock = new Mock<IHttpContextAccessor>();
|
||||
httpContextAccessorMock.Setup(x => x.HttpContext.Request.Query[Define.TOKEN_NAME]).Returns("tokentest");
|
||||
|
||||
services.AddScoped(x => httpContextAccessorMock.Object);
|
||||
|
||||
return services;
|
||||
}
|
||||
|
||||
|
||||
[Test]
|
||||
public void Add()
|
||||
{
|
||||
var frm =
|
||||
"{\"id\":\"\",\"userName\":\"111111111\",\"requestType\":\"\",\"startDate\":\"2019-03-05T16:00:00.000Z\",\"startTime\":\"2019-03-19T08:01:23.000Z\",\"endDate\":\"2019-03-27T16:00:00.000Z\",\"endTime\":\"2019-03-19T08:01:26.000Z\",\"requestComment\":\"2222222222222\",\"attachment\":\"\",\"createDate\":\"2019-03-19T08:01:26.000Z\",\"createUserId\":\"\",\"createUserName\":\"\",\"extendInfo\":\"\"}";
|
||||
var app = _autofacServiceProvider.GetService<FrmLeaveReqApp>();
|
||||
app.Add("d8fa445f-edd9-4604-8d9e-b17ba921f9dd",
|
||||
frm);
|
||||
}
|
||||
}
|
||||
}
|
||||
41
OpenAuth.App/Test/TestJob.cs
Normal file
41
OpenAuth.App/Test/TestJob.cs
Normal file
@@ -0,0 +1,41 @@
|
||||
using System;
|
||||
using Infrastructure;
|
||||
using Infrastructure.Cache;
|
||||
using Microsoft.AspNetCore.Http;
|
||||
using NUnit.Framework;
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
using Moq;
|
||||
using OpenAuth.App.Request;
|
||||
using OpenAuth.App.SSO;
|
||||
|
||||
namespace OpenAuth.App.Test
|
||||
{
|
||||
[TestFixture]
|
||||
public class TestJob :TestBase
|
||||
{
|
||||
public override ServiceCollection GetService()
|
||||
{
|
||||
var services = new ServiceCollection();
|
||||
|
||||
var cachemock = new Mock<ICacheContext>();
|
||||
cachemock.Setup(x => x.Get<UserAuthSession>("tokentest")).Returns(new UserAuthSession { Account = "admin" });
|
||||
services.AddScoped(x => cachemock.Object);
|
||||
|
||||
var httpContextAccessorMock = new Mock<IHttpContextAccessor>();
|
||||
httpContextAccessorMock.Setup(x => x.HttpContext.Request.Query[Define.TOKEN_NAME]).Returns("tokentest");
|
||||
|
||||
services.AddScoped(x => httpContextAccessorMock.Object);
|
||||
|
||||
return services;
|
||||
}
|
||||
|
||||
|
||||
[Test]
|
||||
public void GetSysJobs()
|
||||
{
|
||||
var app = _autofacServiceProvider.GetService<OpenJobApp>();
|
||||
var result = app.QueryLocalHandlers();
|
||||
Console.WriteLine(JsonHelper.Instance.Serialize(result));
|
||||
}
|
||||
}
|
||||
}
|
||||
77
OpenAuth.App/Test/TestOrgApp.cs
Normal file
77
OpenAuth.App/Test/TestOrgApp.cs
Normal file
@@ -0,0 +1,77 @@
|
||||
using System;
|
||||
using Infrastructure;
|
||||
using Infrastructure.Cache;
|
||||
using Microsoft.AspNetCore.Http;
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
using Moq;
|
||||
using NUnit.Framework;
|
||||
using OpenAuth.App.SSO;
|
||||
using OpenAuth.Repository.Domain;
|
||||
|
||||
namespace OpenAuth.App.Test
|
||||
{
|
||||
class TestOrgApp :TestBase
|
||||
{
|
||||
public override ServiceCollection GetService()
|
||||
{
|
||||
var services = new ServiceCollection();
|
||||
|
||||
var cachemock = new Mock<ICacheContext>();
|
||||
cachemock.Setup(x => x.Get<UserAuthSession>("tokentest")).Returns(new UserAuthSession { Account = "test" });
|
||||
services.AddScoped(x => cachemock.Object);
|
||||
|
||||
var httpContextAccessorMock = new Mock<IHttpContextAccessor>();
|
||||
httpContextAccessorMock.Setup(x => x.HttpContext.Request.Query[Define.TOKEN_NAME]).Returns("tokentest");
|
||||
|
||||
services.AddScoped(x => httpContextAccessorMock.Object);
|
||||
|
||||
return services;
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void TestAdd()
|
||||
{
|
||||
var orgname = "user_" + DateTime.Now.ToString("yyyy_MM_dd HH:mm:ss");
|
||||
Console.WriteLine(orgname);
|
||||
var app = _autofacServiceProvider.GetService<OrgManagerApp>();
|
||||
|
||||
var id = app.Add(new Org
|
||||
{
|
||||
Name = orgname,
|
||||
ParentId = ""
|
||||
});
|
||||
|
||||
var org = app.Get(id);
|
||||
Console.WriteLine(JsonHelper.Instance.Serialize(org));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 测试删除华东、中部片区
|
||||
/// </summary>
|
||||
[Test]
|
||||
public void TestDel()
|
||||
{
|
||||
var app = _autofacServiceProvider.GetService<OrgManagerApp>();
|
||||
app.DelOrgCascade(new []{"66386671-0494-4e83-8346-fbcf73283f7b","182dac38-64a0-414c-990c-7c9b7558a367"});
|
||||
}
|
||||
|
||||
|
||||
[Test]
|
||||
public void TestUpdate()
|
||||
{
|
||||
var orgname = "user_" + DateTime.Now.ToString("yyyy_MM_dd HH:mm:ss");
|
||||
Console.WriteLine(orgname);
|
||||
var app = _autofacServiceProvider.GetService<OrgManagerApp>();
|
||||
|
||||
var id = app.Update(new Org
|
||||
{
|
||||
Id="543a9fcf-4770-4fd9-865f-030e562be238",
|
||||
Name = orgname,
|
||||
ParentId = ""
|
||||
});
|
||||
|
||||
var org = app.Get(id);
|
||||
Console.WriteLine(JsonHelper.Instance.Serialize(org));
|
||||
}
|
||||
}
|
||||
}
|
||||
84
OpenAuth.App/Test/TestUserApp.cs
Normal file
84
OpenAuth.App/Test/TestUserApp.cs
Normal file
@@ -0,0 +1,84 @@
|
||||
using System;
|
||||
using Infrastructure;
|
||||
using Infrastructure.Cache;
|
||||
using Microsoft.AspNetCore.Http;
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
using Moq;
|
||||
using NUnit.Framework;
|
||||
using OpenAuth.App.Request;
|
||||
using OpenAuth.App.SSO;
|
||||
|
||||
namespace OpenAuth.App.Test
|
||||
{
|
||||
class TestUserApp :TestBase
|
||||
{
|
||||
public override ServiceCollection GetService()
|
||||
{
|
||||
var services = new ServiceCollection();
|
||||
|
||||
var cachemock = new Mock<ICacheContext>();
|
||||
cachemock.Setup(x => x.Get<UserAuthSession>("tokentest")).Returns(new UserAuthSession { Account = "System" });
|
||||
services.AddScoped(x => cachemock.Object);
|
||||
|
||||
var httpContextAccessorMock = new Mock<IHttpContextAccessor>();
|
||||
httpContextAccessorMock.Setup(x => x.HttpContext.Request.Query[Define.TOKEN_NAME]).Returns("tokentest");
|
||||
|
||||
services.AddScoped(x => httpContextAccessorMock.Object);
|
||||
|
||||
return services;
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void TestAdd()
|
||||
{
|
||||
var account = "user_" + DateTime.Now.ToString("yyyy_MM_dd HH:mm:ss");
|
||||
Console.WriteLine(account);
|
||||
var app = _autofacServiceProvider.GetService<UserManagerApp>();
|
||||
|
||||
var newuser = new UpdateUserReq
|
||||
{
|
||||
Account = account,
|
||||
Name = account,
|
||||
OrganizationIds = "08f41bf6-4388-4b1e-bd3e-2ff538b44b1b,543a9fcf-4770-4fd9-865f-030e562be238",
|
||||
};
|
||||
app.AddOrUpdate(newuser);
|
||||
|
||||
app.AddOrUpdate(new UpdateUserReq
|
||||
{
|
||||
Id = newuser.Id,
|
||||
Password = "newpassword",
|
||||
Account = account,
|
||||
Name = "新名字",
|
||||
OrganizationIds = "08f41bf6-4388-4b1e-bd3e-2ff538b44b1b",
|
||||
});
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void TestLoad()
|
||||
{
|
||||
var app = _autofacServiceProvider.GetService<UserManagerApp>();
|
||||
var result = app.Load(new QueryUserListReq()
|
||||
{
|
||||
page = 1,
|
||||
limit = 10,
|
||||
orgId = "08f41bf6-4388-4b1e-bd3e-2ff538b44b1b"
|
||||
});
|
||||
|
||||
Console.WriteLine(JsonHelper.Instance.Serialize(result));
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void TestLoadByOrg()
|
||||
{
|
||||
var app = _autofacServiceProvider.GetService<UserManagerApp>();
|
||||
var result = app.LoadByOrg(new QueryUserListByOrgReq
|
||||
{
|
||||
page = 1,
|
||||
limit = 10,
|
||||
orgId = "08f41bf6-4388-4b1e-bd3e-2ff538b44b1b"
|
||||
});
|
||||
|
||||
Console.WriteLine(JsonHelper.Instance.Serialize(result));
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user