Files
WireMock.Net-wiremock/test/WireMock.Net.Tests/Proxy/ProxyUrlTransformerTests.cs
Stef Heyenrath a292f28dda Version 2.x (#1359)
* Version 2.x

* Setup .NET 9

* 12

* cleanup some #if for NETSTANDARD1_3

* cleanup + fix tests for net8

* openapi

* NO ConfigureAwait(false) + cleanup

* .

* #endif

* HashSet

* WireMock.Net.NUnit

* HttpContext

* Add WebSockets (#1423)

* Add WebSockets

* Add tests

* fix

* more tests

* Add tests

* ...

* remove IOwin

* -

* tests

* fluent

* ok

* match

* .

* byte[]

* x

* func

* func

* byte

* trans

* ...

* frameworks.........

* jmes

* xxx

* sc

* using var httpClient = new HttpClient();

* usings

* maxRetries

* up

* xunit v3

* ct

* ---

* ct

* ct2

* T Unit

* WireMock.Net.TUnitTests / 10

* t unit first

* --project

* no tunit

* t2

* --project

* --project

* ci -  --project

* publish ./test/wiremock-coverage.xml

* windows

* .

* log

* ...

* log

* goed

* BodyType

* .

* .

* --scenario

* ...

* pact

* ct

* .

* WireMock.Net.RestClient.AwesomeAssertions (#1427)

* WireMock.Net.RestClient.AwesomeAssertions

* ok

* atpath

* fix test

* sonar fixes

* ports

* proxy test

* FIX?

* ---

* await Task.Delay(100, _ct);

* ?

* --project

* Aspire: use IDistributedApplicationEventingSubscriber (#1428)

* broadcast

* ok

* more tsts

* .

* Collection

* up

* .

* 2

* remove nfluent

* <VersionPrefix>2.0.0-preview-02</VersionPrefix>

* ...

* .

* nuget icon

* .

* <PackageReference Include="JmesPath.Net" Version="1.1.0" />

* x

* 500

* .

* fix some warnings

* ws
2026-03-11 17:02:47 +01:00

97 lines
2.8 KiB
C#

using System.Globalization;
using Moq;
using WireMock.Handlers;
using WireMock.Proxy;
using WireMock.Settings;
using WireMock.Types;
namespace WireMock.Net.Tests.Proxy;
public class ProxyUrlTransformerTests
{
private readonly Mock<IFileSystemHandler> _fileSystemHandlerMock = new();
[Fact]
public void Transform_WithUseTransformerFalse_PerformsSimpleReplace_CaseSensitive()
{
// Arrange
var settings = new WireMockServerSettings
{
FileSystemHandler = _fileSystemHandlerMock.Object,
Culture = CultureInfo.InvariantCulture
};
var replaceSettings = new ProxyUrlReplaceSettings
{
TransformTemplate = null,
OldValue = "/old",
NewValue = "/new",
IgnoreCase = false
};
var url = "http://example.com/old/path";
var expected = "http://example.com/new/path";
// Act
var actual = ProxyUrlTransformer.Transform(settings, replaceSettings, url);
// Assert
Assert.Equal(expected, actual);
}
[Fact]
public void Transform_WithUseTransformerFalse_PerformsSimpleReplace_IgnoreCase()
{
// Arrange
var settings = new WireMockServerSettings
{
FileSystemHandler = _fileSystemHandlerMock.Object,
Culture = CultureInfo.InvariantCulture
};
var replaceSettings = new ProxyUrlReplaceSettings
{
TransformTemplate = null, // UseTransformer == false
OldValue = "/OLD",
NewValue = "/new",
IgnoreCase = true
};
var url = "http://example.com/old/path"; // lowercase 'old' but OldValue is uppercase
var expected = "http://example.com/new/path";
// Act
var actual = ProxyUrlTransformer.Transform(settings, replaceSettings, url);
// Assert
Assert.Equal(expected, actual);
}
[Fact]
public void Transform_WithUseTransformerTrue_UsesTransformer_ToTransformUrl()
{
// Arrange
var settings = new WireMockServerSettings
{
FileSystemHandler = _fileSystemHandlerMock.Object,
Culture = CultureInfo.InvariantCulture
};
// Handlebars is the default TransformerType; the TransformTemplate uses the model directly.
var replaceSettings = new ProxyUrlReplaceSettings
{
TransformTemplate = "{{this}}-transformed",
// TransformerType defaults to Handlebars but set explicitly for clarity.
TransformerType = TransformerType.Handlebars
};
var url = "http://example.com/path";
var expected = "http://example.com/path-transformed";
// Act
var actual = ProxyUrlTransformer.Transform(settings, replaceSettings, url);
// Assert
Assert.Equal(expected, actual);
}
}