Files
WireMock.Net/src/WireMock.Net.Abstractions/Extensions/RequestModelExtensions.cs
Stef Heyenrath 54edf0bebc Add link to TIOBE Index on main page + fix issues (#1137)
* Add TIOBE + include SonarAnalyzer.CSharp

* .

* cp

* Copyright © WireMock.Net

* more fixes

* fix

* xpath

* if (Matchers == null || !Matchers.Any())

* if (Matchers != null)

* ?

* .

* .
2024-07-18 18:06:04 +02:00

31 lines
700 B
C#

// Copyright © WireMock.Net
using System.Linq;
using WireMock.Admin.Mappings;
namespace WireMock.Extensions;
public static class RequestModelExtensions
{
public static string? GetPathAsString(this RequestModel request)
{
var path = request.Path switch
{
string pathAsString => pathAsString,
PathModel pathModel => pathModel.Matchers?.FirstOrDefault()?.Pattern as string,
_ => null
};
return FixPath(path);
}
private static string? FixPath(string? path)
{
if (string.IsNullOrEmpty(path))
{
return path;
}
return path!.StartsWith("/") ? path : $"/{path}";
}
}