Added unit test project. Improved route matcher and fixed bugs.

This commit is contained in:
2022-03-03 00:18:45 -08:00
parent 16c42c1ef7
commit da8184f152
5 changed files with 238 additions and 69 deletions

View File

@ -0,0 +1,25 @@

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio Version 17
VisualStudioVersion = 17.0.32112.339
MinimumVisualStudioVersion = 10.0.40219.1
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Rest.Net.Tests", "Rest.Net.Tests\Rest.Net.Tests.csproj", "{729431C7-DA13-4668-9D6A-C785C5AB4064}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Release|Any CPU = Release|Any CPU
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{729431C7-DA13-4668-9D6A-C785C5AB4064}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{729431C7-DA13-4668-9D6A-C785C5AB4064}.Debug|Any CPU.Build.0 = Debug|Any CPU
{729431C7-DA13-4668-9D6A-C785C5AB4064}.Release|Any CPU.ActiveCfg = Release|Any CPU
{729431C7-DA13-4668-9D6A-C785C5AB4064}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {0DB589F0-19C2-46AC-9CAB-903F66E22B52}
EndGlobalSection
EndGlobal

View File

@ -0,0 +1,30 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>net6.0</TargetFramework>
<Nullable>enable</Nullable>
<IsPackable>false</IsPackable>
<AssemblyName>MontoyaTech.Rest.Net.Tests</AssemblyName>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="FluentAssertions" Version="6.5.1" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="16.11.0" />
<PackageReference Include="xunit" Version="2.4.1" />
<PackageReference Include="xunit.runner.visualstudio" Version="2.4.3">
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
<PrivateAssets>all</PrivateAssets>
</PackageReference>
<PackageReference Include="coverlet.collector" Version="3.1.0">
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
<PrivateAssets>all</PrivateAssets>
</PackageReference>
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\..\Rest.Net\Rest.Net\Rest.Net.csproj" />
</ItemGroup>
</Project>

View File

@ -0,0 +1,104 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using FluentAssertions;
using Xunit;
namespace MontoyaTech.Rest.Net.Tests
{
public class RouteMatcherTests
{
[Fact]
public void SyntaxWithRootShouldMatch()
{
RouteMatcher.Matches("http://localhost/", "/", out _).Should().BeTrue();
}
[Fact]
public void SyntaxWithRootCatchAllShouldMatch()
{
RouteMatcher.Matches("http://localhost/test1/test2", "/**", out _).Should().BeTrue();
}
[Fact]
public void SyntaxWithRootWildcardShouldMatch()
{
RouteMatcher.Matches("http://localhost/test1", "/*", out _).Should().BeTrue();
}
[Fact]
public void SyntaxWithRootWildcardShouldNotMatch()
{
RouteMatcher.Matches("http://localhost/test1/test2", "/*", out _).Should().BeFalse();
}
[Fact]
public void SyntaxWithRootNotShouldNotMatch()
{
RouteMatcher.Matches("http://localhost/test1", "/!test1", out _).Should().BeFalse();
}
[Fact]
public void SyntaxWithRootNotShouldMatch()
{
RouteMatcher.Matches("http://localhost/test2", "/!test1", out _).Should().BeTrue();
}
[Fact]
public void SyntaxWithArgumentShouldNotMatch()
{
RouteMatcher.Matches("http://localhost/test1/test2", "/{a}", out _).Should().BeFalse();
}
[Fact]
public void SyntaxWithArgumentShouldMatch()
{
RouteMatcher.Matches("http://localhost/test1", "/{a}", out _).Should().BeTrue();
}
[Fact]
public void SyntaxWithWildcardShouldMatch()
{
RouteMatcher.Matches("http://localhost/1/2/3", "/1/*/3", out _).Should().BeTrue();
}
[Fact]
public void SyntaxWithOrShouldMatch()
{
RouteMatcher.Matches("http://localhost/a/b", "/a/b|c", out _).Should().BeTrue();
RouteMatcher.Matches("http://localhost/a/c", "/a/b|c", out _).Should().BeTrue();
}
[Fact]
public void SyntaxWithOrShouldNotMatch()
{
RouteMatcher.Matches("http://localhost/a/d", "/a/b|c", out _).Should().BeFalse();
}
[Fact]
public void SyntaxWithNotAndShouldMatch()
{
RouteMatcher.Matches("http://localhost/a/d", "/a/!b&!c", out _).Should().BeTrue();
}
[Fact]
public void SyntaxWithNotAndShouldNotMatch()
{
RouteMatcher.Matches("http://localhost/a/b", "/a/!b&!c", out _).Should().BeFalse();
}
[Fact]
public void SyntaxWithSegmentShouldMatch()
{
RouteMatcher.Matches("http://localhost/a", "/a", out _).Should().BeTrue();
}
[Fact]
public void SyntaxWithMultipleSegmentsShouldMatch()
{
RouteMatcher.Matches("http://localhost/a/b/c", "/a/b/c", out _).Should().BeTrue();
}
}
}