add new web api and test

This commit is contained in:
Aigio Liu
2021-03-07 18:54:29 +08:00
parent ec1e7200b4
commit b528b21cf7
28 changed files with 388 additions and 12 deletions
@@ -1,4 +1,5 @@
using NUnit.Framework;
using System.Application.Models;
using System.Application.Services;
using System.Linq;
using System.Threading;
@@ -9,6 +10,9 @@ namespace System.Application
[TestFixture]
public class HttpTest
{
/// <summary>
/// 测试图片下载缓存,同一个图片地址,多次请求,仅发送一次,且优先从缓存中加载图片
/// </summary>
[Test]
public void GetImage()
{
@@ -39,5 +43,47 @@ namespace System.Application
TestContext.WriteLine($"({tid}-{tid2})requestUri: {requestUri}, length: {result?.Length}");
}
}
#if DEBUG
/// <summary>
/// 测试 登陆与注册 接口,先开服务端(私有),再测试
/// </summary>
/// <returns></returns>
[Test]
public async Task LoginOrRegister()
{
var client = ICloudServiceClient.Instance;
var req1 = new SendSmsRequest
{
PhoneNumber = "18611112222",
Type = SmsCodeType.LoginOrRegister,
};
var rsp1 = await client.AuthMessage.SendSms(req1);
Assert.IsTrue(rsp1.IsSuccess);
var req2 = new LoginOrRegisterRequest
{
PhoneNumber = req1.PhoneNumber,
SmsCode = "666666",
};
var rsp2 = await ICloudServiceClient.Instance.Account.LoginOrRegister(req2);
Assert.IsTrue(rsp2.IsSuccess);
var isLoginOrRegister = rsp2.Content.ThrowIsNull(nameof(rsp2.Content)).IsLoginOrRegister;
TestContext.WriteLine($"isLoginOrRegister: {isLoginOrRegister}");
var jsonStr = Serializable2.S(rsp2.Content);
TestContext.WriteLine("jsonStr: ");
TestContext.WriteLine(jsonStr);
}
#endif
}
}
@@ -1,6 +1,9 @@
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Logging;
using NUnit.Framework;
using System.Application.Models;
using System.Application.Services;
using System.Application.Services.Implementation;
using System.IO;
using System.Logging;
@@ -18,6 +21,7 @@ namespace System.Application
// all tests in the assembly are run
if (!DIInit)
{
ModelValidatorProvider.Init();
DI.Init(ConfigureServices);
var path = AppContext.BaseDirectory;
@@ -38,6 +42,9 @@ namespace System.Application
// all tests in the assembly have been run
}
const string DevAppVersion = "00000000000000000000000000000001";
const string DevRSAPublicKey = "{\"v\":\"AQAB\",\"n\":\"u4iAALIX2NLyh9-GeWbBdNK2gpa1qFx1S2fFoRKuzxspTP4oyJ2uMF7xZ1yWogup-M7x3BPYrXMTzmyYTmJFDDsWt3nEl-mk6ABJ5RKeCUO1GfHXo8jvHod_pfs8gmFmyzSoYdxUp6BayXT7LkxZz9pO2ZEK2JU1dkSQKRyy_U9ceDsy9D-xsmkX2MrtYTdG51CxdFD_SrStI1YOEhbBv_A97JYJv_F5UyP2CGJ_zWG-MVWO-2Ir2AiVQMBR9PUfNweAGEAsm-AAnRHqIGHjOIMm8PqmkY4Lft2zwDE2TMcw-yUBOwYUvWanIKbO-T3KdBIc7ZbNe9Vut8aVWJa8UQ\"}";
static void ConfigureServices(IServiceCollection services)
{
services.AddLogging(l => l.AddProvider(NUnitLoggerProvider.Instance));
@@ -45,8 +52,49 @@ namespace System.Application
{
o.MinLevel = LogLevel.Trace;
});
services.TryAddHttpPlatformHelper();
var options = new AppSettings
{
ApiBaseUrl = "https://localhost:5001",
AppVersion = Guid.ParseExact(DevAppVersion, "N"),
RSASecret = DevRSAPublicKey,
};
// app 配置项
services.TryAddOptions(options);
// 模型验证框架
services.TryAddModelValidator();
services.AddRepositories();
// 键值对存储
services.TryAddStorage();
// 业务平台用户管理
services.TryAddUserManager();
// 服务端API调用
services.TryAddCloudServiceClient<CloudServiceClient>();
// 通用 Http 服务
services.AddHttpService();
PlatformToastImpl.TryAddToast(services);
}
}
internal sealed class PlatformToastImpl : ToastImpl
{
public PlatformToastImpl(IToastIntercept intercept) : base(intercept)
{
}
protected override void PlatformShow(string text, int duration)
{
Log.Info("Toast", text);
}
public static IServiceCollection TryAddToast(IServiceCollection services)
=> TryAddToast<PlatformToastImpl>(services);
}
}
@@ -16,6 +16,9 @@
<Compile Include="..\System.Common.UnitTest\Logging\NUnitLoggerProvider.cs">
<Link>Logging\NUnitLoggerProvider.cs</Link>
</Compile>
<Compile Include="..\System.Common.UnitTest\Utils\Serializable2.cs">
<Link>Utils\Serializable2.cs</Link>
</Compile>
</ItemGroup>
<ItemGroup>