Skip to content

Commit

Permalink
Fix tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Kaliumhexacyanoferrat committed Oct 15, 2024
1 parent d8debf9 commit 206b0a2
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 6 deletions.
6 changes: 3 additions & 3 deletions Modules/Controllers/Provider/ControllerHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -60,18 +60,18 @@ private IEnumerable<Func<IHandler, MethodHandler>> AnalyzeMethods(Type type, Ser

private static Operation CreateOperation(MethodInfo method, List<string> arguments)
{
var pathArguments = string.Join('/', arguments.Select(a => "{" + a + "}"));
var pathArguments = string.Join('/', arguments.Select(a => $":{a}"));

if (method.Name == "Index")
{
return OperationBuilder.Create(pathArguments.Length > 0 ? $"/{pathArguments}/" : null, method);
return OperationBuilder.Create(pathArguments.Length > 0 ? $"/{pathArguments}/" : null, method, true);
}

var name = HypenCase(method.Name);

var path = $"/{name}";

return OperationBuilder.Create(pathArguments.Length > 0 ? $"{path}/{pathArguments}" : $"{path}/", method);
return OperationBuilder.Create(pathArguments.Length > 0 ? $"{path}/{pathArguments}/" : $"{path}/", method, true);
}

private List<string> FindPathArguments(MethodInfo method)
Expand Down
5 changes: 3 additions & 2 deletions Modules/Reflection/Operations/OperationBuilder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ public static partial class OperationBuilder

#region Functionality

public static Operation Create(string? definition, MethodInfo method)
public static Operation Create(string? definition, MethodInfo method, bool forceTrailingSlash = false)
{
var isWildcard = CheckWildcardRoute(method.ReturnType);

Expand Down Expand Up @@ -49,7 +49,8 @@ public static Operation Create(string? definition, MethodInfo method)
nameBuilder.Replace(match.Value, "{" + match.Groups[1].Value + "}");
}

var end = isWildcard ? "(/|)" : "(/|)$";
var end = forceTrailingSlash ? "/" : "(/|)";
end = isWildcard ? end : $"{end}$";

var matcher = new Regex($"^/{matchBuilder}{end}", RegexOptions.Compiled);

Expand Down
2 changes: 1 addition & 1 deletion Testing/Acceptance/Modules/Controllers/ActionTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ public sealed class Model
public sealed class TestController
{

public IHandlerBuilder Index() => Content.From(Resource.FromString("Hello World!"));
public string Index() => "Hello World!";

public IHandlerBuilder Action(int? query) => Content.From(Resource.FromString(query?.ToString() ?? "Action"));

Expand Down

0 comments on commit 206b0a2

Please sign in to comment.