mirror of
https://github.com/wiremock/WireMock.Net.git
synced 2026-03-18 07:13:46 +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
118 lines
2.6 KiB
C#
118 lines
2.6 KiB
C#
// Copyright © WireMock.Net
|
|
|
|
using FluentAssertions;
|
|
using Newtonsoft.Json.Linq;
|
|
|
|
using WireMock.Matchers;
|
|
using Xunit;
|
|
|
|
namespace WireMock.Net.Tests.Matchers;
|
|
|
|
public class LinqMatcherTests
|
|
{
|
|
[Fact]
|
|
public void LinqMatcher_For_String_SinglePattern_IsMatch_Positive()
|
|
{
|
|
// Assign
|
|
string input = "2018-08-31 13:59:59";
|
|
|
|
// Act
|
|
var matcher = new LinqMatcher("DateTime.Parse(it) > \"2018-08-01 13:50:00\"");
|
|
|
|
// Assert
|
|
var score = matcher.IsMatch(input).Score;
|
|
score.Should().Be(MatchScores.Perfect);
|
|
}
|
|
|
|
[Fact]
|
|
public void LinqMatcher_For_String_IsMatch_Negative()
|
|
{
|
|
// Assign
|
|
string input = "2018-08-31 13:59:59";
|
|
|
|
// Act
|
|
var matcher = new LinqMatcher("DateTime.Parse(it) > \"2019-01-01 00:00:00\"");
|
|
|
|
// Assert
|
|
var score = matcher.IsMatch(input).Score;
|
|
score.Should().Be(MatchScores.Mismatch);
|
|
}
|
|
|
|
[Fact]
|
|
public void LinqMatcher_For_String_IsMatch_RejectOnMatch()
|
|
{
|
|
// Assign
|
|
string input = "2018-08-31 13:59:59";
|
|
|
|
// Act
|
|
var matcher = new LinqMatcher(MatchBehaviour.RejectOnMatch, "DateTime.Parse(it) > \"2018-08-01 13:50:00\"");
|
|
|
|
// Assert
|
|
var score = matcher.IsMatch(input).Score;
|
|
score.Should().Be(MatchScores.Mismatch);
|
|
}
|
|
|
|
[Fact]
|
|
public void LinqMatcher_For_Object_IsMatch()
|
|
{
|
|
// Assign
|
|
var input = new
|
|
{
|
|
Id = 9,
|
|
Name = "Test"
|
|
};
|
|
|
|
// Act
|
|
var matcher = new LinqMatcher("Id > 1 AND Name == \"Test\"");
|
|
double match = matcher.IsMatch(input).Score;
|
|
|
|
// Assert
|
|
Assert.Equal(1.0, match);
|
|
}
|
|
|
|
[Fact]
|
|
public void LinqMatcher_For_JObject_IsMatch()
|
|
{
|
|
// Assign
|
|
var input = new JObject
|
|
{
|
|
{ "IntegerId", new JValue(9) },
|
|
{ "LongId", new JValue(long.MaxValue) },
|
|
{ "Name", new JValue("Test") }
|
|
};
|
|
|
|
// Act
|
|
var matcher = new LinqMatcher("IntegerId > 1 AND LongId > 1 && Name == \"Test\"");
|
|
double match = matcher.IsMatch(input).Score;
|
|
|
|
// Assert
|
|
Assert.Equal(1.0, match);
|
|
}
|
|
|
|
[Fact]
|
|
public void LinqMatcher_GetName()
|
|
{
|
|
// Assign
|
|
var matcher = new LinqMatcher("x");
|
|
|
|
// Act
|
|
string name = matcher.Name;
|
|
|
|
// Assert
|
|
name.Should().Be("LinqMatcher");
|
|
}
|
|
|
|
[Fact]
|
|
public void LinqMatcher_GetPatterns()
|
|
{
|
|
// Assign
|
|
var matcher = new LinqMatcher("x");
|
|
|
|
// Act
|
|
var patterns = matcher.GetPatterns();
|
|
|
|
// Assert
|
|
patterns.Should().ContainExactly("x");
|
|
}
|
|
}
|