mirror of
https://gitee.com/dotnetchina/OpenAuth.Net.git
synced 2025-04-05 17:38:01 +08:00
88 lines
3.1 KiB
C#
88 lines
3.1 KiB
C#
using System;
|
|
using System.Threading.Tasks;
|
|
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 TestDynamicApiApp :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 async Task TestGet()
|
|
{
|
|
var app = _autofacServiceProvider.GetService<DynamicApiApp>();
|
|
|
|
var obj = await app.Get(new QueryDynamicEntityReq { TableName = "noentity", Id = "1" });
|
|
Console.WriteLine(JsonHelper.Instance.Serialize(obj));
|
|
}
|
|
|
|
[Test]
|
|
public async Task TestGetList()
|
|
{
|
|
var app = _autofacServiceProvider.GetService<DynamicApiApp>();
|
|
|
|
var obj = await app.GetList(new QueryDynamicListReq { TableName = "noentity", page = 1, limit = 10, key = "" });
|
|
Console.WriteLine(JsonHelper.Instance.Serialize(obj));
|
|
}
|
|
|
|
[Test]
|
|
public async Task TestAdd()
|
|
{
|
|
var app = _autofacServiceProvider.GetService<DynamicApiApp>();
|
|
|
|
var obj = await app.Add(new AddOrUpdateDynamicEntityReq { TableName = "noentity", Obj = new { Id = "10", P1 = DateTime.Now.ToString() } });
|
|
Console.WriteLine(JsonHelper.Instance.Serialize(obj));
|
|
}
|
|
|
|
[Test]
|
|
public async Task TestUpdate()
|
|
{
|
|
var app = _autofacServiceProvider.GetService<DynamicApiApp>();
|
|
|
|
var obj = await app.Update(new AddOrUpdateDynamicEntityReq { TableName = "noentity", Obj = new { Id = "1", P1 = DateTime.Now.ToString() } });
|
|
Console.WriteLine(JsonHelper.Instance.Serialize(obj));
|
|
}
|
|
|
|
[Test]
|
|
public async Task TestDelete()
|
|
{
|
|
var app = _autofacServiceProvider.GetService<DynamicApiApp>();
|
|
|
|
var obj = await app.Delete(new DelDynamicReq() { TableName = "noentity", Ids = new string[] { "10" } });
|
|
Console.WriteLine(JsonHelper.Instance.Serialize(obj));
|
|
}
|
|
|
|
[Test]
|
|
public void TestInvoke()
|
|
{
|
|
var app = _autofacServiceProvider.GetService<DynamicApiApp>();
|
|
|
|
var obj = app.Invoke(new InvokeDynamicReq { ServiceName = "UserManagerApp", MethodName = "GetParent",
|
|
Parameters = new { userid = "0ceff0f8-f848-440c-bc26-d8605ac858cd" } });
|
|
Console.WriteLine(JsonHelper.Instance.Serialize(obj));
|
|
}
|
|
}
|
|
}
|