diff --git a/NewLife.Remoting.Extensions/NewLife.Remoting.Extensions.csproj b/NewLife.Remoting.Extensions/NewLife.Remoting.Extensions.csproj index 8f66641..7d9622d 100644 --- a/NewLife.Remoting.Extensions/NewLife.Remoting.Extensions.csproj +++ b/NewLife.Remoting.Extensions/NewLife.Remoting.Extensions.csproj @@ -1,4 +1,4 @@ - + Library @@ -6,7 +6,7 @@ 协议通信扩展库 提供WebApi应用级服务端 新生命开发团队 - ©2002-2024 NewLife + ©2002-2025 NewLife 3.2 $([System.DateTime]::Now.ToString(`yyyy.MMdd`)) $(VersionPrefix).$(VersionSuffix) diff --git a/NewLife.Remoting/NewLife.Remoting.csproj b/NewLife.Remoting/NewLife.Remoting.csproj index f85f058..352552e 100644 --- a/NewLife.Remoting/NewLife.Remoting.csproj +++ b/NewLife.Remoting/NewLife.Remoting.csproj @@ -4,7 +4,7 @@ 协议通信库 提供高性能RPC客户端服务端,提供Http/WebSocket客户端服务端,提供应用级客户端 新生命开发团队 - ©2002-2024 新生命开发团队 + ©2002-2025 新生命开发团队 3.2 $([System.DateTime]::Now.ToString(`yyyy.MMdd`)) $(VersionPrefix).$(VersionSuffix) @@ -54,7 +54,7 @@ - + diff --git a/Readme.MD b/Readme.MD index 585c4e5..e3c9a52 100644 --- a/Readme.MD +++ b/Readme.MD @@ -1,4 +1,4 @@ -# NewLife.Remoting - 协议通信库 +# NewLife.Remoting - 协议通信库 ![GitHub top language](https://img.shields.io/github/languages/top/newlifex/NewLife.Remoting?logo=github) ![GitHub License](https://img.shields.io/github/license/newlifex/NewLife.Remoting?logo=github) @@ -81,18 +81,18 @@ Nuget:NewLife.Remoting / NewLife.Remoting.Extensions ## 新生命项目矩阵 -各项目默认支持net9.0/netstandard2.1/netstandard2.0/net4.5,旧版(2022.1225)支持net4.5/net4.0/net2.0 +各项目默认支持net9.0/netstandard2.1/netstandard2.0/net4.62/net4.5,旧版(2024.0801)支持net4.0/net2.0 | 项目 | 年份 | 说明 | | :--------------------------------------------------------------: | :---: | -------------------------------------------------------------------------------------- | | 基础组件 | | 支撑其它中间件以及产品项目 | | [NewLife.Core](https://github.com/NewLifeX/X) | 2002 | 核心库,日志、配置、缓存、网络、序列化、APM性能追踪 | -| [NewLife.XCode](https://github.com/NewLifeX/NewLife.XCode) | 2005 | 大数据中间件,单表百亿级,MySql/SQLite/SqlServer/Oracle/TDengine/达梦,自动分表 | +| [NewLife.XCode](https://github.com/NewLifeX/NewLife.XCode) | 2005 | 大数据中间件,单表百亿级,MySql/SQLite/SqlServer/Oracle/PostgreSql/达梦,自动分表 | | [NewLife.Net](https://github.com/NewLifeX/NewLife.Net) | 2005 | 网络库,单机千万级吞吐率(2266万tps),单机百万级连接(400万Tcp) | -| [NewLife.Remoting](https://github.com/NewLifeX/NewLife.Remoting) | 2011 | RPC通信框架,内网高吞吐或物联网硬件设备场景 | +| [NewLife.Remoting](https://github.com/NewLifeX/NewLife.Remoting) | 2011 | RPC通信框架,内网高吞吐,物联网设备低开销易接入 | | [NewLife.Cube](https://github.com/NewLifeX/NewLife.Cube) | 2010 | 魔方快速开发平台,集成了用户权限、SSO登录、OAuth服务端等,单表100亿级项目验证 | | [NewLife.Agent](https://github.com/NewLifeX/NewLife.Agent) | 2008 | 服务管理组件,把应用安装成为操作系统守护进程,Windows服务、Linux的Systemd | -| [NewLife.Zero](https://github.com/NewLifeX/NewLife.Zero) | 2020 | Zero零代脚手架,基于NewLife组件生态的项目模板,Web、WebApi、Service | +| [NewLife.Zero](https://github.com/NewLifeX/NewLife.Zero) | 2020 | Zero零代脚手架,基于NewLife组件生态的项目模板NewLife.Templates,Web、WebApi、Service | | 中间件 | | 对接知名中间件平台 | | [NewLife.Redis](https://github.com/NewLifeX/NewLife.Redis) | 2017 | Redis客户端,微秒级延迟,百万级吞吐,丰富的消息队列,百亿级数据量项目验证 | | [NewLife.RocketMQ](https://github.com/NewLifeX/NewLife.RocketMQ) | 2018 | RocketMQ纯托管客户端,支持Apache RocketMQ和阿里云消息队列,十亿级项目验 | @@ -100,36 +100,34 @@ Nuget:NewLife.Remoting / NewLife.Remoting.Extensions | [NewLife.IoT](https://github.com/NewLifeX/NewLife.IoT) | 2022 | IoT标准库,定义物联网领域的各种通信协议标准规范 | | [NewLife.Modbus](https://github.com/NewLifeX/NewLife.Modbus) | 2022 | ModbusTcp/ModbusRTU/ModbusASCII,基于IoT标准库实现,支持IoT平台和IoTEdge | | [NewLife.Siemens](https://github.com/NewLifeX/NewLife.Siemens) | 2022 | 西门子PLC协议,基于IoT标准库实现,支持IoT平台和IoTEdge | -| [NewLife.Map](https://github.com/NewLifeX/NewLife.Map) | 2022 | 地图组件库,封装百度地图、高德地图和腾讯地图 | -| [NewLife.IP](https://github.com/NewLifeX/NewLife.IP) | 2022 | IP地址库,IP地址转物理地址 | +| [NewLife.Map](https://github.com/NewLifeX/NewLife.Map) | 2022 | 地图组件库,封装百度地图、高德地图、腾讯地图、天地图 | +| [NewLife.Audio](https://github.com/NewLifeX/NewLife.Audio) | 2023 | 音频编解码库,PCM/ADPCMA/G711A/G722U/WAV/AAC | | 产品平台 | | 产品平台级,编译部署即用,个性化自定义 | -| [AntJob](https://github.com/NewLifeX/AntJob) | 2019 | 蚂蚁调度,分布式大数据计算平台(实时/离线),蚂蚁搬家分片思想,万亿级数据量项目验证 | | [Stardust](https://github.com/NewLifeX/Stardust) | 2018 | 星尘,分布式服务平台,节点管理、APM监控中心、配置中心、注册中心、发布中心 | +| [AntJob](https://github.com/NewLifeX/AntJob) | 2019 | 蚂蚁调度,分布式大数据计算平台(实时/离线),蚂蚁搬家分片思想,万亿级数据量项目验证 | | [NewLife.ERP](https://github.com/NewLifeX/NewLife.ERP) | 2021 | 企业ERP,产品管理、客户管理、销售管理、供应商管理 | | [CrazyCoder](https://github.com/NewLifeX/XCoder) | 2006 | 码神工具,众多开发者工具,网络、串口、加解密、正则表达式、Modbus | +| [EasyIO](https://github.com/NewLifeX/EasyIO) | 2023 | 简易文件存储,支持分布式系统中文件集中存储。 | | [XProxy](https://github.com/NewLifeX/XProxy) | 2005 | 产品级反向代理,NAT代理、Http代理 | | [HttpMeter](https://github.com/NewLifeX/HttpMeter) | 2022 | Http压力测试工具 | | [GitCandy](https://github.com/NewLifeX/GitCandy) | 2015 | Git源代码管理系统 | | [SmartOS](https://github.com/NewLifeX/SmartOS) | 2014 | 嵌入式操作系统,完全独立自主,支持ARM Cortex-M芯片架构 | | [SmartA2](https://github.com/NewLifeX/SmartA2) | 2019 | 嵌入式工业计算机,物联网边缘网关,高性能.NET6主机,应用于工业、农业、交通、医疗 | -| 菲凡物联FIoT | 2020 | 物联网整体解决方案,建筑、环保、农业,软硬件及大数据分析一体化,单机十万级点位项目验证 | -| NewLife.UWB | 2020 | 厘米级(10~20cm)高精度室内定位,软硬件一体化,与其它系统联动,大型展厅项目验证 | - - +| FIoT物联网平台 | 2020 | 物联网整体解决方案,建筑、环保、农业,软硬件及大数据分析一体化,单机十万级点位项目验证 | +| UWB高精度室内定位 | 2020 | 厘米级(10~20cm)高精度室内定位,软硬件一体化,与其它系统联动,大型展厅项目验证 | ## 新生命开发团队 - ![XCode](https://newlifex.com/logo.png) 新生命团队(NewLife)成立于2002年,是新时代物联网行业解决方案提供者,致力于提供软硬件应用方案咨询、系统架构规划与开发服务。 -团队主导的开源NewLife系列组件已被广泛应用于各行业,Nuget累计下载量高达60余万次。 -团队开发的大数据核心组件NewLife.XCode、蚂蚁调度计算平台AntJob、星尘分布式平台Stardust、缓存队列组件NewLife.Redis以及物联网平台NewLife.IoT,均成功应用于电力、高校、互联网、电信、交通、物流、工控、医疗、文博等行业,为客户提供了大量先进、可靠、安全、高质量、易扩展的产品和系统集成服务。 +团队主导的80多个开源项目已被广泛应用于各行业,Nuget累计下载量高达300余万次。 +团队开发的大数据中间件NewLife.XCode、蚂蚁调度计算平台AntJob、星尘分布式平台Stardust、缓存队列组件NewLife.Redis以及物联网平台FIoT,均成功应用于电力、高校、互联网、电信、交通、物流、工控、医疗、文博等行业,为客户提供了大量先进、可靠、安全、高质量、易扩展的产品和系统集成服务。 -我们将不断通过服务的持续改进,成为客户长期信赖的合作伙伴,通过不断的创新和发展,成为国内优秀的IT服务供应商。 +我们将不断通过服务的持续改进,成为客户长期信赖的合作伙伴,通过不断的创新和发展,成为国内优秀的IoT服务供应商。 `新生命团队始于2002年,部分开源项目具有20年以上漫长历史,源码库保留有2010年以来所有修改记录` 网站:https://newlifex.com 开源:https://github.com/newlifex QQ群:1600800/1600838 -微信公众号:(智能大石头) +微信公众号: ![智能大石头](https://newlifex.com/stone.jpg) diff --git a/Samples/Demo/Demo.csproj b/Samples/Demo/Demo.csproj index 089739d..63f3633 100644 --- a/Samples/Demo/Demo.csproj +++ b/Samples/Demo/Demo.csproj @@ -1,4 +1,4 @@ - + Exe @@ -6,7 +6,7 @@ RPC例程 RPC通信例程 新生命开发团队 - ©2002-2024 NewLife + ©2002-2025 NewLife 1.0 $([System.DateTime]::Now.ToString(`yyyy.MMdd`)) $(VersionPrefix).$(VersionSuffix) diff --git a/Samples/IoTZero/IoTZero.csproj b/Samples/IoTZero/IoTZero.csproj index 8861a95..70670e2 100644 --- a/Samples/IoTZero/IoTZero.csproj +++ b/Samples/IoTZero/IoTZero.csproj @@ -5,7 +5,7 @@ 物联网服务平台 IoT服务平台 新生命开发团队 - ©2002-2024 NewLife + ©2002-2025 NewLife 1.0 $([System.DateTime]::Now.ToString(`yyyy.MMdd`)) $(VersionPrefix).$(VersionSuffix) @@ -19,11 +19,11 @@ - - - + + + - + diff --git a/Samples/Zero.Desktop/Zero.Desktop.csproj b/Samples/Zero.Desktop/Zero.Desktop.csproj index 906a277..0980a6e 100644 --- a/Samples/Zero.Desktop/Zero.Desktop.csproj +++ b/Samples/Zero.Desktop/Zero.Desktop.csproj @@ -6,7 +6,7 @@ 客户端桌面应用 CS架构的客户端桌面应用,给用户提供便捷操作,可对接硬件 新生命开发团队 - ©2002-2024 NewLife + ©2002-2025 NewLife 1.0 $([System.DateTime]::Now.ToString(`yyyy.MMdd`)) $(VersionPrefix).$(VersionSuffix) @@ -26,7 +26,7 @@ - + diff --git a/Samples/Zero.RpcServer/Zero.RpcServer.csproj b/Samples/Zero.RpcServer/Zero.RpcServer.csproj index 033b135..b45931f 100644 --- a/Samples/Zero.RpcServer/Zero.RpcServer.csproj +++ b/Samples/Zero.RpcServer/Zero.RpcServer.csproj @@ -1,4 +1,4 @@ - + Exe @@ -6,7 +6,7 @@ RPC服务端 高性能,长连接,数据接口 新生命开发团队 - ©2002-2024 NewLife + ©2002-2025 NewLife 1.0 $([System.DateTime]::Now.ToString(`yyyy.MMdd`)) $(VersionPrefix).$(VersionSuffix) @@ -21,7 +21,7 @@ - + diff --git a/Samples/ZeroServer/ZeroServer.csproj b/Samples/ZeroServer/ZeroServer.csproj index f3d8003..a4489d1 100644 --- a/Samples/ZeroServer/ZeroServer.csproj +++ b/Samples/ZeroServer/ZeroServer.csproj @@ -5,7 +5,7 @@ 零代服务平台 CS架构服务端平台 新生命开发团队 - ©2002-2024 NewLife + ©2002-2025 NewLife 1.0 $([System.DateTime]::Now.ToString(`yyyy.MMdd`)) $(VersionPrefix).$(VersionSuffix) @@ -19,9 +19,9 @@ - + - + diff --git a/Test/Test.csproj b/Test/Test.csproj index f555b3e..7d64f71 100644 --- a/Test/Test.csproj +++ b/Test/Test.csproj @@ -10,7 +10,7 @@ - + diff --git a/XUnitTest/ApiDownTests.cs b/XUnitTest/ApiDownTests.cs index 5490b0f..ae25ef9 100644 --- a/XUnitTest/ApiDownTests.cs +++ b/XUnitTest/ApiDownTests.cs @@ -1,5 +1,6 @@ using System; using System.Threading; +using System.Threading.Tasks; using NewLife; using NewLife.Data; using NewLife.Log; diff --git a/XUnitTest/ApiHelperTest.cs b/XUnitTest/ApiHelperTest.cs index f9acc6c..f6e347f 100644 --- a/XUnitTest/ApiHelperTest.cs +++ b/XUnitTest/ApiHelperTest.cs @@ -5,6 +5,7 @@ using System.Net.Http; using System.Net.Http.Headers; using System.Runtime.Serialization; +using System.Threading.Tasks; using NewLife; using NewLife.Data; using NewLife.Remoting; @@ -75,7 +76,7 @@ public void BuildRequestTest(String method, String action) [InlineData("Put", "api/info", "[packet]")] [InlineData("Put", "api/info", "[object]")] [InlineData("Put", "api/info", "[dictionary]")] - public async void BuildRequestTest2(String method, String action, String argKind) + public async Task BuildRequestTest2(String method, String action, String argKind) { // 几大类型参数 Object args = null; @@ -161,7 +162,7 @@ public async void BuildRequestTest2(String method, String action, String argKind [Theory(DisplayName = "处理Http错误响应")] [InlineData(null)] [InlineData("12345678")] - public async void ProcessErrorResponseTest(String content) + public async Task ProcessErrorResponseTest(String content) { var msg = new HttpResponseMessage(HttpStatusCode.BadRequest); if (!content.IsNullOrEmpty()) msg.Content = new StringContent(content); @@ -171,9 +172,9 @@ public async void ProcessErrorResponseTest(String content) Assert.Equal(msg, rs); // 捕获Api异常 - var ex = await Assert.ThrowsAsync(() => ApiHelper.ProcessResponse(msg)); + var ex = await Assert.ThrowsAsync(() => ApiHelper.ProcessResponse(msg)); - Assert.Equal(HttpStatusCode.BadRequest, (HttpStatusCode)ex.Code); + Assert.Equal(HttpStatusCode.BadRequest, (HttpStatusCode)ex.StatusCode); if (!content.IsNullOrEmpty()) Assert.Equal(content, ex.Message); else @@ -184,7 +185,7 @@ public async void ProcessErrorResponseTest(String content) [InlineData("{code:500,data:\"Stone\"}")] [InlineData("{code:501,message:\"error\"}")] [InlineData("{code:502,data:\"Stone\",msg:\"error\"}")] - public async void ProcessErrorResponseTest2(String content) + public async Task ProcessErrorResponseTest2(String content) { var msg = new HttpResponseMessage(HttpStatusCode.OK); if (!content.IsNullOrEmpty()) msg.Content = new StringContent(content); @@ -207,7 +208,7 @@ public async void ProcessErrorResponseTest2(String content) [Theory(DisplayName = "处理Byte响应")] [InlineData(null)] [InlineData("12345678")] - public async void ProcessByteResponseTest(String content) + public async Task ProcessByteResponseTest(String content) { var msg = new HttpResponseMessage(HttpStatusCode.OK); if (!content.IsNullOrEmpty()) msg.Content = new ByteArrayContent(content.ToHex()); @@ -228,7 +229,7 @@ public async void ProcessByteResponseTest(String content) [Theory(DisplayName = "处理Packet响应")] [InlineData(null)] [InlineData("12345678")] - public async void ProcessPacketResponseTest(String content) + public async Task ProcessPacketResponseTest(String content) { var msg = new HttpResponseMessage(HttpStatusCode.OK); if (!content.IsNullOrEmpty()) msg.Content = new ByteArrayContent(content.ToHex()); @@ -251,7 +252,7 @@ public async void ProcessPacketResponseTest(String content) [InlineData("{code:0,data:\"Stone\"}")] [InlineData("{code:0,data:{aaa:\"bbb\",xxx:1234}}")] [InlineData("{code:0,data:{OSName:\"win10\",OSVersion:\"10.0\"}}")] - public async void ProcessResponseTest(String content) + public async Task ProcessResponseTest(String content) { var msg = new HttpResponseMessage(HttpStatusCode.OK); if (!content.IsNullOrEmpty()) msg.Content = new StringContent(content); @@ -293,7 +294,7 @@ public async void ProcessResponseTest(String content) [Theory(DisplayName = "处理复杂响应")] [InlineData("{errcode:0,errmsg:\"ok\",access_token:\"12345678\"}")] - public async void ProcessResponse_OtherData(String content) + public async Task ProcessResponse_OtherData(String content) { var msg = new HttpResponseMessage(HttpStatusCode.OK); if (!content.IsNullOrEmpty()) msg.Content = new StringContent(content); @@ -321,7 +322,7 @@ class MyToken [Theory(DisplayName = "处理异常响应")] [InlineData("{errcode:500,errmsg:\"valid data\"}")] - public async void ProcessResponse_Error(String content) + public async Task ProcessResponse_Error(String content) { var msg = new HttpResponseMessage(HttpStatusCode.OK); if (!content.IsNullOrEmpty()) msg.Content = new StringContent(content); @@ -333,7 +334,7 @@ public async void ProcessResponse_Error(String content) } //[Fact] - public async void ProcessResponse_DingTalk() + public async Task ProcessResponse_DingTalk() { var key = "dingbvcq0mz3pidpwtch"; var secret = "7OTdnimQwf5LJnVp8e0udX1wPxKyCsspLqM2YcBDawvg3BlIkzxIsOs1YhDjiOxj"; @@ -354,7 +355,7 @@ public async void ProcessResponse_DingTalk() } [Fact(DisplayName = "异步请求")] - public async void SendAsyncTest() + public async Task SendAsyncTest() { var dic = await _Client.GetAsync>("api/info"); Assert.NotNull(dic); @@ -371,7 +372,7 @@ public async void SendAsyncTest() } [Fact(DisplayName = "异常请求")] - public async void ErrorTest() + public async Task ErrorTest() { var msg = await _Client.GetAsync("api/info"); Assert.NotNull(msg); @@ -392,7 +393,7 @@ public async void ErrorTest() } [Fact(DisplayName = "上传数据")] - public async void PostAsyncTest() + public async Task PostAsyncTest() { var state = Rand.NextString(8); var state2 = Rand.NextString(8); @@ -412,7 +413,7 @@ public async void PostAsyncTest() } [Fact(DisplayName = "令牌请求")] - public async void TokenTest() + public async Task TokenTest() { var auth = new AuthenticationHeaderValue("Bearer", "12345678"); //var headers = new Dictionary(); diff --git a/XUnitTest/ApiHttpClientTests.cs b/XUnitTest/ApiHttpClientTests.cs index 11669e2..0028305 100644 --- a/XUnitTest/ApiHttpClientTests.cs +++ b/XUnitTest/ApiHttpClientTests.cs @@ -1,256 +1,253 @@ using System; using System.Collections.Generic; -using System.Net; -using System.Net.Http; +using System.Threading.Tasks; using NewLife; -using NewLife.Data; using NewLife.Http; using NewLife.Log; using NewLife.Remoting; using NewLife.Security; using Xunit; -namespace XUnitTest.Remoting +namespace XUnitTest.Remoting; + +public class ApiHttpClientTests : DisposeBase { - public class ApiHttpClientTests : DisposeBase - { - private readonly ApiServer _Server; - private readonly String _Address; - private readonly IApiClient _Client; + private readonly ApiServer _Server; + private readonly String _Address; + private readonly IApiClient _Client; - public ApiHttpClientTests() + public ApiHttpClientTests() + { + _Server = new ApiServer(12347) { - _Server = new ApiServer(12347) - { - //Log = XTrace.Log, - //EncoderLog = XTrace.Log, - }; - _Server.Handler = new TokenApiHandler { Host = _Server }; - _Server.Start(); - - _Address = "http://127.0.0.1:12347"; - - //_Client = new ApiHttpClient(); - //_Client.Add("addr1", new Uri("http://127.0.0.1:12347")); - _Client = new ApiHttpClient(_Address); - } + //Log = XTrace.Log, + //EncoderLog = XTrace.Log, + }; + _Server.Handler = new TokenApiHandler { Host = _Server }; + _Server.Start(); - protected override void Dispose(Boolean disposing) - { - base.Dispose(disposing); + _Address = "http://127.0.0.1:12347"; - _Server.TryDispose(); - } + //_Client = new ApiHttpClient(); + //_Client.Add("addr1", new Uri("http://127.0.0.1:12347")); + _Client = new ApiHttpClient(_Address); + } - [Fact(DisplayName = "基础Api测试")] - public async void BasicTest() - { - var apis = await _Client.InvokeAsync("api/all"); - Assert.NotNull(apis); - Assert.Equal(2, apis.Length); - Assert.Equal("String[] Api/All()", apis[0]); - Assert.Equal("Object Api/Info(String state)", apis[1]); - //Assert.Equal("Packet Api/Info2(Packet state)", apis[2]); - } + protected override void Dispose(Boolean disposing) + { + base.Dispose(disposing); - [Fact(DisplayName = "参数测试")] - public async void InfoTest() - { - var state = Rand.NextString(8); - var state2 = Rand.NextString(8); + _Server.TryDispose(); + } - var infs = await _Client.InvokeAsync>("api/info", new { state, state2 }); - Assert.NotNull(infs); - Assert.Equal(Environment.MachineName, infs["MachineName"]); - //Assert.Equal(Environment.UserName, infs["UserName"]); + [Fact(DisplayName = "基础Api测试")] + public async Task BasicTest() + { + var apis = await _Client.InvokeAsync("api/all"); + Assert.NotNull(apis); + Assert.Equal(2, apis.Length); + Assert.Equal("String[] Api/All()", apis[0]); + Assert.Equal("Object Api/Info(String state)", apis[1]); + //Assert.Equal("Packet Api/Info2(Packet state)", apis[2]); + } - Assert.Equal(state, infs["state"]); - Assert.Null(infs["state2"]); - } + [Fact(DisplayName = "参数测试")] + public async Task InfoTest() + { + var state = Rand.NextString(8); + var state2 = Rand.NextString(8); + + var infs = await _Client.InvokeAsync>("api/info", new { state, state2 }); + Assert.NotNull(infs); + Assert.Equal(Environment.MachineName, infs["MachineName"]); + //Assert.Equal(Environment.UserName, infs["UserName"]); + + Assert.Equal(state, infs["state"]); + Assert.Null(infs["state2"]); + } + + //[Fact(DisplayName = "二进制测试")] + //public async Task Info2Test() + //{ + // var buf = Rand.NextBytes(32); + + // var pk = await _Client.InvokeAsync("api/info2", buf); + // Assert.NotNull(pk); + // Assert.True(pk.Total > buf.Length); + // Assert.Equal(buf, pk.Slice(pk.Total - buf.Length, -1).ToArray()); + //} + + [Fact(DisplayName = "异常请求")] + public async Task ErrorTest() + { + var ex = await Assert.ThrowsAsync(() => _Client.InvokeAsync("api/info3")); - //[Fact(DisplayName = "二进制测试")] - //public async void Info2Test() - //{ - // var buf = Rand.NextBytes(32); + Assert.NotNull(ex); + Assert.Equal(404, ex.Code); + //Assert.True(ex.Message.EndsWith("无法找到名为[api/info3]的服务!")); + Assert.EndsWith("无法找到名为[api/info3]的服务!", ex.Message); + } + + [Theory(DisplayName = "令牌测试")] + [InlineData("12345678", "ABCDEFG")] + [InlineData("ABCDEFG", "12345678")] + public async Task TokenTest(String token, String state) + { + var client = new ApiHttpClient(_Address) { Token = token }; + var ac = client as IApiClient; + + var infs = await ac.InvokeAsync>("api/info", new { state }); + Assert.NotNull(infs); + Assert.Equal(token, infs["token"]); - // var pk = await _Client.InvokeAsync("api/info2", buf); - // Assert.NotNull(pk); - // Assert.True(pk.Total > buf.Length); - // Assert.Equal(buf, pk.Slice(pk.Total - buf.Length, -1).ToArray()); - //} + // 另一个客户端,共用令牌,应该可以拿到上一次状态数据 + var client2 = new ApiHttpClient(_Address) { Token = token }; - [Fact(DisplayName = "异常请求")] - public async void ErrorTest() + infs = await client2.GetAsync>("api/info"); + Assert.NotNull(infs); + //Assert.Equal(state, infs["LastState"]); + } + + [Fact] + public void SlaveTest() + { + var client = new ApiHttpClient("http://127.0.0.1:10000,http://127.0.0.1:20000," + _Address) { - var ex = await Assert.ThrowsAsync(() => _Client.InvokeAsync("api/info3")); + Timeout = 3_000 + }; + var ac = client as IApiClient; - Assert.NotNull(ex); - Assert.Equal(404, ex.Code); - //Assert.True(ex.Message.EndsWith("无法找到名为[api/info3]的服务!")); - Assert.EndsWith("无法找到名为[api/info3]的服务!", ex.Message); - } + var infs = ac.Invoke>("api/info"); + Assert.NotNull(infs); + } - [Theory(DisplayName = "令牌测试")] - [InlineData("12345678", "ABCDEFG")] - [InlineData("ABCDEFG", "12345678")] - public async void TokenTest(String token, String state) + [Fact] + public async Task SlaveAsyncTest() + { + var filter = new TokenHttpFilter { - var client = new ApiHttpClient(_Address) { Token = token }; - var ac = client as IApiClient; + UserName = "test", + Password = "", + }; + var client = new ApiHttpClient("http://127.0.0.1:10001,http://127.0.0.1:20001,http://star.newlifex.com:6600") + { + Filter = filter, + Timeout = 3_000 + }; + + var rs = await client.PostAsync("config/getall", new { appid = "starweb" }); + Assert.NotNull(rs); + + var ss = client.Services; + Assert.Equal(3, ss.Count); + Assert.Equal(1, ss[0].Times); + Assert.Equal(1, ss[0].Errors); + Assert.Equal(1, ss[1].Times); + Assert.Equal(1, ss[1].Errors); + Assert.Equal(1, ss[2].Times); + Assert.Equal(0, ss[2].Errors); + } - var infs = await ac.InvokeAsync>("api/info", new { state }); - Assert.NotNull(infs); - Assert.Equal(token, infs["token"]); + [Fact] + public async Task RoundRobinTest() + { + var client = new ApiHttpClient("test1=3*http://127.0.0.1:10000,test2=7*http://127.0.0.1:20000,") + { + RoundRobin = true, + Timeout = 3_000, + Log = XTrace.Log, + }; - // 另一个客户端,共用令牌,应该可以拿到上一次状态数据 - var client2 = new ApiHttpClient(_Address) { Token = token }; + Assert.Equal(2, client.Services.Count); - infs = await client2.GetAsync>("api/info"); - Assert.NotNull(infs); - //Assert.Equal(state, infs["LastState"]); - } + // 再加两个 + client.Add("test3", "2*" + _Address); + client.Add("test4", "1*" + _Address); + + Assert.Equal(4, client.Services.Count); - [Fact] - public void SlaveTest() { - var client = new ApiHttpClient("http://127.0.0.1:10000,http://127.0.0.1:20000," + _Address) - { - Timeout = 3_000 - }; - var ac = client as IApiClient; + var svc = client.Services[0]; + Assert.Equal("test1", svc.Name); + Assert.Equal(3, svc.Weight); + Assert.Equal("http://127.0.0.1:10000/", svc.Address + ""); + + svc = client.Services[1]; + Assert.Equal("test2", svc.Name); + Assert.Equal(7, svc.Weight); + Assert.Equal("http://127.0.0.1:20000/", svc.Address + ""); + + svc = client.Services[2]; + Assert.Equal("test3", svc.Name); + Assert.Equal(2, svc.Weight); + Assert.Equal(_Address + "/", svc.Address + ""); + } + + var ac = client as IApiClient; - var infs = ac.Invoke>("api/info"); + { + var infs = await ac.InvokeAsync>("api/info"); Assert.NotNull(infs); } - - [Fact] - public async void SlaveAsyncTest() { - var filter = new TokenHttpFilter - { - UserName = "test", - Password = "", - }; - var client = new ApiHttpClient("http://127.0.0.1:10001,http://127.0.0.1:20001,http://star.newlifex.com:6600") - { - Filter = filter, - Timeout = 3_000 - }; - - var rs = await client.PostAsync("config/getall", new { appid = "starweb" }); - Assert.NotNull(rs); - - var ss = client.Services; - Assert.Equal(3, ss.Count); - Assert.Equal(1, ss[0].Times); - Assert.Equal(1, ss[0].Errors); - Assert.Equal(1, ss[1].Times); - Assert.Equal(1, ss[1].Errors); - Assert.Equal(1, ss[2].Times); - Assert.Equal(0, ss[2].Errors); + var infs = await ac.InvokeAsync>("api/info"); + Assert.NotNull(infs); + } + { + var infs = await ac.InvokeAsync>("api/info"); + Assert.NotNull(infs); + } + { + var infs = await ac.InvokeAsync>("api/info"); + Assert.NotNull(infs); } - [Fact] - public async void RoundRobinTest() + // 判断结果 + { + var svc = client.Services[0]; + Assert.Null(svc.Client); + Assert.True(svc.NextTime > DateTime.Now.AddSeconds(55)); + Assert.Equal(1, svc.Times); + } { - var client = new ApiHttpClient("test1=3*http://127.0.0.1:10000,test2=7*http://127.0.0.1:20000,") - { - RoundRobin = true, - Timeout = 3_000, - Log = XTrace.Log, - }; - - Assert.Equal(2, client.Services.Count); - - // 再加两个 - client.Add("test3", "2*" + _Address); - client.Add("test4", "1*" + _Address); - - Assert.Equal(4, client.Services.Count); - - { - var svc = client.Services[0]; - Assert.Equal("test1", svc.Name); - Assert.Equal(3, svc.Weight); - Assert.Equal("http://127.0.0.1:10000/", svc.Address + ""); - - svc = client.Services[1]; - Assert.Equal("test2", svc.Name); - Assert.Equal(7, svc.Weight); - Assert.Equal("http://127.0.0.1:20000/", svc.Address + ""); - - svc = client.Services[2]; - Assert.Equal("test3", svc.Name); - Assert.Equal(2, svc.Weight); - Assert.Equal(_Address + "/", svc.Address + ""); - } - - var ac = client as IApiClient; - - { - var infs = await ac.InvokeAsync>("api/info"); - Assert.NotNull(infs); - } - { - var infs = await ac.InvokeAsync>("api/info"); - Assert.NotNull(infs); - } - { - var infs = await ac.InvokeAsync>("api/info"); - Assert.NotNull(infs); - } - { - var infs = await ac.InvokeAsync>("api/info"); - Assert.NotNull(infs); - } - - // 判断结果 - { - var svc = client.Services[0]; - Assert.Null(svc.Client); - Assert.True(svc.NextTime > DateTime.Now.AddSeconds(55)); - Assert.Equal(1, svc.Times); - } - { - var svc = client.Services[1]; - Assert.Null(svc.Client); - Assert.True(svc.NextTime > DateTime.Now.AddSeconds(55)); - Assert.Equal(1, svc.Times); - } - { - var svc = client.Services[2]; - Assert.NotNull(svc.Client); - Assert.True(svc.NextTime.Year < 2000); - Assert.Equal(3, svc.Times); - } - { - var svc = client.Services[3]; - Assert.NotNull(svc.Client); - Assert.True(svc.NextTime.Year < 2000); - Assert.Equal(1, svc.Times); - } + var svc = client.Services[1]; + Assert.Null(svc.Client); + Assert.True(svc.NextTime > DateTime.Now.AddSeconds(55)); + Assert.Equal(1, svc.Times); } + { + var svc = client.Services[2]; + Assert.NotNull(svc.Client); + Assert.True(svc.NextTime.Year < 2000); + Assert.Equal(3, svc.Times); + } + { + var svc = client.Services[3]; + Assert.NotNull(svc.Client); + Assert.True(svc.NextTime.Year < 2000); + Assert.Equal(1, svc.Times); + } + } - [Fact] - public async void FilterTest() + [Fact] + public async Task FilterTest() + { + var filter = new TokenHttpFilter { - var filter = new TokenHttpFilter - { - UserName = "test", - Password = "", - }; + UserName = "test", + Password = "", + }; - var client = new ApiHttpClient("http://star.newlifex.com:6600") - { - Filter = filter, + var client = new ApiHttpClient("http://star.newlifex.com:6600") + { + Filter = filter, - Log = XTrace.Log, - }; + Log = XTrace.Log, + }; - var rs = await client.PostAsync("config/getall", new { appid = "starweb" }); + var rs = await client.PostAsync("config/getall", new { appid = "starweb" }); - Assert.NotNull(rs); - Assert.NotNull(filter.Token); - } + Assert.NotNull(rs); + Assert.NotNull(filter.Token); } } \ No newline at end of file diff --git a/XUnitTest/ApiTest.cs b/XUnitTest/ApiTest.cs index e190b64..849830c 100644 --- a/XUnitTest/ApiTest.cs +++ b/XUnitTest/ApiTest.cs @@ -1,6 +1,7 @@ using System; using System.Collections.Generic; using System.Linq; +using System.Threading.Tasks; using NewLife; using NewLife.Caching; using NewLife.Data; @@ -58,7 +59,7 @@ public ApiTest() //[Order(1)] [Fact(DisplayName = "基础Api测试")] - public async void BasicTest() + public async Task BasicTest() { var apis = await _Client.InvokeAsync("api/all"); Assert.NotNull(apis); @@ -72,7 +73,7 @@ public async void BasicTest() [Theory(DisplayName = "参数测试")] [InlineData("12345678", "ABCDEFG")] [InlineData("ABCDEFG", "12345678")] - public async void InfoTest(String state, String state2) + public async Task InfoTest(String state, String state2) { var infs = await _Client.InvokeAsync>("api/info", new { state, state2 }); Assert.NotNull(infs); @@ -85,7 +86,7 @@ public async void InfoTest(String state, String state2) ////[Order(3)] //[Fact(DisplayName = "二进制测试")] - //public async void Info2Test() + //public async Task Info2Test() //{ // var buf = Rand.NextBytes(32); @@ -97,7 +98,7 @@ public async void InfoTest(String state, String state2) //[Order(4)] [Fact(DisplayName = "异常请求")] - public async void ErrorTest() + public async Task ErrorTest() { var ex = await Assert.ThrowsAsync(() => _Client.InvokeAsync("api/info3")); @@ -112,7 +113,7 @@ public async void ErrorTest() [Theory(DisplayName = "令牌测试")] [InlineData("12345678", "ABCDEFG")] [InlineData("ABCDEFG", "12345678")] - public async void TokenTest(String token, String state) + public async Task TokenTest(String token, String state) { var client = new ApiClient(_Uri) { @@ -137,11 +138,11 @@ public async void TokenTest(String token, String state) } [Fact] - public async void BigMessage() + public async Task BigMessage() { using var server = new ApiServer(12399); server.Log = XTrace.Log; - server.EncoderLog = XTrace.Log; + //server.EncoderLog = XTrace.Log; server.Register(); server.Start(); @@ -161,11 +162,11 @@ public async void BigMessage() } [Fact] - public async void BigMessage64k() + public async Task BigMessage64k() { using var server = new ApiServer(12399); server.Log = XTrace.Log; - server.EncoderLog = XTrace.Log; + //server.EncoderLog = XTrace.Log; server.Register(); server.Start(); @@ -246,7 +247,7 @@ class SPService } [Fact] - public async void SimpleType() + public async Task SimpleType() { using var server = new ApiServer(12377); server.Log = XTrace.Log; diff --git a/XUnitTest/XUnitTest.csproj b/XUnitTest/XUnitTest.csproj index d6e8fb4..6982851 100644 --- a/XUnitTest/XUnitTest.csproj +++ b/XUnitTest/XUnitTest.csproj @@ -12,10 +12,10 @@ - + - + all runtime; build; native; contentfiles; analyzers; buildtransitive