mirror of
https://github.com/wiremock/WireMock.Net.git
synced 2026-03-12 05:11:31 +01:00
PathSegments (#114)
This commit is contained in:
@@ -34,6 +34,11 @@ namespace WireMock
|
||||
/// </summary>
|
||||
public string Path { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets the path segments.
|
||||
/// </summary>
|
||||
public string[] PathSegments { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets the method.
|
||||
/// </summary>
|
||||
@@ -120,6 +125,7 @@ namespace WireMock
|
||||
Port = url.Port;
|
||||
Origin = $"{url.Scheme}://{url.Host}:{url.Port}";
|
||||
Path = WebUtility.UrlDecode(url.AbsolutePath);
|
||||
PathSegments = Path.Split('/').Skip(1).ToArray();
|
||||
Method = method.ToLower();
|
||||
ClientIP = clientIP;
|
||||
|
||||
@@ -157,11 +163,14 @@ namespace WireMock
|
||||
Port = url.Port;
|
||||
Origin = $"{url.Scheme}://{url.Host}:{url.Port}";
|
||||
Path = WebUtility.UrlDecode(url.AbsolutePath);
|
||||
PathSegments = Path.Split('/').Skip(1).ToArray();
|
||||
Method = method.ToLower();
|
||||
ClientIP = clientIP;
|
||||
|
||||
BodyAsBytes = bodyAsBytes;
|
||||
Body = body;
|
||||
BodyEncoding = bodyEncoding;
|
||||
|
||||
Headers = headers?.ToDictionary(header => header.Key, header => new WireMockList<string>(header.Value));
|
||||
Cookies = cookies;
|
||||
RawQuery = WebUtility.UrlDecode(url.Query);
|
||||
|
||||
@@ -18,7 +18,6 @@ namespace WireMock.ResponseBuilders
|
||||
/// <returns>A <see cref="IResponseBuilder"/>.</returns>
|
||||
IResponseBuilder WithBody([NotNull] string body, [CanBeNull] string destination = BodyDestinationFormat.SameAsSource, [CanBeNull] Encoding encoding = null);
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// WithBody : Create a ... response based on a callback function.
|
||||
/// </summary>
|
||||
@@ -26,8 +25,7 @@ namespace WireMock.ResponseBuilders
|
||||
/// <param name="destination">The Body Destination format (SameAsSource, String or Bytes).</param>
|
||||
/// <param name="encoding">The body encoding.</param>
|
||||
/// <returns>A <see cref="IResponseBuilder"/>.</returns>
|
||||
IResponseBuilder WithBody([NotNull] Func<RequestMessage,string> bodyFactory, [CanBeNull] string destination = BodyDestinationFormat.SameAsSource, [CanBeNull] Encoding encoding = null);
|
||||
|
||||
IResponseBuilder WithBody([NotNull] Func<RequestMessage, string> bodyFactory, [CanBeNull] string destination = BodyDestinationFormat.SameAsSource, [CanBeNull] Encoding encoding = null);
|
||||
|
||||
/// <summary>
|
||||
/// WithBody : Create a ... response based on a bytearray.
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
using System;
|
||||
using NFluent;
|
||||
using WireMock.Util;
|
||||
using Xunit;
|
||||
|
||||
namespace WireMock.Net.Tests
|
||||
@@ -50,5 +51,25 @@ namespace WireMock.Net.Tests
|
||||
Check.That(request.GetParameter("key")).Contains("2");
|
||||
Check.That(request.GetParameter("key")).Contains("3");
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void RequestMessage_Constructor1_PathSegments()
|
||||
{
|
||||
// Assign
|
||||
var request = new RequestMessage(new Uri("http://localhost/a/b/c"), "POST", ClientIp);
|
||||
|
||||
// Assert
|
||||
Check.That(request.PathSegments).ContainsExactly("a", "b", "c");
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void RequestMessage_Constructor2_PathSegments()
|
||||
{
|
||||
// Assign
|
||||
var request = new RequestMessage(new Uri("http://localhost/a/b/c"), "POST", ClientIp, new BodyData());
|
||||
|
||||
// Assert
|
||||
Check.That(request.PathSegments).ContainsExactly("a", "b", "c");
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user