Skip to content

Commit

Permalink
Merge pull request #30 from liuhaoyang/master
Browse files Browse the repository at this point in the history
Update IgnoredRoutes_Tests
  • Loading branch information
liuhaoyang authored Feb 17, 2018
2 parents 5826dc9 + b39f8a2 commit 2b77181
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 6 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>netcoreapp2.0</TargetFramework>
<IsPackable>false</IsPackable>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="15.3.0-preview-20170628-02" />
<PackageReference Include="NSubstitute" Version="3.1.0" />
<PackageReference Include="xunit" Version="2.2.0" />
<PackageReference Include="xunit.runner.visualstudio" Version="2.2.0" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\..\src\Butterfly.Client.AspNetCore\Butterfly.Client.AspNetCore.csproj" />
</ItemGroup>
</Project>
24 changes: 18 additions & 6 deletions test/Butterfly.Client.AspNetCore.Tests/IgnoredRoutes_Tests.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System.Text.RegularExpressions;
using System.Linq;
using System.Text.RegularExpressions;
using Xunit;

namespace Butterfly.Client.AspNetCore.Tests
Expand All @@ -18,12 +19,23 @@ public void IgnoredRoutes_Test()
public void IgnoredRoutes_Regex_Test()
{
var config = new ButterflyConfig();
config.IgnoredRoutesRegexPatterns = new string[] {"[home]"};
var routes = new string[] {"/home/index", "/user/about"};
var result = Regex.IsMatch(config.IgnoredRoutesRegexPatterns[0], routes[0]);
config.IgnoredRoutesRegexPatterns = new string[] {"/status"};
var routes = new string[] {"/status", "/administration/status"};
var result = IsMatch(config.IgnoredRoutesRegexPatterns, routes[0]);
Assert.True(result);
result = Regex.IsMatch(config.IgnoredRoutesRegexPatterns[0], routes[1]);
Assert.False(result);
result = result = IsMatch(config.IgnoredRoutesRegexPatterns, routes[1]);
Assert.True(result);
}

private bool IsMatch(string[] patterns, string path)
{
if (patterns == null || patterns.Any(x => Regex.IsMatch(path, x)))
{
return true;
}

return false;
}

}
}

0 comments on commit 2b77181

Please sign in to comment.