Skip to content

Commit

Permalink
新增 Bing.AspNetCore 功能模块
Browse files Browse the repository at this point in the history
  • Loading branch information
jianxuanbing committed Feb 21, 2019
1 parent c165b9b commit f836a97
Show file tree
Hide file tree
Showing 8 changed files with 262 additions and 10 deletions.
11 changes: 9 additions & 2 deletions Bing.NetCore.sln
Original file line number Diff line number Diff line change
Expand Up @@ -212,11 +212,13 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Bing.Datas.Test.Integration
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "11-Mapping", "11-Mapping", "{6A3D8548-25CE-45E4-AFC7-86779FCF39B4}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Bing.AutoMapper", "src\Bing.AutoMapper\Bing.AutoMapper.csproj", "{24789049-0DA9-4B9C-B67B-410750FC56A7}"
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Bing.AutoMapper", "src\Bing.AutoMapper\Bing.AutoMapper.csproj", "{24789049-0DA9-4B9C-B67B-410750FC56A7}"
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "11-Mapping", "11-Mapping", "{BA03F576-3C03-4F4A-AB8A-F36AAC0096BB}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Bing.AutoMapper.Tests", "tests\Bing.AutoMapper.Tests\Bing.AutoMapper.Tests.csproj", "{C4A33092-EA55-40C1-B8C8-A5398B3A0053}"
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Bing.AutoMapper.Tests", "tests\Bing.AutoMapper.Tests\Bing.AutoMapper.Tests.csproj", "{C4A33092-EA55-40C1-B8C8-A5398B3A0053}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Bing.AspNetCore", "src\Bing.AspNetCore\Bing.AspNetCore.csproj", "{BA1A1ED0-1659-4EDE-8398-6AF4D8F0F876}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Expand Down Expand Up @@ -492,6 +494,10 @@ Global
{C4A33092-EA55-40C1-B8C8-A5398B3A0053}.Debug|Any CPU.Build.0 = Debug|Any CPU
{C4A33092-EA55-40C1-B8C8-A5398B3A0053}.Release|Any CPU.ActiveCfg = Release|Any CPU
{C4A33092-EA55-40C1-B8C8-A5398B3A0053}.Release|Any CPU.Build.0 = Release|Any CPU
{BA1A1ED0-1659-4EDE-8398-6AF4D8F0F876}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{BA1A1ED0-1659-4EDE-8398-6AF4D8F0F876}.Debug|Any CPU.Build.0 = Debug|Any CPU
{BA1A1ED0-1659-4EDE-8398-6AF4D8F0F876}.Release|Any CPU.ActiveCfg = Release|Any CPU
{BA1A1ED0-1659-4EDE-8398-6AF4D8F0F876}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
Expand Down Expand Up @@ -598,6 +604,7 @@ Global
{24789049-0DA9-4B9C-B67B-410750FC56A7} = {6A3D8548-25CE-45E4-AFC7-86779FCF39B4}
{BA03F576-3C03-4F4A-AB8A-F36AAC0096BB} = {77209C11-A719-45C3-9C49-27FA702503A1}
{C4A33092-EA55-40C1-B8C8-A5398B3A0053} = {BA03F576-3C03-4F4A-AB8A-F36AAC0096BB}
{BA1A1ED0-1659-4EDE-8398-6AF4D8F0F876} = {0AF1076E-5001-4F92-A564-4E47E9C88ACE}
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {82408448-62DC-44A6-B7C1-6FCEBCC12C93}
Expand Down
22 changes: 22 additions & 0 deletions src/Bing.AspNetCore/Bing.AspNetCore.csproj
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>
18 changes: 18 additions & 0 deletions src/Bing.AspNetCore/IMiddleware.cs
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);
}
}
34 changes: 34 additions & 0 deletions src/Bing.AspNetCore/IVerifyCodeService.cs
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);
}
}
1 change: 0 additions & 1 deletion src/Bing/Dependency/Bootstrapper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
using System.Reflection;
using AspectCore.Configuration;
using Autofac;
using Bing.Contexts;
using Bing.Events.Handlers;
using Bing.Helpers;
using Bing.Reflections;
Expand Down
6 changes: 1 addition & 5 deletions src/Bing/Reflections/WebAppTypeFinder.cs
Original file line number Diff line number Diff line change
@@ -1,8 +1,4 @@
using System;
using System.Text;
using Microsoft.Extensions.PlatformAbstractions;

namespace Bing.Reflections
namespace Bing.Reflections
{
/// <summary>
/// Web应用类型查找器
Expand Down
4 changes: 2 additions & 2 deletions tests/Bing.AutoMapper.Tests/MapTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ public void Test_MapTo_MultipleThread()
/// 测试忽略特性
/// </summary>
[Fact]
public void TestMapTo_Ignore()
public void Test_MapTo_Ignore()
{
DtoSample sample2 = new DtoSample { Name = "a", IgnoreValue = "b" };
EntitySample sample = sample2.MapTo<EntitySample>();
Expand All @@ -140,7 +140,7 @@ public void TestMapTo_Ignore()
/// 测试Castle代理类
/// </summary>
[Fact]
public void TestMapTo_CastleProxy()
public void Test_MapTo_CastleProxy()
{
Castle.DynamicProxy.ProxyGenerator proxyGenerator = new Castle.DynamicProxy.ProxyGenerator();
var proxy = proxyGenerator.CreateClassProxy<DtoSample>();
Expand Down
176 changes: 176 additions & 0 deletions tests/Bing.Tests/Reflections/FinderTest.cs
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>
{
}
}

0 comments on commit f836a97

Please sign in to comment.