forked from bing-framework/Bing.NetCore
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
c165b9b
commit f836a97
Showing
8 changed files
with
262 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
<Project Sdk="Microsoft.NET.Sdk"> | ||
<Import Project="../../build/version.props"></Import> | ||
<PropertyGroup> | ||
<TargetFramework>netstandard2.0</TargetFramework> | ||
<Description>Bing.AspNetCore 组件,提供AspNetCore的服务端功能的封装</Description> | ||
</PropertyGroup> | ||
|
||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|AnyCPU'"> | ||
<OutputPath>..\..\output\release\</OutputPath> | ||
<DocumentationFile>..\..\output\release\netstandard2.0\Bing.AspNetCore.xml</DocumentationFile> | ||
</PropertyGroup> | ||
|
||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|AnyCPU'"> | ||
<OutputPath>..\..\output\release\</OutputPath> | ||
<DocumentationFile>..\..\output\release\netstandard2.0\Bing.AspNetCore.xml</DocumentationFile> | ||
</PropertyGroup> | ||
|
||
<ItemGroup> | ||
<ProjectReference Include="..\Bing\Bing.csproj" /> | ||
</ItemGroup> | ||
|
||
</Project> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
using System.Threading.Tasks; | ||
using Microsoft.AspNetCore.Http; | ||
|
||
namespace Bing.AspNetCore | ||
{ | ||
/// <summary> | ||
/// 定义AspNetCore中间件 | ||
/// </summary> | ||
public interface IMiddleware | ||
{ | ||
/// <summary> | ||
/// 执行中间件拦截逻辑 | ||
/// </summary> | ||
/// <param name="context">Http上下文</param> | ||
/// <returns></returns> | ||
Task Invoke(HttpContext context); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
using System.Drawing; | ||
|
||
namespace Bing.AspNetCore | ||
{ | ||
/// <summary> | ||
/// 验证码服务 | ||
/// </summary> | ||
public interface IVerifyCodeService | ||
{ | ||
/// <summary> | ||
/// 校验验证码有效性 | ||
/// </summary> | ||
/// <param name="code">验证码</param> | ||
/// <param name="id">验证码编号</param> | ||
/// <param name="removeIfSuccess">验证成功时是否移除</param> | ||
/// <returns></returns> | ||
bool CheckCode(string code, string id, bool removeIfSuccess = true); | ||
|
||
/// <summary> | ||
/// 设置验证码到Session中 | ||
/// </summary> | ||
/// <param name="code">验证码</param> | ||
/// <param name="id">验证码编号</param> | ||
void SetCode(string code, out string id); | ||
|
||
/// <summary> | ||
/// 将图片序列化成字符串 | ||
/// </summary> | ||
/// <param name="image">图片</param> | ||
/// <param name="id">验证码编号</param> | ||
/// <returns></returns> | ||
string GetImageString(Image image, string id); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,176 @@ | ||
using Bing.Reflections; | ||
using Xunit; | ||
using Xunit.Abstractions; | ||
|
||
namespace Bing.Tests.Reflections | ||
{ | ||
/// <summary> | ||
/// 类型查找器测试 | ||
/// </summary> | ||
public class FinderTest:TestBase | ||
{ | ||
/// <summary> | ||
/// 类型查找器 | ||
/// </summary> | ||
private readonly ITypeFinder _finder; | ||
|
||
/// <summary> | ||
/// 初始化一个<see cref="FinderTest"/>类型的实例 | ||
/// </summary> | ||
public FinderTest(ITestOutputHelper output) : base(output) | ||
{ | ||
_finder = new AppDomainTypeFinder(); | ||
} | ||
|
||
/// <summary> | ||
/// 查找类型集合 | ||
/// </summary> | ||
[Fact] | ||
public void Test_Find() | ||
{ | ||
var types = _finder.Find<IA>(); | ||
Assert.Single(types); | ||
Assert.Equal(typeof(A), types[0]); | ||
} | ||
|
||
/// <summary> | ||
/// 查找类型集合 | ||
/// </summary> | ||
[Fact] | ||
public void Test_Find_2() | ||
{ | ||
var types = _finder.Find<IB>(); | ||
Assert.Equal(2, types.Count); | ||
Assert.Equal(typeof(A), types[0]); | ||
Assert.Equal(typeof(B), types[1]); | ||
} | ||
|
||
/// <summary> | ||
/// 查找的结果类型包含泛型 | ||
/// </summary> | ||
[Fact] | ||
public void Test_Find_3() | ||
{ | ||
var types = _finder.Find<IC>(); | ||
Assert.Equal(2, types.Count); | ||
Assert.Equal(typeof(B), types[0]); | ||
Assert.Equal(typeof(D<>), types[1]); | ||
} | ||
|
||
/// <summary> | ||
/// 查找泛型类型 | ||
/// </summary> | ||
[Fact] | ||
public void Test_Find_4() | ||
{ | ||
var types = _finder.Find<IG<E>>(); | ||
Assert.Single(types); | ||
Assert.Equal(typeof(E), types[0]); | ||
} | ||
|
||
/// <summary> | ||
/// 查找泛型类型 | ||
/// </summary> | ||
[Fact] | ||
public void Test_Find_5() | ||
{ | ||
var types = _finder.Find(typeof(IG<>)); | ||
Assert.Equal(2, types.Count); | ||
Assert.Equal(typeof(E), types[0]); | ||
Assert.Equal(typeof(F2<>), types[1]); | ||
} | ||
|
||
/// <summary> | ||
/// 测试并发 | ||
/// </summary> | ||
[Fact] | ||
public void Test_Find_6() | ||
{ | ||
Bing.Utils.Helpers.Thread.ParallelExecute(() => { | ||
var types = _finder.Find<IA>(); | ||
Assert.Single(types); | ||
Assert.Equal(typeof(A), types[0]); | ||
}, () => { | ||
var types = _finder.Find<IB>(); | ||
Assert.Equal(2, types.Count); | ||
Assert.Equal(typeof(A), types[0]); | ||
Assert.Equal(typeof(B), types[1]); | ||
}, () => { | ||
var types = _finder.Find<IC>(); | ||
Assert.Equal(2, types.Count); | ||
Assert.Equal(typeof(B), types[0]); | ||
Assert.Equal(typeof(D<>), types[1]); | ||
}); | ||
} | ||
} | ||
|
||
/// <summary> | ||
/// 测试查找接口 | ||
/// </summary> | ||
public interface IA | ||
{ | ||
} | ||
|
||
/// <summary> | ||
/// 测试类型 | ||
/// </summary> | ||
public class A : IA, IB | ||
{ | ||
} | ||
|
||
/// <summary> | ||
/// 测试查找接口 | ||
/// </summary> | ||
public interface IB | ||
{ | ||
} | ||
|
||
/// <summary> | ||
/// 测试类型 | ||
/// </summary> | ||
public class B : IB, IC | ||
{ | ||
} | ||
|
||
/// <summary> | ||
/// 测试类型 | ||
/// </summary> | ||
public abstract class C : IB, IC | ||
{ | ||
} | ||
|
||
/// <summary> | ||
/// 测试查找接口 | ||
/// </summary> | ||
public interface IC | ||
{ | ||
} | ||
|
||
/// <summary> | ||
/// 测试类型 | ||
/// </summary> | ||
public class D<T> : IC | ||
{ | ||
} | ||
|
||
/// <summary> | ||
/// 测试查找接口 | ||
/// </summary> | ||
public interface IG<T> | ||
{ | ||
} | ||
|
||
/// <summary> | ||
/// 测试类型 | ||
/// </summary> | ||
public class E : IG<E> | ||
{ | ||
} | ||
|
||
/// <summary> | ||
/// 测试类型 | ||
/// </summary> | ||
public class F2<T> : IG<T> | ||
{ | ||
} | ||
} |