mirror of
https://github.com/wiremock/WireMock.Net.git
synced 2026-03-18 07:24:34 +01:00
* 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
135 lines
4.4 KiB
C#
135 lines
4.4 KiB
C#
// Copyright © WireMock.Net
|
|
|
|
using WireMock.Admin.Mappings;
|
|
using WireMock.Matchers;
|
|
|
|
namespace WireMock.Net.Tests.Matchers;
|
|
|
|
public class XPathMatcherTests
|
|
{
|
|
[Fact]
|
|
public void XPathMatcher_GetName()
|
|
{
|
|
// Assign
|
|
var matcher = new XPathMatcher("X");
|
|
|
|
// Act
|
|
string name = matcher.Name;
|
|
|
|
// Assert
|
|
name.Should().Be("XPathMatcher");
|
|
}
|
|
|
|
[Fact]
|
|
public void XPathMatcher_GetPatterns()
|
|
{
|
|
// Assign
|
|
var matcher = new XPathMatcher("X");
|
|
|
|
// Act
|
|
var patterns = matcher.GetPatterns();
|
|
|
|
// Assert
|
|
patterns.Should().ContainSingle("X");
|
|
}
|
|
|
|
[Fact]
|
|
public void XPathMatcher_IsMatch_AcceptOnMatch()
|
|
{
|
|
// Assign
|
|
string xml = @"
|
|
<todo-list>
|
|
<todo-item id='a1'>abc</todo-item>
|
|
</todo-list>";
|
|
var matcher = new XPathMatcher("/todo-list[count(todo-item) = 1]");
|
|
|
|
// Act
|
|
double result = matcher.IsMatch(xml).Score;
|
|
|
|
// Assert
|
|
result.Should().Be(1.0);
|
|
}
|
|
|
|
[Fact]
|
|
public void XPathMatcher_IsMatch_WithNamespaces_AcceptOnMatch()
|
|
{
|
|
// Assign
|
|
string input =
|
|
@"<s:Envelope xmlns:s=""http://schemas.xmlsoap.org/soap/envelope/"">
|
|
<s:Body>
|
|
<QueryRequest xmlns=""urn://MyWcfService"">
|
|
<MaxResults i:nil=""true"" xmlns:i=""http://www.w3.org/2001/XMLSchema-instance""/>
|
|
<Restriction i:nil=""true"" xmlns:i=""http://www.w3.org/2001/XMLSchema-instance""/>
|
|
<SearchMode i:nil=""true"" xmlns:i=""http://www.w3.org/2001/XMLSchema-instance""/>
|
|
</QueryRequest>
|
|
</s:Body>
|
|
</s:Envelope>";
|
|
var xmlNamespaces = new[]
|
|
{
|
|
new XmlNamespace { Prefix = "s", Uri = "http://schemas.xmlsoap.org/soap/envelope/" },
|
|
new XmlNamespace { Prefix = "i", Uri = "http://www.w3.org/2001/XMLSchema-instance" }
|
|
};
|
|
var matcher = new XPathMatcher(
|
|
MatchBehaviour.AcceptOnMatch,
|
|
MatchOperator.Or,
|
|
xmlNamespaces,
|
|
"/s:Envelope/s:Body/*[local-name()='QueryRequest' and namespace-uri()='urn://MyWcfService']");
|
|
|
|
// Act
|
|
double result = matcher.IsMatch(input).Score;
|
|
|
|
// Assert
|
|
result.Should().Be(1.0);
|
|
}
|
|
|
|
[Fact]
|
|
public void XPathMatcher_IsMatch_WithNamespaces_OneSelfDefined_AcceptOnMatch()
|
|
{
|
|
// Assign
|
|
string input =
|
|
@"<s:Envelope xmlns:s=""http://schemas.xmlsoap.org/soap/envelope/"">
|
|
<s:Body>
|
|
<QueryRequest xmlns=""urn://MyWcfService"">
|
|
<MaxResults i:nil=""true"" xmlns:i=""http://www.w3.org/2001/XMLSchema-instance""/>
|
|
<Restriction i:nil=""true"" xmlns:i=""http://www.w3.org/2001/XMLSchema-instance""/>
|
|
<SearchMode i:nil=""true"" xmlns:i=""http://www.w3.org/2001/XMLSchema-instance""/>
|
|
</QueryRequest>
|
|
</s:Body>
|
|
</s:Envelope>";
|
|
var xmlNamespaces = new[]
|
|
{
|
|
new XmlNamespace { Prefix = "s", Uri = "http://schemas.xmlsoap.org/soap/envelope/" },
|
|
new XmlNamespace { Prefix = "i", Uri = "http://www.w3.org/2001/XMLSchema-instance" },
|
|
new XmlNamespace { Prefix = "q", Uri = "urn://MyWcfService" }
|
|
};
|
|
var matcher = new XPathMatcher(
|
|
MatchBehaviour.AcceptOnMatch,
|
|
MatchOperator.Or,
|
|
xmlNamespaces,
|
|
"/s:Envelope/s:Body/q:QueryRequest");
|
|
|
|
// Act
|
|
double result = matcher.IsMatch(input).Score;
|
|
|
|
// Assert
|
|
result.Should().Be(1.0);
|
|
}
|
|
|
|
[Fact]
|
|
public void XPathMatcher_IsMatch_RejectOnMatch()
|
|
{
|
|
// Assign
|
|
string xml = @"
|
|
<todo-list>
|
|
<todo-item id='a1'>abc</todo-item>
|
|
</todo-list>";
|
|
var matcher = new XPathMatcher(MatchBehaviour.RejectOnMatch, MatchOperator.Or, null, "/todo-list[count(todo-item) = 1]");
|
|
|
|
// Act
|
|
double result = matcher.IsMatch(xml).Score;
|
|
|
|
// Assert
|
|
result.Should().Be(0.0);
|
|
}
|
|
}
|