Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

添加 MessageHandler 正则表达式的单元测试 #2651

Merged
merged 1 commit into from
May 26, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -245,6 +245,27 @@ public void SyncTest()
Assert.AreEqual(messageHandlers1.GlobalMessageContext.GetHashCode(), messageHandlers2.GlobalMessageContext.GetHashCode());
}

[TestMethod]
public void RegexTest()
{
string regexXmlText = @"<?xml version=""1.0"" encoding=""utf-8""?>
<xml>
<ToUserName><![CDATA[gh_a96a4a619366]]></ToUserName>
<FromUserName><![CDATA[olPjZjsXuQPJoV0HlruZkNzKc91E]]></FromUserName>
<CreateTime>1357986928</CreateTime>
<MsgType><![CDATA[text]]></MsgType>
<Content><![CDATA[13987654321]]></Content>
<MsgId>5832509444155992351</MsgId>
</xml>
";
var messageHandler = new CustomMessageHandlers(XDocument.Parse(regexXmlText));
messageHandler.DefaultMessageHandlerAsyncEvent = NeuChar.MessageHandlers.DefaultMessageHandlerAsyncEvent.SelfSynicMethod;
messageHandler.ExecuteAsync(new CancellationToken()).GetAwaiter().GetResult();
Assert.IsNotNull(messageHandler.ResponseMessage);
Assert.IsInstanceOfType(messageHandler.ResponseMessage, typeof(ResponseMessageText));
Console.WriteLine(messageHandler.ResponseMessage.ToJson(true));
}

