mirror of
https://github.com/wiremock/WireMock.Net.git
synced 2026-01-16 07:06:54 +01:00
* Add new package WireMock.Net.Extensions.Routing * Update documentation for WireMock.Net.Extensions.Routing * Cleanup imports * Add header to all source files inside WireMock.Net.Extensions.Routing * Add header to all source files inside WireMock.Net.Extensions.Routing.Tests * Revert unintended changes * Remove redundant build configurations * Remove incorrect links from documentation * Update nuget package references * Revert unintended changes * Migrate to AwesomeAssertions * Remove redundant project reference * Adjust formatting * Migrate to primary constructor * Refactoring: rename delegate parameter * Abstract over JSON converter * Replace WireMock with WireMock.Net in comments * Move local functions to the bottom of the methods
36 lines
1.3 KiB
C#
36 lines
1.3 KiB
C#
// Copyright © WireMock.Net
|
|
|
|
using WireMock.Matchers;
|
|
using WireMock.Net.Extensions.Routing.Delegates;
|
|
using WireMock.RequestBuilders;
|
|
using WireMock.ResponseBuilders;
|
|
using WireMock.Server;
|
|
|
|
namespace WireMock.Net.Extensions.Routing.Extensions;
|
|
|
|
/// <summary>
|
|
/// Provides extension methods for mapping HTTP requests to handlers in <see cref="WireMockServer"/>.
|
|
/// </summary>
|
|
public static class WireMockServerExtensions
|
|
{
|
|
/// <summary>
|
|
/// Maps a request to a WireMock.Net server using the specified method, path matcher, and request handler.
|
|
/// </summary>
|
|
/// <param name="source">The WireMock.Net server to extend.</param>
|
|
/// <param name="method">The HTTP method to match.</param>
|
|
/// <param name="pathMatcher">The matcher for the request path.</param>
|
|
/// <param name="httpRequestHandler">The handler to process the request.</param>
|
|
/// <returns>The current <see cref="WireMockServer"/> instance.</returns>
|
|
public static WireMockServer Map(
|
|
this WireMockServer source,
|
|
string method,
|
|
IStringMatcher pathMatcher,
|
|
WireMockHttpRequestHandler httpRequestHandler)
|
|
{
|
|
source
|
|
.Given(Request.Create().WithPath(pathMatcher).UsingMethod(method))
|
|
.RespondWith(Response.Create().WithCallback(req => httpRequestHandler(req)));
|
|
return source;
|
|
}
|
|
}
|