mirror of
https://gitee.com/dotnetchina/OpenAuth.Net.git
synced 2025-07-15 14:04:41 +08:00
78 lines
2.7 KiB
C#
78 lines
2.7 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));
|
|||
|
}
|
|||
|
}
|
|||
|
}
|