[TestMethod]
public void ContextTest()
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,11 +44,11 @@ public override IResponseMessageBase OnTextRequest(RequestMessageText requestMes


var requestHandler = requestMessage.StartHandler();
requestHandler.Keyword("代理", () =>
{
responseMessage.Content = "收到关键字:代理";
return responseMessage;
})
requestHandler.Keyword("代理", () =>
{
responseMessage.Content = "收到关键字:代理";
return responseMessage;
})
.SelectMenuKeyword("101", () =>
{
responseMessage.Content = $"选择菜单:{requestMessage.bizmsgmenuid},文字:{requestMessage.Content}";
Expand All @@ -59,6 +59,11 @@ public override IResponseMessageBase OnTextRequest(RequestMessageText requestMes
responseMessage.Content = $"选择菜单:{requestMessage.bizmsgmenuid},文字:{requestMessage.Content}";
return responseMessage;
})
.Regex("^[1][3-9]{1}[0-9]{9}$", () =>
{
responseMessage.Content = $"正则:{requestMessage.Content}";
return responseMessage;
})
.Default(() =>
{
responseMessage.Content = "文字信息";
Expand Down
Original file line number Diff line number Diff line change
@@ -1,29 +1,29 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFrameworks>net462;netstandard2.0;netstandard2.1</TargetFrameworks>
<FrameworkPathOverride Condition="'$(TargetFramework)' == 'net35'">$(Net35FrameworkPathOverride)</FrameworkPathOverride>
<Version>3.15.4-beta3</Version>
<LangVersion>10.0</LangVersion>
<AssemblyName>Senparc.Weixin.Work</AssemblyName>
<RootNamespace>Senparc.Weixin.Work</RootNamespace>
<GeneratePackageOnBuild Condition=" '$(Configuration)' == 'Release' ">true</GeneratePackageOnBuild>
<Description>
<PropertyGroup>
<TargetFrameworks>net462;netstandard2.0;netstandard2.1</TargetFrameworks>
<FrameworkPathOverride Condition="'$(TargetFramework)' == 'net35'">$(Net35FrameworkPathOverride)</FrameworkPathOverride>
<Version>3.15.4-beta3</Version>
<LangVersion>10.0</LangVersion>
<AssemblyName>Senparc.Weixin.Work</AssemblyName>
<RootNamespace>Senparc.Weixin.Work</RootNamespace>
<GeneratePackageOnBuild Condition=" '$(Configuration)' == 'Release' ">true</GeneratePackageOnBuild>
<Description>
微信 SDK - 企业微信 模块

Senparc.Weixin SDK 开源项目:
https://github.com/JeffreySu/WeiXinMPSDK
</Description>
<Copyright>Senparc Copyright © 2004~2022</Copyright>
<PackageTags>微信,weixin,公众号,企业微信,WeChat,Senparc,盛派,SDK,C#,JSSDK,微信支付,分布式,小程序,企业号</PackageTags>
<Authors>Jeffrey Su</Authors>
<Owners>Senparc</Owners>
<PackageLicenseExpression>Apache-2.0</PackageLicenseExpression>
<ProjectUrl>https://github.com/JeffreySu/WeiXinMPSDK</ProjectUrl>
<Title>Senparc.Weixin.Work.dll</Title>
<Summary>微信公众号SDK for C#</Summary>
<PackageProjectUrl>https://github.com/JeffreySu/WeiXinMPSDK</PackageProjectUrl>
<PackageIcon>icon.jpg</PackageIcon>
<PackageReleaseNotes>
<Copyright>Senparc Copyright © 2004~2022</Copyright>
<PackageTags>微信,weixin,公众号,企业微信,WeChat,Senparc,盛派,SDK,C#,JSSDK,微信支付,分布式,小程序,企业号</PackageTags>
<Authors>Jeffrey Su</Authors>
<Owners>Senparc</Owners>
<PackageLicenseExpression>Apache-2.0</PackageLicenseExpression>
<ProjectUrl>https://github.com/JeffreySu/WeiXinMPSDK</ProjectUrl>
<Title>Senparc.Weixin.Work.dll</Title>
<Summary>微信公众号SDK for C#</Summary>
<PackageProjectUrl>https://github.com/JeffreySu/WeiXinMPSDK</PackageProjectUrl>
<PackageIcon>icon.jpg</PackageIcon>
<PackageReleaseNotes>
v0.1.0 完成从Senparc.Weixin.Work.dll的初步移植,添加Work(企业微信)中的新接口

v0.2.0 1、整理类名,MessageHandler跑通
Expand Down Expand Up @@ -173,66 +173,66 @@
v3.14.3 修正“批量获取客户详情”接口传入参数
v3.14.6 添加“审批申请状态变化回调通知”接口
v3.14.7 添加“自建应用&gt;审批流程引擎”接口及 Sample
v3.14.8 为 JsApiTicket 提供 IsAgentConfig 参数
v3.14.10 添加异步方法
v3.14.11 优化OAuth相关接口
v3.15.1 修复 LoginCheckResultJson 缺少 open_userid
v3.15.2 添加“用户标签管理”接口
v3.15.4 添加 MailList.Member 下的 biz_mail 属性
</PackageReleaseNotes>
<RepositoryUrl>https://github.com/JeffreySu/WeiXinMPSDK</RepositoryUrl>
<SignAssembly>False</SignAssembly>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)' == 'Release' ">
<OutputPath>..\..\BuildOutPut</OutputPath>
<DefineConstants>$(DefineConstants);RELEASE</DefineConstants>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Release|x86'">
<OutputPath>..\..\BuildOutPut</OutputPath>
<DefineConstants>$(DefineConstants);RELEASE</DefineConstants>
<DocumentationFile>..\..\BuildOutPut\Senparc.Weixin.Work.XML</DocumentationFile>
<Optimize>true</Optimize>
<DebugType>pdbonly</DebugType>
<ErrorReport>prompt</ErrorReport>
<CodeAnalysisRuleSet>MinimumRecommendedRules.ruleset</CodeAnalysisRuleSet>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(TargetFramework)|$(Platform)'=='Release|net462|AnyCPU'">
<OutputPath>..\..\BuildOutPut\</OutputPath>
<DocumentationFile>..\..\BuildOutPut\net462\Senparc.Weixin.Work.xml</DocumentationFile>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(TargetFramework)|$(Platform)'=='Release|netstandard2.0|AnyCPU'">
<OutputPath>..\..\BuildOutPut\</OutputPath>
<DocumentationFile>..\..\BuildOutPut\netstandard2.0\Senparc.Weixin.Work.xml</DocumentationFile>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(TargetFramework)|$(Platform)'=='Release|netstandard2.1|AnyCPU'">
<OutputPath>..\..\BuildOutPut\</OutputPath>
<DocumentationFile>..\..\BuildOutPut\netstandard2.1\Senparc.Weixin.Work.xml</DocumentationFile>
</PropertyGroup>
<ItemGroup>
<None Include="..\..\Senparc.Weixin\icon.jpg" Pack="true" Visible="false" PackagePath="" />
</ItemGroup>
<ItemGroup Condition=" '$(TargetFramework)' == 'net462' ">
<Reference Include="System.Core" />
<Reference Include="System.Data" />
<Reference Include="System.Data.DataSetExtensions" />
<Reference Include="System.Net.Http" />
<Reference Include="System.Runtime.Serialization" />
<Reference Include="System.Web" />
<Reference Include="System.Web.Extensions" />
<Reference Include="System.Xml" />
<Reference Include="System.Xml.Linq" />
</ItemGroup>
<ItemGroup Condition=" '$(TargetFramework)' != 'net462' ">
<PackageReference Include="System.Xml.XmlDocument" Version="4.3.0" />
<PackageReference Include="System.Xml.XPath.XmlDocument" Version="4.3.0" />
</ItemGroup>
<ItemGroup>
<PackageReference Include="Senparc.NeuChar" Version="2.1.1.1" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\..\Senparc.Weixin\Senparc.Weixin\Senparc.Weixin.net6.csproj" />
</ItemGroup>
<ItemGroup>
<PackageReference Update="Microsoft.SourceLink.GitHub" Version="1.1.1" />
</ItemGroup>
v3.14.8 为 JsApiTicket 提供 IsAgentConfig 参数
v3.14.10 添加异步方法
v3.14.11 优化OAuth相关接口
v3.15.1 修复 LoginCheckResultJson 缺少 open_userid
v3.15.2 添加“用户标签管理”接口
v3.15.4 添加 MailList.Member 下的 biz_mail 属性
</PackageReleaseNotes>
<RepositoryUrl>https://github.com/JeffreySu/WeiXinMPSDK</RepositoryUrl>
<SignAssembly>False</SignAssembly>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)' == 'Release' ">
<OutputPath>..\..\BuildOutPut</OutputPath>
<DefineConstants>$(DefineConstants);RELEASE</DefineConstants>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Release|x86'">
<OutputPath>..\..\BuildOutPut</OutputPath>
<DefineConstants>$(DefineConstants);RELEASE</DefineConstants>
<DocumentationFile>..\..\BuildOutPut\Senparc.Weixin.Work.XML</DocumentationFile>
<Optimize>true</Optimize>
<DebugType>pdbonly</DebugType>
<ErrorReport>prompt</ErrorReport>
<CodeAnalysisRuleSet>MinimumRecommendedRules.ruleset</CodeAnalysisRuleSet>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(TargetFramework)|$(Platform)'=='Release|net462|AnyCPU'">
<OutputPath>..\..\BuildOutPut\</OutputPath>
<DocumentationFile>..\..\BuildOutPut\net462\Senparc.Weixin.Work.xml</DocumentationFile>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(TargetFramework)|$(Platform)'=='Release|netstandard2.0|AnyCPU'">
<OutputPath>..\..\BuildOutPut\</OutputPath>
<DocumentationFile>..\..\BuildOutPut\netstandard2.0\Senparc.Weixin.Work.xml</DocumentationFile>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(TargetFramework)|$(Platform)'=='Release|netstandard2.1|AnyCPU'">
<OutputPath>..\..\BuildOutPut\</OutputPath>
<DocumentationFile>..\..\BuildOutPut\netstandard2.1\Senparc.Weixin.Work.xml</DocumentationFile>
</PropertyGroup>
<ItemGroup>
<None Include="..\..\Senparc.Weixin\icon.jpg" Pack="true" Visible="false" PackagePath="" />
</ItemGroup>
<ItemGroup Condition=" '$(TargetFramework)' == 'net462' ">
<Reference Include="System.Core" />
<Reference Include="System.Data" />
<Reference Include="System.Data.DataSetExtensions" />
<Reference Include="System.Net.Http" />
<Reference Include="System.Runtime.Serialization" />
<Reference Include="System.Web" />
<Reference Include="System.Web.Extensions" />
<Reference Include="System.Xml" />
<Reference Include="System.Xml.Linq" />
</ItemGroup>
<ItemGroup Condition=" '$(TargetFramework)' != 'net462' ">
<PackageReference Include="System.Xml.XmlDocument" Version="4.3.0" />
<PackageReference Include="System.Xml.XPath.XmlDocument" Version="4.3.0" />
</ItemGroup>
<ItemGroup>
<PackageReference Include="Senparc.NeuChar" Version="2.1.1.1" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\..\Senparc.Weixin\Senparc.Weixin\Senparc.Weixin.net6.csproj" />
</ItemGroup>
<ItemGroup>
<PackageReference Update="Microsoft.SourceLink.GitHub" Version="1.1.1" />
</ItemGroup>
</Project>