mirror of
https://github.com/wiremock/WireMock.Net.git
synced 2026-03-23 09:52:05 +01:00
Generate C# code from Mapping (#842)
* 1 * . * v * . * . * - * b * res b * Fix UT * . * Verify * v * ... * . * . * dir * m
This commit is contained in:
18
test/WireMock.Net.Tests/.filenesting.json
Normal file
18
test/WireMock.Net.Tests/.filenesting.json
Normal file
@@ -0,0 +1,18 @@
|
||||
{
|
||||
"help": "https://go.microsoft.com/fwlink/?linkid=866610",
|
||||
"root": true,
|
||||
|
||||
"dependentFileProviders": {
|
||||
"add": {
|
||||
"addedExtension": {},
|
||||
"pathSegment": {},
|
||||
"fileSuffixToExtension": {
|
||||
"add": {
|
||||
".verified.txt": [
|
||||
".cs"
|
||||
]
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -5,40 +5,39 @@ using FluentAssertions;
|
||||
using WireMock.Http;
|
||||
using Xunit;
|
||||
|
||||
namespace WireMock.Net.Tests.Http
|
||||
namespace WireMock.Net.Tests.Http;
|
||||
|
||||
public class ByteArrayContentHelperTests
|
||||
{
|
||||
public class ByteArrayContentHelperTests
|
||||
[Fact]
|
||||
public async Task ByteArrayContentHelperTests_Create_WithNullContentType()
|
||||
{
|
||||
[Fact]
|
||||
public async Task ByteArrayContentHelperTests_Create_WithNullContentType()
|
||||
{
|
||||
// Arrange
|
||||
var content = Encoding.UTF8.GetBytes("test");
|
||||
// Arrange
|
||||
var content = Encoding.UTF8.GetBytes("test");
|
||||
|
||||
// Act
|
||||
var result = ByteArrayContentHelper.Create(content, null);
|
||||
// Act
|
||||
var result = ByteArrayContentHelper.Create(content, null);
|
||||
|
||||
// Assert
|
||||
result.Headers.ContentType.Should().BeNull();
|
||||
(await result.ReadAsByteArrayAsync().ConfigureAwait(false)).Should().BeEquivalentTo(content);
|
||||
}
|
||||
|
||||
[Theory]
|
||||
[InlineData("application/octet-stream", "application/octet-stream")]
|
||||
[InlineData("application/soap+xml", "application/soap+xml")]
|
||||
[InlineData("multipart/form-data; boundary=------------------------x", "multipart/form-data; boundary=------------------------x")]
|
||||
public async Task ByteArrayContentHelperTests_Create(string test, string expected)
|
||||
{
|
||||
// Arrange
|
||||
var content = Encoding.UTF8.GetBytes("test");
|
||||
var contentType = MediaTypeHeaderValue.Parse(test);
|
||||
|
||||
// Act
|
||||
var result = ByteArrayContentHelper.Create(content, contentType);
|
||||
|
||||
// Assert
|
||||
result.Headers.ContentType.ToString().Should().Be(expected);
|
||||
(await result.ReadAsByteArrayAsync().ConfigureAwait(false)).Should().BeEquivalentTo(content);
|
||||
}
|
||||
// Assert
|
||||
result.Headers.ContentType.Should().BeNull();
|
||||
(await result.ReadAsByteArrayAsync().ConfigureAwait(false)).Should().BeEquivalentTo(content);
|
||||
}
|
||||
}
|
||||
|
||||
[Theory]
|
||||
[InlineData("application/octet-stream", "application/octet-stream")]
|
||||
[InlineData("application/soap+xml", "application/soap+xml")]
|
||||
[InlineData("multipart/form-data; boundary=------------------------x", "multipart/form-data; boundary=------------------------x")]
|
||||
public async Task ByteArrayContentHelperTests_Create(string test, string expected)
|
||||
{
|
||||
// Arrange
|
||||
var content = Encoding.UTF8.GetBytes("test");
|
||||
var contentType = MediaTypeHeaderValue.Parse(test);
|
||||
|
||||
// Act
|
||||
var result = ByteArrayContentHelper.Create(content, contentType);
|
||||
|
||||
// Assert
|
||||
result.Headers.ContentType.ToString().Should().Be(expected);
|
||||
(await result.ReadAsByteArrayAsync().ConfigureAwait(false)).Should().BeEquivalentTo(content);
|
||||
}
|
||||
}
|
||||
@@ -1,164 +1,163 @@
|
||||
using NFluent;
|
||||
using System.Collections.Generic;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using System.Threading.Tasks;
|
||||
using WireMock.Http;
|
||||
using WireMock.Models;
|
||||
using WireMock.Types;
|
||||
using WireMock.Util;
|
||||
using Xunit;
|
||||
|
||||
namespace WireMock.Net.Tests.Http
|
||||
namespace WireMock.Net.Tests.Http;
|
||||
|
||||
public class HttpRequestMessageHelperTests
|
||||
{
|
||||
public class HttpRequestMessageHelperTests
|
||||
private const string ClientIp = "::1";
|
||||
|
||||
[Fact]
|
||||
public void HttpRequestMessageHelper_Create()
|
||||
{
|
||||
private const string ClientIp = "::1";
|
||||
// Assign
|
||||
var headers = new Dictionary<string, string[]> { { "x", new[] { "value-1" } } };
|
||||
var request = new RequestMessage(new UrlDetails("http://localhost/foo"), "PUT", ClientIp, null, headers);
|
||||
|
||||
[Fact]
|
||||
public void HttpRequestMessageHelper_Create()
|
||||
// Act
|
||||
var message = HttpRequestMessageHelper.Create(request, "http://url");
|
||||
|
||||
// Assert
|
||||
Check.That(message.Headers.GetValues("x")).ContainsExactly("value-1");
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task HttpRequestMessageHelper_Create_Bytes()
|
||||
{
|
||||
// Assign
|
||||
var body = new BodyData
|
||||
{
|
||||
// Assign
|
||||
var headers = new Dictionary<string, string[]> { { "x", new[] { "value-1" } } };
|
||||
var request = new RequestMessage(new UrlDetails("http://localhost/foo"), "PUT", ClientIp, null, headers);
|
||||
BodyAsBytes = Encoding.UTF8.GetBytes("hi"),
|
||||
DetectedBodyType = BodyType.Bytes
|
||||
};
|
||||
var request = new RequestMessage(new UrlDetails("http://localhost/foo"), "GET", ClientIp, body);
|
||||
|
||||
// Act
|
||||
var message = HttpRequestMessageHelper.Create(request, "http://url");
|
||||
// Act
|
||||
var message = HttpRequestMessageHelper.Create(request, "http://url");
|
||||
|
||||
// Assert
|
||||
Check.That(message.Headers.GetValues("x")).ContainsExactly("value-1");
|
||||
}
|
||||
// Assert
|
||||
Check.That(await message.Content.ReadAsByteArrayAsync().ConfigureAwait(false)).ContainsExactly(Encoding.UTF8.GetBytes("hi"));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task HttpRequestMessageHelper_Create_Bytes()
|
||||
[Fact]
|
||||
public async Task HttpRequestMessageHelper_Create_Json()
|
||||
{
|
||||
// Assign
|
||||
var body = new BodyData
|
||||
{
|
||||
// Assign
|
||||
var body = new BodyData
|
||||
{
|
||||
BodyAsBytes = Encoding.UTF8.GetBytes("hi"),
|
||||
DetectedBodyType = BodyType.Bytes
|
||||
};
|
||||
var request = new RequestMessage(new UrlDetails("http://localhost/foo"), "GET", ClientIp, body);
|
||||
BodyAsJson = new { x = 42 },
|
||||
DetectedBodyType = BodyType.Json
|
||||
};
|
||||
var request = new RequestMessage(new UrlDetails("http://localhost/foo"), "GET", ClientIp, body);
|
||||
|
||||
// Act
|
||||
var message = HttpRequestMessageHelper.Create(request, "http://url");
|
||||
// Act
|
||||
var message = HttpRequestMessageHelper.Create(request, "http://url");
|
||||
|
||||
// Assert
|
||||
Check.That(await message.Content.ReadAsByteArrayAsync().ConfigureAwait(false)).ContainsExactly(Encoding.UTF8.GetBytes("hi"));
|
||||
}
|
||||
// Assert
|
||||
Check.That(await message.Content.ReadAsStringAsync().ConfigureAwait(false)).Equals("{\"x\":42}");
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task HttpRequestMessageHelper_Create_Json()
|
||||
[Fact]
|
||||
public async Task HttpRequestMessageHelper_Create_Json_With_ContentType_ApplicationJson()
|
||||
{
|
||||
// Assign
|
||||
var headers = new Dictionary<string, string[]> { { "Content-Type", new[] { "application/json" } } };
|
||||
var body = new BodyData
|
||||
{
|
||||
// Assign
|
||||
var body = new BodyData
|
||||
{
|
||||
BodyAsJson = new { x = 42 },
|
||||
DetectedBodyType = BodyType.Json
|
||||
};
|
||||
var request = new RequestMessage(new UrlDetails("http://localhost/foo"), "GET", ClientIp, body);
|
||||
BodyAsJson = new { x = 42 },
|
||||
DetectedBodyType = BodyType.Json
|
||||
};
|
||||
var request = new RequestMessage(new UrlDetails("http://localhost/foo"), "GET", ClientIp, body, headers);
|
||||
|
||||
// Act
|
||||
var message = HttpRequestMessageHelper.Create(request, "http://url");
|
||||
// Act
|
||||
var message = HttpRequestMessageHelper.Create(request, "http://url");
|
||||
|
||||
// Assert
|
||||
Check.That(await message.Content.ReadAsStringAsync().ConfigureAwait(false)).Equals("{\"x\":42}");
|
||||
}
|
||||
// Assert
|
||||
Check.That(await message.Content.ReadAsStringAsync().ConfigureAwait(false)).Equals("{\"x\":42}");
|
||||
Check.That(message.Content.Headers.GetValues("Content-Type")).ContainsExactly("application/json");
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task HttpRequestMessageHelper_Create_Json_With_ContentType_ApplicationJson()
|
||||
[Fact]
|
||||
public async Task HttpRequestMessageHelper_Create_Json_With_ContentType_ApplicationJson_UTF8()
|
||||
{
|
||||
// Assign
|
||||
var headers = new Dictionary<string, string[]> { { "Content-Type", new[] { "application/json; charset=utf-8" } } };
|
||||
var body = new BodyData
|
||||
{
|
||||
// Assign
|
||||
var headers = new Dictionary<string, string[]> { { "Content-Type", new[] { "application/json" } } };
|
||||
var body = new BodyData
|
||||
{
|
||||
BodyAsJson = new { x = 42 },
|
||||
DetectedBodyType = BodyType.Json
|
||||
};
|
||||
var request = new RequestMessage(new UrlDetails("http://localhost/foo"), "GET", ClientIp, body, headers);
|
||||
BodyAsJson = new { x = 42 },
|
||||
DetectedBodyType = BodyType.Json
|
||||
};
|
||||
var request = new RequestMessage(new UrlDetails("http://localhost/foo"), "GET", ClientIp, body, headers);
|
||||
|
||||
// Act
|
||||
var message = HttpRequestMessageHelper.Create(request, "http://url");
|
||||
// Act
|
||||
var message = HttpRequestMessageHelper.Create(request, "http://url");
|
||||
|
||||
// Assert
|
||||
Check.That(await message.Content.ReadAsStringAsync().ConfigureAwait(false)).Equals("{\"x\":42}");
|
||||
Check.That(message.Content.Headers.GetValues("Content-Type")).ContainsExactly("application/json");
|
||||
}
|
||||
// Assert
|
||||
Check.That(await message.Content.ReadAsStringAsync().ConfigureAwait(false)).Equals("{\"x\":42}");
|
||||
Check.That(message.Content.Headers.GetValues("Content-Type")).ContainsExactly("application/json; charset=utf-8");
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task HttpRequestMessageHelper_Create_Json_With_ContentType_ApplicationJson_UTF8()
|
||||
[Fact]
|
||||
public void HttpRequestMessageHelper_Create_String_With_ContentType_ApplicationXml()
|
||||
{
|
||||
// Assign
|
||||
var headers = new Dictionary<string, string[]> { { "Content-Type", new[] { "application/xml" } } };
|
||||
var body = new BodyData
|
||||
{
|
||||
// Assign
|
||||
var headers = new Dictionary<string, string[]> { { "Content-Type", new[] { "application/json; charset=utf-8" } } };
|
||||
var body = new BodyData
|
||||
{
|
||||
BodyAsJson = new { x = 42 },
|
||||
DetectedBodyType = BodyType.Json
|
||||
};
|
||||
var request = new RequestMessage(new UrlDetails("http://localhost/foo"), "GET", ClientIp, body, headers);
|
||||
BodyAsString = "<xml>hello</xml>",
|
||||
DetectedBodyType = BodyType.String
|
||||
};
|
||||
var request = new RequestMessage(new UrlDetails("http://localhost/foo"), "PUT", ClientIp, body, headers);
|
||||
|
||||
// Act
|
||||
var message = HttpRequestMessageHelper.Create(request, "http://url");
|
||||
// Act
|
||||
var message = HttpRequestMessageHelper.Create(request, "http://url");
|
||||
|
||||
// Assert
|
||||
Check.That(await message.Content.ReadAsStringAsync().ConfigureAwait(false)).Equals("{\"x\":42}");
|
||||
Check.That(message.Content.Headers.GetValues("Content-Type")).ContainsExactly("application/json; charset=utf-8");
|
||||
}
|
||||
// Assert
|
||||
Check.That(message.Content.Headers.GetValues("Content-Type")).ContainsExactly("application/xml");
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void HttpRequestMessageHelper_Create_String_With_ContentType_ApplicationXml()
|
||||
[Fact]
|
||||
public void HttpRequestMessageHelper_Create_String_With_ContentType_ApplicationXml_UTF8()
|
||||
{
|
||||
// Assign
|
||||
var headers = new Dictionary<string, string[]> { { "Content-Type", new[] { "application/xml; charset=UTF-8" } } };
|
||||
var body = new BodyData
|
||||
{
|
||||
// Assign
|
||||
var headers = new Dictionary<string, string[]> { { "Content-Type", new[] { "application/xml" } } };
|
||||
var body = new BodyData
|
||||
{
|
||||
BodyAsString = "<xml>hello</xml>",
|
||||
DetectedBodyType = BodyType.String
|
||||
};
|
||||
var request = new RequestMessage(new UrlDetails("http://localhost/foo"), "PUT", ClientIp, body, headers);
|
||||
BodyAsString = "<xml>hello</xml>",
|
||||
DetectedBodyType = BodyType.String
|
||||
};
|
||||
var request = new RequestMessage(new UrlDetails("http://localhost/foo"), "PUT", ClientIp, body, headers);
|
||||
|
||||
// Act
|
||||
var message = HttpRequestMessageHelper.Create(request, "http://url");
|
||||
// Act
|
||||
var message = HttpRequestMessageHelper.Create(request, "http://url");
|
||||
|
||||
// Assert
|
||||
Check.That(message.Content.Headers.GetValues("Content-Type")).ContainsExactly("application/xml");
|
||||
}
|
||||
// Assert
|
||||
Check.That(message.Content.Headers.GetValues("Content-Type")).ContainsExactly("application/xml; charset=UTF-8");
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void HttpRequestMessageHelper_Create_String_With_ContentType_ApplicationXml_UTF8()
|
||||
[Fact]
|
||||
public void HttpRequestMessageHelper_Create_String_With_ContentType_ApplicationXml_ASCII()
|
||||
{
|
||||
// Assign
|
||||
var headers = new Dictionary<string, string[]> { { "Content-Type", new[] { "application/xml; charset=Ascii" } } };
|
||||
var body = new BodyData
|
||||
{
|
||||
// Assign
|
||||
var headers = new Dictionary<string, string[]> { { "Content-Type", new[] { "application/xml; charset=UTF-8" } } };
|
||||
var body = new BodyData
|
||||
{
|
||||
BodyAsString = "<xml>hello</xml>",
|
||||
DetectedBodyType = BodyType.String
|
||||
};
|
||||
var request = new RequestMessage(new UrlDetails("http://localhost/foo"), "PUT", ClientIp, body, headers);
|
||||
BodyAsString = "<xml>hello</xml>",
|
||||
DetectedBodyType = BodyType.String
|
||||
};
|
||||
var request = new RequestMessage(new UrlDetails("http://localhost/foo"), "PUT", ClientIp, body, headers);
|
||||
|
||||
// Act
|
||||
var message = HttpRequestMessageHelper.Create(request, "http://url");
|
||||
// Act
|
||||
var message = HttpRequestMessageHelper.Create(request, "http://url");
|
||||
|
||||
// Assert
|
||||
Check.That(message.Content.Headers.GetValues("Content-Type")).ContainsExactly("application/xml; charset=UTF-8");
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void HttpRequestMessageHelper_Create_String_With_ContentType_ApplicationXml_ASCII()
|
||||
{
|
||||
// Assign
|
||||
var headers = new Dictionary<string, string[]> { { "Content-Type", new[] { "application/xml; charset=Ascii" } } };
|
||||
var body = new BodyData
|
||||
{
|
||||
BodyAsString = "<xml>hello</xml>",
|
||||
DetectedBodyType = BodyType.String
|
||||
};
|
||||
var request = new RequestMessage(new UrlDetails("http://localhost/foo"), "PUT", ClientIp, body, headers);
|
||||
|
||||
// Act
|
||||
var message = HttpRequestMessageHelper.Create(request, "http://url");
|
||||
|
||||
// Assert
|
||||
Check.That(message.Content.Headers.GetValues("Content-Type")).ContainsExactly("application/xml; charset=Ascii");
|
||||
}
|
||||
// Assert
|
||||
Check.That(message.Content.Headers.GetValues("Content-Type")).ContainsExactly("application/xml; charset=Ascii");
|
||||
}
|
||||
}
|
||||
@@ -1,39 +1,38 @@
|
||||
using System.Net.Http.Headers;
|
||||
using System.Net.Http.Headers;
|
||||
using FluentAssertions;
|
||||
using WireMock.Http;
|
||||
using Xunit;
|
||||
|
||||
namespace WireMock.Net.Tests.Http
|
||||
namespace WireMock.Net.Tests.Http;
|
||||
|
||||
public class StringContentHelperTests
|
||||
{
|
||||
public class StringContentHelperTests
|
||||
[Fact]
|
||||
public void StringContentHelper_Create_WithNullContentType()
|
||||
{
|
||||
[Fact]
|
||||
public void StringContentHelper_Create_WithNullContentType()
|
||||
{
|
||||
// Act
|
||||
var result = StringContentHelper.Create("test", null);
|
||||
// Act
|
||||
var result = StringContentHelper.Create("test", null);
|
||||
|
||||
// Assert
|
||||
result.Headers.ContentType.Should().BeNull();
|
||||
result.ReadAsStringAsync().Result.Should().Be("test");
|
||||
}
|
||||
|
||||
[Theory]
|
||||
[InlineData("application/json", "application/json")]
|
||||
[InlineData("application/soap+xml", "application/soap+xml")]
|
||||
[InlineData("application/soap+xml;charset=UTF-8", "application/soap+xml; charset=UTF-8")]
|
||||
[InlineData("application/soap+xml;charset=UTF-8;action=\"http://myCompany.Customer.Contract/ICustomerService/GetSomeConfiguration\"", "application/soap+xml; charset=UTF-8; action=\"http://myCompany.Customer.Contract/ICustomerService/GetSomeConfiguration\"")]
|
||||
public void StringContentHelper_Create(string test, string expected)
|
||||
{
|
||||
// Arrange
|
||||
var contentType = MediaTypeHeaderValue.Parse(test);
|
||||
|
||||
// Act
|
||||
var result = StringContentHelper.Create("test", contentType);
|
||||
|
||||
// Assert
|
||||
result.Headers.ContentType.ToString().Should().Be(expected);
|
||||
result.ReadAsStringAsync().Result.Should().Be("test");
|
||||
}
|
||||
// Assert
|
||||
result.Headers.ContentType.Should().BeNull();
|
||||
result.ReadAsStringAsync().Result.Should().Be("test");
|
||||
}
|
||||
}
|
||||
|
||||
[Theory]
|
||||
[InlineData("application/json", "application/json")]
|
||||
[InlineData("application/soap+xml", "application/soap+xml")]
|
||||
[InlineData("application/soap+xml;charset=UTF-8", "application/soap+xml; charset=UTF-8")]
|
||||
[InlineData("application/soap+xml;charset=UTF-8;action=\"http://myCompany.Customer.Contract/ICustomerService/GetSomeConfiguration\"", "application/soap+xml; charset=UTF-8; action=\"http://myCompany.Customer.Contract/ICustomerService/GetSomeConfiguration\"")]
|
||||
public void StringContentHelper_Create(string test, string expected)
|
||||
{
|
||||
// Arrange
|
||||
var contentType = MediaTypeHeaderValue.Parse(test);
|
||||
|
||||
// Act
|
||||
var result = StringContentHelper.Create("test", contentType);
|
||||
|
||||
// Assert
|
||||
result.Headers.ContentType.ToString().Should().Be(expected);
|
||||
result.ReadAsStringAsync().Result.Should().Be("test");
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,25 @@
|
||||
[
|
||||
{
|
||||
Guid: 41372914-1838-4c67-916b-b9aacdd096ce,
|
||||
UpdatedAt: 2023-01-14 15:16:17,
|
||||
Request: {
|
||||
Path: {
|
||||
Matchers: [
|
||||
{
|
||||
Name: WildcardMatcher,
|
||||
Pattern: /foo,
|
||||
IgnoreCase: false
|
||||
}
|
||||
]
|
||||
},
|
||||
Methods: [
|
||||
GET
|
||||
]
|
||||
},
|
||||
Response: {
|
||||
BodyDestination: SameAsSource,
|
||||
Body: { msg: "Hello world!"}
|
||||
},
|
||||
UseWebhooksFireAndForget: false
|
||||
}
|
||||
]
|
||||
@@ -0,0 +1,25 @@
|
||||
[
|
||||
{
|
||||
Guid: 41372914-1838-4c67-916b-b9aacdd096ce,
|
||||
UpdatedAt: 2023-01-14T15:16:17,
|
||||
Request: {
|
||||
Path: {
|
||||
Matchers: [
|
||||
{
|
||||
Name: WildcardMatcher,
|
||||
Pattern: /foo,
|
||||
IgnoreCase: false
|
||||
}
|
||||
]
|
||||
},
|
||||
Methods: [
|
||||
GET
|
||||
]
|
||||
},
|
||||
Response: {
|
||||
BodyDestination: SameAsSource,
|
||||
Body: { msg: "Hello world!"}
|
||||
},
|
||||
UseWebhooksFireAndForget: false
|
||||
}
|
||||
]
|
||||
@@ -1,5 +1,10 @@
|
||||
using FluentAssertions;
|
||||
#if !(NET452 || NET461 || NETCOREAPP3_1)
|
||||
using System;
|
||||
using System.Runtime.CompilerServices;
|
||||
using System.Threading.Tasks;
|
||||
using Moq;
|
||||
using VerifyTests;
|
||||
using VerifyXunit;
|
||||
using WireMock.Handlers;
|
||||
using WireMock.Logging;
|
||||
using WireMock.Owin;
|
||||
@@ -7,13 +12,17 @@ using WireMock.RequestBuilders;
|
||||
using WireMock.ResponseBuilders;
|
||||
using WireMock.Serialization;
|
||||
using WireMock.Settings;
|
||||
using WireMock.Util;
|
||||
using Xunit;
|
||||
|
||||
namespace WireMock.Net.Tests;
|
||||
|
||||
[UsesVerify]
|
||||
public class MappingBuilderTests
|
||||
{
|
||||
private static readonly string MappingGuid = "41372914-1838-4c67-916b-b9aacdd096ce";
|
||||
private static readonly Guid NewGuid = new("98fae52e-76df-47d9-876f-2ee32e931d9b");
|
||||
private const string MappingGuid = "41372914-1838-4c67-916b-b9aacdd096ce";
|
||||
private static readonly DateTime UtcNow = new(2023, 1, 14, 15, 16, 17);
|
||||
|
||||
private readonly Mock<IFileSystemHandler> _fileSystemHandlerMock;
|
||||
|
||||
@@ -23,6 +32,12 @@ public class MappingBuilderTests
|
||||
{
|
||||
_fileSystemHandlerMock = new Mock<IFileSystemHandler>();
|
||||
|
||||
var guidUtilsMock = new Mock<IGuidUtils>();
|
||||
guidUtilsMock.Setup(g => g.NewGuid()).Returns(NewGuid);
|
||||
|
||||
var dateTimeUtilsMock = new Mock<IDateTimeUtils>();
|
||||
dateTimeUtilsMock.SetupGet(d => d.UtcNow).Returns(UtcNow);
|
||||
|
||||
var settings = new WireMockServerSettings
|
||||
{
|
||||
FileSystemHandler = _fileSystemHandlerMock.Object,
|
||||
@@ -33,7 +48,14 @@ public class MappingBuilderTests
|
||||
var mappingConverter = new MappingConverter(matcherMapper);
|
||||
var mappingToFileSaver = new MappingToFileSaver(settings, mappingConverter);
|
||||
|
||||
_sut = new MappingBuilder(settings, options, mappingConverter, mappingToFileSaver);
|
||||
_sut = new MappingBuilder(
|
||||
settings,
|
||||
options,
|
||||
mappingConverter,
|
||||
mappingToFileSaver,
|
||||
guidUtilsMock.Object,
|
||||
dateTimeUtilsMock.Object
|
||||
);
|
||||
|
||||
_sut.Given(Request.Create()
|
||||
.WithPath("/foo")
|
||||
@@ -45,24 +67,31 @@ public class MappingBuilderTests
|
||||
);
|
||||
}
|
||||
|
||||
[ModuleInitializer]
|
||||
public static void ModuleInitializer()
|
||||
{
|
||||
VerifierSettings.DontScrubGuids();
|
||||
VerifierSettings.DontScrubDateTimes();
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void GetMappings()
|
||||
public Task GetMappings()
|
||||
{
|
||||
// Act
|
||||
var mappings = _sut.GetMappings();
|
||||
|
||||
// Assert
|
||||
mappings.Should().HaveCount(1);
|
||||
// Verify
|
||||
return Verifier.Verify(mappings);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void ToJson()
|
||||
public Task ToJson()
|
||||
{
|
||||
// Act
|
||||
var json = _sut.ToJson();
|
||||
|
||||
// Assert
|
||||
json.Should().NotBeEmpty();
|
||||
// Verify
|
||||
return Verifier.VerifyJson(json);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
@@ -133,4 +162,5 @@ public class MappingBuilderTests
|
||||
_fileSystemHandlerMock.Verify(fs => fs.WriteMappingFile(It.IsAny<string>(), It.IsAny<string>()), Times.Once);
|
||||
_fileSystemHandlerMock.VerifyNoOtherCalls();
|
||||
}
|
||||
}
|
||||
}
|
||||
#endif
|
||||
@@ -2,91 +2,90 @@ using NFluent;
|
||||
using WireMock.Matchers;
|
||||
using Xunit;
|
||||
|
||||
namespace WireMock.Net.Tests.Matchers
|
||||
namespace WireMock.Net.Tests.Matchers;
|
||||
|
||||
public class CSharpCodeMatcherTests
|
||||
{
|
||||
public class CSharpCodeMatcherTests
|
||||
[Fact]
|
||||
public void CSharpCodeMatcher_For_String_SinglePattern_IsMatch_Positive()
|
||||
{
|
||||
[Fact]
|
||||
public void CSharpCodeMatcher_For_String_SinglePattern_IsMatch_Positive()
|
||||
// Assign
|
||||
string input = "x";
|
||||
|
||||
// Act
|
||||
var matcher = new CSharpCodeMatcher("return it == \"x\";");
|
||||
|
||||
// Assert
|
||||
Check.That(matcher.IsMatch(input)).IsEqualTo(1.0d);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void CSharpCodeMatcher_For_String_IsMatch_Negative()
|
||||
{
|
||||
// Assign
|
||||
string input = "y";
|
||||
|
||||
// Act
|
||||
var matcher = new CSharpCodeMatcher("return it == \"x\";");
|
||||
|
||||
// Assert
|
||||
Check.That(matcher.IsMatch(input)).IsEqualTo(0.0d);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void CSharpCodeMatcher_For_String_IsMatch_RejectOnMatch()
|
||||
{
|
||||
// Assign
|
||||
string input = "x";
|
||||
|
||||
// Act
|
||||
var matcher = new CSharpCodeMatcher(MatchBehaviour.RejectOnMatch, MatchOperator.Or, "return it == \"x\";");
|
||||
|
||||
// Assert
|
||||
Check.That(matcher.IsMatch(input)).IsEqualTo(0.0d);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void CSharpCodeMatcher_For_Object_IsMatch()
|
||||
{
|
||||
// Assign
|
||||
var input = new
|
||||
{
|
||||
// Assign
|
||||
string input = "x";
|
||||
Id = 9,
|
||||
Name = "Test"
|
||||
};
|
||||
|
||||
// Act
|
||||
var matcher = new CSharpCodeMatcher("return it == \"x\";");
|
||||
// Act
|
||||
var matcher = new CSharpCodeMatcher("return it.Id > 1 && it.Name == \"Test\";");
|
||||
double match = matcher.IsMatch(input);
|
||||
|
||||
// Assert
|
||||
Check.That(matcher.IsMatch(input)).IsEqualTo(1.0d);
|
||||
}
|
||||
// Assert
|
||||
Assert.Equal(1.0, match);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void CSharpCodeMatcher_For_String_IsMatch_Negative()
|
||||
{
|
||||
// Assign
|
||||
string input = "y";
|
||||
[Fact]
|
||||
public void CSharpCodeMatcher_GetName()
|
||||
{
|
||||
// Assign
|
||||
var matcher = new CSharpCodeMatcher("x");
|
||||
|
||||
// Act
|
||||
var matcher = new CSharpCodeMatcher("return it == \"x\";");
|
||||
// Act
|
||||
string name = matcher.Name;
|
||||
|
||||
// Assert
|
||||
Check.That(matcher.IsMatch(input)).IsEqualTo(0.0d);
|
||||
}
|
||||
// Assert
|
||||
Check.That(name).Equals("CSharpCodeMatcher");
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void CSharpCodeMatcher_For_String_IsMatch_RejectOnMatch()
|
||||
{
|
||||
// Assign
|
||||
string input = "x";
|
||||
[Fact]
|
||||
public void CSharpCodeMatcher_GetPatterns()
|
||||
{
|
||||
// Assign
|
||||
var matcher = new CSharpCodeMatcher("x");
|
||||
|
||||
// Act
|
||||
var matcher = new CSharpCodeMatcher(MatchBehaviour.RejectOnMatch, MatchOperator.Or, "return it == \"x\";");
|
||||
// Act
|
||||
var patterns = matcher.GetPatterns();
|
||||
|
||||
// Assert
|
||||
Check.That(matcher.IsMatch(input)).IsEqualTo(0.0d);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void CSharpCodeMatcher_For_Object_IsMatch()
|
||||
{
|
||||
// Assign
|
||||
var input = new
|
||||
{
|
||||
Id = 9,
|
||||
Name = "Test"
|
||||
};
|
||||
|
||||
// Act
|
||||
var matcher = new CSharpCodeMatcher("return it.Id > 1 && it.Name == \"Test\";");
|
||||
double match = matcher.IsMatch(input);
|
||||
|
||||
// Assert
|
||||
Assert.Equal(1.0, match);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void CSharpCodeMatcher_GetName()
|
||||
{
|
||||
// Assign
|
||||
var matcher = new CSharpCodeMatcher("x");
|
||||
|
||||
// Act
|
||||
string name = matcher.Name;
|
||||
|
||||
// Assert
|
||||
Check.That(name).Equals("CSharpCodeMatcher");
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void CSharpCodeMatcher_GetPatterns()
|
||||
{
|
||||
// Assign
|
||||
var matcher = new CSharpCodeMatcher("x");
|
||||
|
||||
// Act
|
||||
var patterns = matcher.GetPatterns();
|
||||
|
||||
// Assert
|
||||
Check.That(patterns).ContainsExactly("x");
|
||||
}
|
||||
// Assert
|
||||
Check.That(patterns).ContainsExactly("x");
|
||||
}
|
||||
}
|
||||
@@ -1,59 +1,57 @@
|
||||
using AnyOfTypes;
|
||||
using NFluent;
|
||||
using WireMock.Matchers;
|
||||
using Xunit;
|
||||
|
||||
namespace WireMock.Net.Tests.Matchers
|
||||
namespace WireMock.Net.Tests.Matchers;
|
||||
|
||||
public class ContentTypeMatcherTests
|
||||
{
|
||||
public class ContentTypeMatcherTests
|
||||
[Theory]
|
||||
[InlineData("application/json")]
|
||||
[InlineData("application/json; charset=ascii")]
|
||||
[InlineData("application/json; charset=utf-8")]
|
||||
[InlineData("application/json; charset=UTF-8")]
|
||||
public void ContentTypeMatcher_IsMatchWithIgnoreCaseFalse_Positive(string contentType)
|
||||
{
|
||||
[Theory]
|
||||
[InlineData("application/json")]
|
||||
[InlineData("application/json; charset=ascii")]
|
||||
[InlineData("application/json; charset=utf-8")]
|
||||
[InlineData("application/json; charset=UTF-8")]
|
||||
public void ContentTypeMatcher_IsMatchWithIgnoreCaseFalse_Positive(string contentType)
|
||||
{
|
||||
var matcher = new ContentTypeMatcher("application/json");
|
||||
Check.That(matcher.IsMatch(contentType)).IsEqualTo(1.0d);
|
||||
}
|
||||
var matcher = new ContentTypeMatcher("application/json");
|
||||
Check.That(matcher.IsMatch(contentType)).IsEqualTo(1.0d);
|
||||
}
|
||||
|
||||
[Theory]
|
||||
[InlineData("application/json")]
|
||||
[InlineData("application/JSON")]
|
||||
[InlineData("application/json; CharSet=ascii")]
|
||||
[InlineData("application/json; charset=utf-8")]
|
||||
[InlineData("application/json; charset=UTF-8")]
|
||||
public void ContentTypeMatcher_IsMatchWithIgnoreCaseTrue_Positive(string contentType)
|
||||
{
|
||||
var matcher = new ContentTypeMatcher("application/json", true);
|
||||
Check.That(matcher.IsMatch(contentType)).IsEqualTo(1.0d);
|
||||
}
|
||||
[Theory]
|
||||
[InlineData("application/json")]
|
||||
[InlineData("application/JSON")]
|
||||
[InlineData("application/json; CharSet=ascii")]
|
||||
[InlineData("application/json; charset=utf-8")]
|
||||
[InlineData("application/json; charset=UTF-8")]
|
||||
public void ContentTypeMatcher_IsMatchWithIgnoreCaseTrue_Positive(string contentType)
|
||||
{
|
||||
var matcher = new ContentTypeMatcher("application/json", true);
|
||||
Check.That(matcher.IsMatch(contentType)).IsEqualTo(1.0d);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void ContentTypeMatcher_GetName()
|
||||
{
|
||||
// Assign
|
||||
var matcher = new ContentTypeMatcher("x");
|
||||
[Fact]
|
||||
public void ContentTypeMatcher_GetName()
|
||||
{
|
||||
// Assign
|
||||
var matcher = new ContentTypeMatcher("x");
|
||||
|
||||
// Act
|
||||
string name = matcher.Name;
|
||||
// Act
|
||||
string name = matcher.Name;
|
||||
|
||||
// Assert
|
||||
Check.That(name).Equals("ContentTypeMatcher");
|
||||
}
|
||||
// Assert
|
||||
Check.That(name).Equals("ContentTypeMatcher");
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void ContentTypeMatcher_GetPatterns()
|
||||
{
|
||||
// Assign
|
||||
var matcher = new ContentTypeMatcher("x");
|
||||
[Fact]
|
||||
public void ContentTypeMatcher_GetPatterns()
|
||||
{
|
||||
// Assign
|
||||
var matcher = new ContentTypeMatcher("x");
|
||||
|
||||
// Act
|
||||
var patterns = matcher.GetPatterns();
|
||||
// Act
|
||||
var patterns = matcher.GetPatterns();
|
||||
|
||||
// Assert
|
||||
Check.That(patterns).ContainsExactly("x");
|
||||
}
|
||||
// Assert
|
||||
Check.That(patterns).ContainsExactly("x");
|
||||
}
|
||||
}
|
||||
@@ -1,65 +1,64 @@
|
||||
using NFluent;
|
||||
using NFluent;
|
||||
using WireMock.Matchers;
|
||||
using Xunit;
|
||||
|
||||
namespace WireMock.Net.Tests.Matchers
|
||||
namespace WireMock.Net.Tests.Matchers;
|
||||
|
||||
public class ExactObjectMatcherTests
|
||||
{
|
||||
public class ExactObjectMatcherTests
|
||||
[Fact]
|
||||
public void ExactObjectMatcher_GetName()
|
||||
{
|
||||
[Fact]
|
||||
public void ExactObjectMatcher_GetName()
|
||||
{
|
||||
// Assign
|
||||
object obj = 1;
|
||||
// Assign
|
||||
object obj = 1;
|
||||
|
||||
// Act
|
||||
var matcher = new ExactObjectMatcher(obj);
|
||||
string name = matcher.Name;
|
||||
// Act
|
||||
var matcher = new ExactObjectMatcher(obj);
|
||||
string name = matcher.Name;
|
||||
|
||||
// Assert
|
||||
Check.That(name).Equals("ExactObjectMatcher");
|
||||
}
|
||||
// Assert
|
||||
Check.That(name).Equals("ExactObjectMatcher");
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void ExactObjectMatcher_IsMatch_ByteArray()
|
||||
{
|
||||
// Assign
|
||||
object checkValue = new byte[] { 1, 2 };
|
||||
[Fact]
|
||||
public void ExactObjectMatcher_IsMatch_ByteArray()
|
||||
{
|
||||
// Assign
|
||||
object checkValue = new byte[] { 1, 2 };
|
||||
|
||||
// Act
|
||||
var matcher = new ExactObjectMatcher(new byte[] { 1, 2 });
|
||||
double result = matcher.IsMatch(checkValue);
|
||||
// Act
|
||||
var matcher = new ExactObjectMatcher(new byte[] { 1, 2 });
|
||||
double result = matcher.IsMatch(checkValue);
|
||||
|
||||
// Assert
|
||||
Check.That(result).IsEqualTo(1.0);
|
||||
}
|
||||
// Assert
|
||||
Check.That(result).IsEqualTo(1.0);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void ExactObjectMatcher_IsMatch_AcceptOnMatch()
|
||||
{
|
||||
// Assign
|
||||
object obj = new { x = 500, s = "s" };
|
||||
[Fact]
|
||||
public void ExactObjectMatcher_IsMatch_AcceptOnMatch()
|
||||
{
|
||||
// Assign
|
||||
object obj = new { x = 500, s = "s" };
|
||||
|
||||
// Act
|
||||
var matcher = new ExactObjectMatcher(obj);
|
||||
double result = matcher.IsMatch(new { x = 500, s = "s" });
|
||||
// Act
|
||||
var matcher = new ExactObjectMatcher(obj);
|
||||
double result = matcher.IsMatch(new { x = 500, s = "s" });
|
||||
|
||||
// Assert
|
||||
Check.That(result).IsEqualTo(1.0);
|
||||
}
|
||||
// Assert
|
||||
Check.That(result).IsEqualTo(1.0);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void ExactObjectMatcher_IsMatch_RejectOnMatch()
|
||||
{
|
||||
// Assign
|
||||
object obj = new { x = 500, s = "s" };
|
||||
[Fact]
|
||||
public void ExactObjectMatcher_IsMatch_RejectOnMatch()
|
||||
{
|
||||
// Assign
|
||||
object obj = new { x = 500, s = "s" };
|
||||
|
||||
// Act
|
||||
var matcher = new ExactObjectMatcher(MatchBehaviour.RejectOnMatch, obj);
|
||||
double result = matcher.IsMatch(new { x = 500, s = "s" });
|
||||
// Act
|
||||
var matcher = new ExactObjectMatcher(MatchBehaviour.RejectOnMatch, obj);
|
||||
double result = matcher.IsMatch(new { x = 500, s = "s" });
|
||||
|
||||
// Assert
|
||||
Check.That(result).IsEqualTo(0.0);
|
||||
}
|
||||
// Assert
|
||||
Check.That(result).IsEqualTo(0.0);
|
||||
}
|
||||
}
|
||||
@@ -3,164 +3,163 @@ using NFluent;
|
||||
using WireMock.Matchers;
|
||||
using Xunit;
|
||||
|
||||
namespace WireMock.Net.Tests.Matchers
|
||||
namespace WireMock.Net.Tests.Matchers;
|
||||
|
||||
public class JmesPathMatcherTests
|
||||
{
|
||||
public class JmesPathMatcherTests
|
||||
[Fact]
|
||||
public void JmesPathMatcher_GetName()
|
||||
{
|
||||
[Fact]
|
||||
public void JmesPathMatcher_GetName()
|
||||
// Assign
|
||||
var matcher = new JmesPathMatcher("X");
|
||||
|
||||
// Act
|
||||
string name = matcher.Name;
|
||||
|
||||
// Assert
|
||||
Check.That(name).Equals("JmesPathMatcher");
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void JmesPathMatcher_GetPatterns()
|
||||
{
|
||||
// Assign
|
||||
var matcher = new JmesPathMatcher("X");
|
||||
|
||||
// Act
|
||||
var patterns = matcher.GetPatterns();
|
||||
|
||||
// Assert
|
||||
Check.That(patterns).ContainsExactly("X");
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void JmesPathMatcher_IsMatch_ByteArray()
|
||||
{
|
||||
// Assign
|
||||
var bytes = new byte[0];
|
||||
var matcher = new JmesPathMatcher("");
|
||||
|
||||
// Act
|
||||
double match = matcher.IsMatch(bytes);
|
||||
|
||||
// Assert
|
||||
Check.That(match).IsEqualTo(0);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void JmesPathMatcher_IsMatch_NullString()
|
||||
{
|
||||
// Assign
|
||||
string? s = null;
|
||||
var matcher = new JmesPathMatcher("");
|
||||
|
||||
// Act
|
||||
double match = matcher.IsMatch(s);
|
||||
|
||||
// Assert
|
||||
Check.That(match).IsEqualTo(0);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void JmesPathMatcher_IsMatch_NullObject()
|
||||
{
|
||||
// Assign
|
||||
object? o = null;
|
||||
var matcher = new JmesPathMatcher("");
|
||||
|
||||
// Act
|
||||
double match = matcher.IsMatch(o);
|
||||
|
||||
// Assert
|
||||
Check.That(match).IsEqualTo(0);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void JmesPathMatcher_IsMatch_String_Exception_Mismatch()
|
||||
{
|
||||
// Assign
|
||||
var matcher = new JmesPathMatcher("xxx");
|
||||
|
||||
// Act
|
||||
double match = matcher.IsMatch("");
|
||||
|
||||
// Assert
|
||||
Check.That(match).IsEqualTo(0);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void JmesPathMatcher_IsMatch_Object_Exception_Mismatch()
|
||||
{
|
||||
// Assign
|
||||
var matcher = new JmesPathMatcher("");
|
||||
|
||||
// Act
|
||||
double match = matcher.IsMatch("x");
|
||||
|
||||
// Assert
|
||||
Check.That(match).IsEqualTo(0);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void JmesPathMatcher_IsMatch_AnonymousObject()
|
||||
{
|
||||
// Assign
|
||||
var matcher = new JmesPathMatcher("things.name == 'RequiredThing'");
|
||||
|
||||
// Act
|
||||
double match = matcher.IsMatch(new { things = new { name = "RequiredThing" } });
|
||||
|
||||
// Assert
|
||||
Check.That(match).IsEqualTo(1);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void JmesPathMatcher_IsMatch_JObject()
|
||||
{
|
||||
// Assign
|
||||
string[] patterns = { "things.x == 'RequiredThing'" };
|
||||
var matcher = new JmesPathMatcher(patterns);
|
||||
|
||||
// Act
|
||||
var sub = new JObject
|
||||
{
|
||||
// Assign
|
||||
var matcher = new JmesPathMatcher("X");
|
||||
|
||||
// Act
|
||||
string name = matcher.Name;
|
||||
|
||||
// Assert
|
||||
Check.That(name).Equals("JmesPathMatcher");
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void JmesPathMatcher_GetPatterns()
|
||||
{ "x", new JValue("RequiredThing") }
|
||||
};
|
||||
var jobject = new JObject
|
||||
{
|
||||
// Assign
|
||||
var matcher = new JmesPathMatcher("X");
|
||||
{ "Id", new JValue(1) },
|
||||
{ "things", sub }
|
||||
};
|
||||
double match = matcher.IsMatch(jobject);
|
||||
|
||||
// Act
|
||||
var patterns = matcher.GetPatterns();
|
||||
// Assert
|
||||
Check.That(match).IsEqualTo(1);
|
||||
}
|
||||
|
||||
// Assert
|
||||
Check.That(patterns).ContainsExactly("X");
|
||||
}
|
||||
[Fact]
|
||||
public void JmesPathMatcher_IsMatch_JObject_Parsed()
|
||||
{
|
||||
// Assign
|
||||
var matcher = new JmesPathMatcher("things.x == 'RequiredThing'");
|
||||
|
||||
[Fact]
|
||||
public void JmesPathMatcher_IsMatch_ByteArray()
|
||||
{
|
||||
// Assign
|
||||
var bytes = new byte[0];
|
||||
var matcher = new JmesPathMatcher("");
|
||||
// Act
|
||||
double match = matcher.IsMatch(JObject.Parse("{ \"things\": { \"x\": \"RequiredThing\" } }"));
|
||||
|
||||
// Act
|
||||
double match = matcher.IsMatch(bytes);
|
||||
// Assert
|
||||
Check.That(match).IsEqualTo(1);
|
||||
}
|
||||
|
||||
// Assert
|
||||
Check.That(match).IsEqualTo(0);
|
||||
}
|
||||
[Fact]
|
||||
public void JmesPathMatcher_IsMatch_RejectOnMatch()
|
||||
{
|
||||
// Assign
|
||||
var matcher = new JmesPathMatcher(MatchBehaviour.RejectOnMatch, false, MatchOperator.Or, "things.x == 'RequiredThing'");
|
||||
|
||||
[Fact]
|
||||
public void JmesPathMatcher_IsMatch_NullString()
|
||||
{
|
||||
// Assign
|
||||
string? s = null;
|
||||
var matcher = new JmesPathMatcher("");
|
||||
// Act
|
||||
double match = matcher.IsMatch(JObject.Parse("{ \"things\": { \"x\": \"RequiredThing\" } }"));
|
||||
|
||||
// Act
|
||||
double match = matcher.IsMatch(s);
|
||||
|
||||
// Assert
|
||||
Check.That(match).IsEqualTo(0);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void JmesPathMatcher_IsMatch_NullObject()
|
||||
{
|
||||
// Assign
|
||||
object? o = null;
|
||||
var matcher = new JmesPathMatcher("");
|
||||
|
||||
// Act
|
||||
double match = matcher.IsMatch(o);
|
||||
|
||||
// Assert
|
||||
Check.That(match).IsEqualTo(0);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void JmesPathMatcher_IsMatch_String_Exception_Mismatch()
|
||||
{
|
||||
// Assign
|
||||
var matcher = new JmesPathMatcher("xxx");
|
||||
|
||||
// Act
|
||||
double match = matcher.IsMatch("");
|
||||
|
||||
// Assert
|
||||
Check.That(match).IsEqualTo(0);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void JmesPathMatcher_IsMatch_Object_Exception_Mismatch()
|
||||
{
|
||||
// Assign
|
||||
var matcher = new JmesPathMatcher("");
|
||||
|
||||
// Act
|
||||
double match = matcher.IsMatch("x");
|
||||
|
||||
// Assert
|
||||
Check.That(match).IsEqualTo(0);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void JmesPathMatcher_IsMatch_AnonymousObject()
|
||||
{
|
||||
// Assign
|
||||
var matcher = new JmesPathMatcher("things.name == 'RequiredThing'");
|
||||
|
||||
// Act
|
||||
double match = matcher.IsMatch(new { things = new { name = "RequiredThing" } });
|
||||
|
||||
// Assert
|
||||
Check.That(match).IsEqualTo(1);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void JmesPathMatcher_IsMatch_JObject()
|
||||
{
|
||||
// Assign
|
||||
string[] patterns = { "things.x == 'RequiredThing'" };
|
||||
var matcher = new JmesPathMatcher(patterns);
|
||||
|
||||
// Act
|
||||
var sub = new JObject
|
||||
{
|
||||
{ "x", new JValue("RequiredThing") }
|
||||
};
|
||||
var jobject = new JObject
|
||||
{
|
||||
{ "Id", new JValue(1) },
|
||||
{ "things", sub }
|
||||
};
|
||||
double match = matcher.IsMatch(jobject);
|
||||
|
||||
// Assert
|
||||
Check.That(match).IsEqualTo(1);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void JmesPathMatcher_IsMatch_JObject_Parsed()
|
||||
{
|
||||
// Assign
|
||||
var matcher = new JmesPathMatcher("things.x == 'RequiredThing'");
|
||||
|
||||
// Act
|
||||
double match = matcher.IsMatch(JObject.Parse("{ \"things\": { \"x\": \"RequiredThing\" } }"));
|
||||
|
||||
// Assert
|
||||
Check.That(match).IsEqualTo(1);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void JmesPathMatcher_IsMatch_RejectOnMatch()
|
||||
{
|
||||
// Assign
|
||||
var matcher = new JmesPathMatcher(MatchBehaviour.RejectOnMatch, false, MatchOperator.Or, "things.x == 'RequiredThing'");
|
||||
|
||||
// Act
|
||||
double match = matcher.IsMatch(JObject.Parse("{ \"things\": { \"x\": \"RequiredThing\" } }"));
|
||||
|
||||
// Assert
|
||||
Check.That(match).IsEqualTo(0.0);
|
||||
}
|
||||
// Assert
|
||||
Check.That(match).IsEqualTo(0.0);
|
||||
}
|
||||
}
|
||||
@@ -7,416 +7,415 @@ using NFluent;
|
||||
using WireMock.Matchers;
|
||||
using Xunit;
|
||||
|
||||
namespace WireMock.Net.Tests.Matchers
|
||||
namespace WireMock.Net.Tests.Matchers;
|
||||
|
||||
public class JsonPartialMatcherTests
|
||||
{
|
||||
public class JsonPartialMatcherTests
|
||||
[Fact]
|
||||
public void JsonPartialMatcher_GetName()
|
||||
{
|
||||
[Fact]
|
||||
public void JsonPartialMatcher_GetName()
|
||||
{
|
||||
// Assign
|
||||
var matcher = new JsonPartialMatcher("{}");
|
||||
// Assign
|
||||
var matcher = new JsonPartialMatcher("{}");
|
||||
|
||||
// Act
|
||||
string name = matcher.Name;
|
||||
// Act
|
||||
string name = matcher.Name;
|
||||
|
||||
// Assert
|
||||
Check.That(name).Equals("JsonPartialMatcher");
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void JsonPartialMatcher_GetValue()
|
||||
{
|
||||
// Assign
|
||||
var matcher = new JsonPartialMatcher("{}");
|
||||
|
||||
// Act
|
||||
object value = matcher.Value;
|
||||
|
||||
// Assert
|
||||
Check.That(value).Equals("{}");
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void JsonPartialMatcher_WithInvalidStringValue_Should_ThrowException()
|
||||
{
|
||||
// Act
|
||||
// ReSharper disable once ObjectCreationAsStatement
|
||||
Action action = () => new JsonPartialMatcher(MatchBehaviour.AcceptOnMatch, "{ \"Id\"");
|
||||
|
||||
// Assert
|
||||
action.Should().Throw<JsonException>();
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void JsonPartialMatcher_WithInvalidObjectValue_Should_ThrowException()
|
||||
{
|
||||
// Act
|
||||
// ReSharper disable once ObjectCreationAsStatement
|
||||
Action action = () => new JsonPartialMatcher(MatchBehaviour.AcceptOnMatch, new MemoryStream());
|
||||
|
||||
// Assert
|
||||
action.Should().Throw<JsonException>();
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void JsonPartialMatcher_IsMatch_WithInvalidValue_And_ThrowExceptionIsFalse_Should_ReturnMismatch()
|
||||
{
|
||||
// Assign
|
||||
var matcher = new JsonPartialMatcher("");
|
||||
|
||||
// Act
|
||||
double match = matcher.IsMatch(new MemoryStream());
|
||||
|
||||
// Assert
|
||||
Check.That(match).IsEqualTo(0);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void JsonPartialMatcher_IsMatch_WithInvalidValue_And_ThrowExceptionIsTrue_Should_ReturnMismatch()
|
||||
{
|
||||
// Assign
|
||||
var matcher = new JsonPartialMatcher("", false, true);
|
||||
|
||||
// Act
|
||||
Action action = () => matcher.IsMatch(new MemoryStream());
|
||||
|
||||
// Assert
|
||||
action.Should().Throw<JsonException>();
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void JsonPartialMatcher_IsMatch_ByteArray()
|
||||
{
|
||||
// Assign
|
||||
var bytes = new byte[0];
|
||||
var matcher = new JsonPartialMatcher("");
|
||||
|
||||
// Act
|
||||
double match = matcher.IsMatch(bytes);
|
||||
|
||||
// Assert
|
||||
Check.That(match).IsEqualTo(0);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void JsonPartialMatcher_IsMatch_NullString()
|
||||
{
|
||||
// Assign
|
||||
string? s = null;
|
||||
var matcher = new JsonPartialMatcher("");
|
||||
|
||||
// Act
|
||||
double match = matcher.IsMatch(s);
|
||||
|
||||
// Assert
|
||||
Check.That(match).IsEqualTo(0);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void JsonPartialMatcher_IsMatch_NullObject()
|
||||
{
|
||||
// Assign
|
||||
object? o = null;
|
||||
var matcher = new JsonPartialMatcher("");
|
||||
|
||||
// Act
|
||||
double match = matcher.IsMatch(o);
|
||||
|
||||
// Assert
|
||||
Check.That(match).IsEqualTo(0);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void JsonPartialMatcher_IsMatch_JArray()
|
||||
{
|
||||
// Assign
|
||||
var matcher = new JsonPartialMatcher(new[] { "x", "y" });
|
||||
|
||||
// Act
|
||||
var jArray = new JArray
|
||||
{
|
||||
"x",
|
||||
"y"
|
||||
};
|
||||
double match = matcher.IsMatch(jArray);
|
||||
|
||||
// Assert
|
||||
Assert.Equal(1.0, match);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void JsonPartialMatcher_IsMatch_JObject()
|
||||
{
|
||||
// Assign
|
||||
var matcher = new JsonPartialMatcher(new { Id = 1, Name = "Test" });
|
||||
|
||||
// Act
|
||||
var jObject = new JObject
|
||||
{
|
||||
{ "Id", new JValue(1) },
|
||||
{ "Name", new JValue("Test") }
|
||||
};
|
||||
double match = matcher.IsMatch(jObject);
|
||||
|
||||
// Assert
|
||||
Assert.Equal(1.0, match);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void JsonPartialMatcher_IsMatch_WithRegexTrue()
|
||||
{
|
||||
// Assign
|
||||
var matcher = new JsonPartialMatcher(new { Id = "^\\d+$", Name = "Test" }, false, false, true);
|
||||
|
||||
// Act
|
||||
var jObject = new JObject
|
||||
{
|
||||
{ "Id", new JValue(1) },
|
||||
{ "Name", new JValue("Test") }
|
||||
};
|
||||
double match = matcher.IsMatch(jObject);
|
||||
|
||||
// Assert
|
||||
Assert.Equal(1.0, match);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void JsonPartialMatcher_IsMatch_WithRegexFalse()
|
||||
{
|
||||
// Assign
|
||||
var matcher = new JsonPartialMatcher(new { Id = "^\\d+$", Name = "Test" });
|
||||
|
||||
// Act
|
||||
var jObject = new JObject
|
||||
{
|
||||
{ "Id", new JValue(1) },
|
||||
{ "Name", new JValue("Test") }
|
||||
};
|
||||
double match = matcher.IsMatch(jObject);
|
||||
|
||||
// Assert
|
||||
Assert.Equal(0.0, match);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void JsonPartialMatcher_IsMatch_WithIgnoreCaseTrue_JObject()
|
||||
{
|
||||
// Assign
|
||||
var matcher = new JsonPartialMatcher(new { id = 1, Name = "test" }, true);
|
||||
|
||||
// Act
|
||||
var jObject = new JObject
|
||||
{
|
||||
{ "Id", new JValue(1) },
|
||||
{ "NaMe", new JValue("Test") }
|
||||
};
|
||||
double match = matcher.IsMatch(jObject);
|
||||
|
||||
// Assert
|
||||
Assert.Equal(1.0, match);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void JsonPartialMatcher_IsMatch_JObjectParsed()
|
||||
{
|
||||
// Assign
|
||||
var matcher = new JsonPartialMatcher(new { Id = 1, Name = "Test" });
|
||||
|
||||
// Act
|
||||
var jObject = JObject.Parse("{ \"Id\" : 1, \"Name\" : \"Test\" }");
|
||||
double match = matcher.IsMatch(jObject);
|
||||
|
||||
// Assert
|
||||
Assert.Equal(1.0, match);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void JsonPartialMatcher_IsMatch_WithIgnoreCaseTrue_JObjectParsed()
|
||||
{
|
||||
// Assign
|
||||
var matcher = new JsonPartialMatcher(new { Id = 1, Name = "TESt" }, true);
|
||||
|
||||
// Act
|
||||
var jObject = JObject.Parse("{ \"Id\" : 1, \"Name\" : \"Test\" }");
|
||||
double match = matcher.IsMatch(jObject);
|
||||
|
||||
// Assert
|
||||
Assert.Equal(1.0, match);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void JsonPartialMatcher_IsMatch_JArrayAsString()
|
||||
{
|
||||
// Assign
|
||||
var matcher = new JsonPartialMatcher("[ \"x\", \"y\" ]");
|
||||
|
||||
// Act
|
||||
var jArray = new JArray
|
||||
{
|
||||
"x",
|
||||
"y"
|
||||
};
|
||||
double match = matcher.IsMatch(jArray);
|
||||
|
||||
// Assert
|
||||
Assert.Equal(1.0, match);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void JsonPartialMatcher_IsMatch_JObjectAsString()
|
||||
{
|
||||
// Assign
|
||||
var matcher = new JsonPartialMatcher("{ \"Id\" : 1, \"Name\" : \"Test\" }");
|
||||
|
||||
// Act
|
||||
var jObject = new JObject
|
||||
{
|
||||
{ "Id", new JValue(1) },
|
||||
{ "Name", new JValue("Test") }
|
||||
};
|
||||
double match = matcher.IsMatch(jObject);
|
||||
|
||||
// Assert
|
||||
Assert.Equal(1.0, match);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void JsonPartialMatcher_IsMatch_WithIgnoreCaseTrue_JObjectAsString()
|
||||
{
|
||||
// Assign
|
||||
var matcher = new JsonPartialMatcher("{ \"Id\" : 1, \"Name\" : \"test\" }", true);
|
||||
|
||||
// Act
|
||||
var jObject = new JObject
|
||||
{
|
||||
{ "Id", new JValue(1) },
|
||||
{ "Name", new JValue("Test") }
|
||||
};
|
||||
double match = matcher.IsMatch(jObject);
|
||||
|
||||
// Assert
|
||||
Assert.Equal(1.0, match);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void JsonPartialMatcher_IsMatch_JObjectAsString_RejectOnMatch()
|
||||
{
|
||||
// Assign
|
||||
var matcher = new JsonPartialMatcher(MatchBehaviour.RejectOnMatch, "{ \"Id\" : 1, \"Name\" : \"Test\" }");
|
||||
|
||||
// Act
|
||||
var jObject = new JObject
|
||||
{
|
||||
{ "Id", new JValue(1) },
|
||||
{ "Name", new JValue("Test") }
|
||||
};
|
||||
double match = matcher.IsMatch(jObject);
|
||||
|
||||
// Assert
|
||||
Assert.Equal(0.0, match);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void JsonPartialMatcher_IsMatch_JObjectWithDateTimeOffsetAsString()
|
||||
{
|
||||
// Assign
|
||||
var matcher = new JsonPartialMatcher("{ \"preferredAt\" : \"2019-11-21T10:32:53.2210009+00:00\" }");
|
||||
|
||||
// Act
|
||||
var jObject = new JObject
|
||||
{
|
||||
{ "preferredAt", new JValue("2019-11-21T10:32:53.2210009+00:00") }
|
||||
};
|
||||
double match = matcher.IsMatch(jObject);
|
||||
|
||||
// Assert
|
||||
Assert.Equal(1.0, match);
|
||||
}
|
||||
|
||||
[Theory]
|
||||
[InlineData("{\"test\":\"abc\"}", "{\"test\":\"abc\",\"other\":\"xyz\"}")]
|
||||
[InlineData("\"test\"", "\"test\"")]
|
||||
[InlineData("123", "123")]
|
||||
[InlineData("[\"test\"]", "[\"test\"]")]
|
||||
[InlineData("[\"test\"]", "[\"test\", \"other\"]")]
|
||||
[InlineData("[123]", "[123]")]
|
||||
[InlineData("[123]", "[123, 456]")]
|
||||
[InlineData("{ \"test\":\"value\" }", "{\"test\":\"value\",\"other\":123}")]
|
||||
[InlineData("{ \"test\":\"value\" }", "{\"test\":\"value\"}")]
|
||||
[InlineData("{\"test\":{\"nested\":\"value\"}}", "{\"test\":{\"nested\":\"value\"}}")]
|
||||
public void JsonPartialMatcher_IsMatch_StringInputValidMatch(string value, string input)
|
||||
{
|
||||
// Assign
|
||||
var matcher = new JsonPartialMatcher(value);
|
||||
|
||||
// Act
|
||||
double match = matcher.IsMatch(input);
|
||||
|
||||
// Assert
|
||||
Assert.Equal(1.0, match);
|
||||
}
|
||||
|
||||
[Theory]
|
||||
[InlineData("\"test\"", null)]
|
||||
[InlineData("\"test1\"", "\"test2\"")]
|
||||
[InlineData("123", "1234")]
|
||||
[InlineData("[\"test\"]", "[\"test1\"]")]
|
||||
[InlineData("[\"test\"]", "[\"test1\", \"test2\"]")]
|
||||
[InlineData("[123]", "[1234]")]
|
||||
[InlineData("{}", "\"test\"")]
|
||||
[InlineData("{ \"test\":\"value\" }", "{\"test\":\"value2\"}")]
|
||||
[InlineData("{ \"test.nested\":\"value\" }", "{\"test\":{\"nested\":\"value1\"}}")]
|
||||
[InlineData("{\"test\":{\"test1\":\"value\"}}", "{\"test\":{\"test1\":\"value1\"}}")]
|
||||
[InlineData("[{ \"test.nested\":\"value\" }]", "[{\"test\":{\"nested\":\"value1\"}}]")]
|
||||
public void JsonPartialMatcher_IsMatch_StringInputWithInvalidMatch(string value, string input)
|
||||
{
|
||||
// Assign
|
||||
var matcher = new JsonPartialMatcher(value);
|
||||
|
||||
// Act
|
||||
double match = matcher.IsMatch(input);
|
||||
|
||||
// Assert
|
||||
Assert.Equal(0.0, match);
|
||||
}
|
||||
|
||||
[Theory]
|
||||
[InlineData("{ \"test.nested\":123 }", "{\"test\":{\"nested\":123}}")]
|
||||
[InlineData("{ \"test.nested\":[123, 456] }", "{\"test\":{\"nested\":[123, 456]}}")]
|
||||
[InlineData("{ \"test.nested\":\"value\" }", "{\"test\":{\"nested\":\"value\"}}")]
|
||||
[InlineData("{ \"['name.with.dot']\":\"value\" }", "{\"name.with.dot\":\"value\"}")]
|
||||
[InlineData("[{ \"test.nested\":\"value\" }]", "[{\"test\":{\"nested\":\"value\"}}]")]
|
||||
[InlineData("[{ \"['name.with.dot']\":\"value\" }]", "[{\"name.with.dot\":\"value\"}]")]
|
||||
public void JsonPartialMatcher_IsMatch_ValueAsJPathValidMatch(string value, string input)
|
||||
{
|
||||
// Assign
|
||||
var matcher = new JsonPartialMatcher(value);
|
||||
|
||||
// Act
|
||||
double match = matcher.IsMatch(input);
|
||||
|
||||
// Assert
|
||||
Assert.Equal(1.0, match);
|
||||
}
|
||||
|
||||
[Theory]
|
||||
[InlineData("{ \"test.nested\":123 }", "{\"test\":{\"nested\":456}}")]
|
||||
[InlineData("{ \"test.nested\":[123, 456] }", "{\"test\":{\"nested\":[1, 2]}}")]
|
||||
[InlineData("{ \"test.nested\":\"value\" }", "{\"test\":{\"nested\":\"value1\"}}")]
|
||||
[InlineData("{ \"['name.with.dot']\":\"value\" }", "{\"name.with.dot\":\"value1\"}")]
|
||||
[InlineData("[{ \"test.nested\":\"value\" }]", "[{\"test\":{\"nested\":\"value1\"}}]")]
|
||||
[InlineData("[{ \"['name.with.dot']\":\"value\" }]", "[{\"name.with.dot\":\"value1\"}]")]
|
||||
public void JsonPartialMatcher_IsMatch_ValueAsJPathInvalidMatch(string value, string input)
|
||||
{
|
||||
// Assign
|
||||
var matcher = new JsonPartialMatcher(value);
|
||||
|
||||
// Act
|
||||
double match = matcher.IsMatch(input);
|
||||
|
||||
// Assert
|
||||
Assert.Equal(0.0, match);
|
||||
}
|
||||
// Assert
|
||||
Check.That(name).Equals("JsonPartialMatcher");
|
||||
}
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void JsonPartialMatcher_GetValue()
|
||||
{
|
||||
// Assign
|
||||
var matcher = new JsonPartialMatcher("{}");
|
||||
|
||||
// Act
|
||||
object value = matcher.Value;
|
||||
|
||||
// Assert
|
||||
Check.That(value).Equals("{}");
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void JsonPartialMatcher_WithInvalidStringValue_Should_ThrowException()
|
||||
{
|
||||
// Act
|
||||
// ReSharper disable once ObjectCreationAsStatement
|
||||
Action action = () => new JsonPartialMatcher(MatchBehaviour.AcceptOnMatch, "{ \"Id\"");
|
||||
|
||||
// Assert
|
||||
action.Should().Throw<JsonException>();
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void JsonPartialMatcher_WithInvalidObjectValue_Should_ThrowException()
|
||||
{
|
||||
// Act
|
||||
// ReSharper disable once ObjectCreationAsStatement
|
||||
Action action = () => new JsonPartialMatcher(MatchBehaviour.AcceptOnMatch, new MemoryStream());
|
||||
|
||||
// Assert
|
||||
action.Should().Throw<JsonException>();
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void JsonPartialMatcher_IsMatch_WithInvalidValue_And_ThrowExceptionIsFalse_Should_ReturnMismatch()
|
||||
{
|
||||
// Assign
|
||||
var matcher = new JsonPartialMatcher("");
|
||||
|
||||
// Act
|
||||
double match = matcher.IsMatch(new MemoryStream());
|
||||
|
||||
// Assert
|
||||
Check.That(match).IsEqualTo(0);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void JsonPartialMatcher_IsMatch_WithInvalidValue_And_ThrowExceptionIsTrue_Should_ReturnMismatch()
|
||||
{
|
||||
// Assign
|
||||
var matcher = new JsonPartialMatcher("", false, true);
|
||||
|
||||
// Act
|
||||
Action action = () => matcher.IsMatch(new MemoryStream());
|
||||
|
||||
// Assert
|
||||
action.Should().Throw<JsonException>();
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void JsonPartialMatcher_IsMatch_ByteArray()
|
||||
{
|
||||
// Assign
|
||||
var bytes = new byte[0];
|
||||
var matcher = new JsonPartialMatcher("");
|
||||
|
||||
// Act
|
||||
double match = matcher.IsMatch(bytes);
|
||||
|
||||
// Assert
|
||||
Check.That(match).IsEqualTo(0);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void JsonPartialMatcher_IsMatch_NullString()
|
||||
{
|
||||
// Assign
|
||||
string? s = null;
|
||||
var matcher = new JsonPartialMatcher("");
|
||||
|
||||
// Act
|
||||
double match = matcher.IsMatch(s);
|
||||
|
||||
// Assert
|
||||
Check.That(match).IsEqualTo(0);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void JsonPartialMatcher_IsMatch_NullObject()
|
||||
{
|
||||
// Assign
|
||||
object? o = null;
|
||||
var matcher = new JsonPartialMatcher("");
|
||||
|
||||
// Act
|
||||
double match = matcher.IsMatch(o);
|
||||
|
||||
// Assert
|
||||
Check.That(match).IsEqualTo(0);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void JsonPartialMatcher_IsMatch_JArray()
|
||||
{
|
||||
// Assign
|
||||
var matcher = new JsonPartialMatcher(new[] { "x", "y" });
|
||||
|
||||
// Act
|
||||
var jArray = new JArray
|
||||
{
|
||||
"x",
|
||||
"y"
|
||||
};
|
||||
double match = matcher.IsMatch(jArray);
|
||||
|
||||
// Assert
|
||||
Assert.Equal(1.0, match);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void JsonPartialMatcher_IsMatch_JObject()
|
||||
{
|
||||
// Assign
|
||||
var matcher = new JsonPartialMatcher(new { Id = 1, Name = "Test" });
|
||||
|
||||
// Act
|
||||
var jObject = new JObject
|
||||
{
|
||||
{ "Id", new JValue(1) },
|
||||
{ "Name", new JValue("Test") }
|
||||
};
|
||||
double match = matcher.IsMatch(jObject);
|
||||
|
||||
// Assert
|
||||
Assert.Equal(1.0, match);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void JsonPartialMatcher_IsMatch_WithRegexTrue()
|
||||
{
|
||||
// Assign
|
||||
var matcher = new JsonPartialMatcher(new { Id = "^\\d+$", Name = "Test" }, false, false, true);
|
||||
|
||||
// Act
|
||||
var jObject = new JObject
|
||||
{
|
||||
{ "Id", new JValue(1) },
|
||||
{ "Name", new JValue("Test") }
|
||||
};
|
||||
double match = matcher.IsMatch(jObject);
|
||||
|
||||
// Assert
|
||||
Assert.Equal(1.0, match);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void JsonPartialMatcher_IsMatch_WithRegexFalse()
|
||||
{
|
||||
// Assign
|
||||
var matcher = new JsonPartialMatcher(new { Id = "^\\d+$", Name = "Test" });
|
||||
|
||||
// Act
|
||||
var jObject = new JObject
|
||||
{
|
||||
{ "Id", new JValue(1) },
|
||||
{ "Name", new JValue("Test") }
|
||||
};
|
||||
double match = matcher.IsMatch(jObject);
|
||||
|
||||
// Assert
|
||||
Assert.Equal(0.0, match);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void JsonPartialMatcher_IsMatch_WithIgnoreCaseTrue_JObject()
|
||||
{
|
||||
// Assign
|
||||
var matcher = new JsonPartialMatcher(new { id = 1, Name = "test" }, true);
|
||||
|
||||
// Act
|
||||
var jObject = new JObject
|
||||
{
|
||||
{ "Id", new JValue(1) },
|
||||
{ "NaMe", new JValue("Test") }
|
||||
};
|
||||
double match = matcher.IsMatch(jObject);
|
||||
|
||||
// Assert
|
||||
Assert.Equal(1.0, match);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void JsonPartialMatcher_IsMatch_JObjectParsed()
|
||||
{
|
||||
// Assign
|
||||
var matcher = new JsonPartialMatcher(new { Id = 1, Name = "Test" });
|
||||
|
||||
// Act
|
||||
var jObject = JObject.Parse("{ \"Id\" : 1, \"Name\" : \"Test\" }");
|
||||
double match = matcher.IsMatch(jObject);
|
||||
|
||||
// Assert
|
||||
Assert.Equal(1.0, match);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void JsonPartialMatcher_IsMatch_WithIgnoreCaseTrue_JObjectParsed()
|
||||
{
|
||||
// Assign
|
||||
var matcher = new JsonPartialMatcher(new { Id = 1, Name = "TESt" }, true);
|
||||
|
||||
// Act
|
||||
var jObject = JObject.Parse("{ \"Id\" : 1, \"Name\" : \"Test\" }");
|
||||
double match = matcher.IsMatch(jObject);
|
||||
|
||||
// Assert
|
||||
Assert.Equal(1.0, match);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void JsonPartialMatcher_IsMatch_JArrayAsString()
|
||||
{
|
||||
// Assign
|
||||
var matcher = new JsonPartialMatcher("[ \"x\", \"y\" ]");
|
||||
|
||||
// Act
|
||||
var jArray = new JArray
|
||||
{
|
||||
"x",
|
||||
"y"
|
||||
};
|
||||
double match = matcher.IsMatch(jArray);
|
||||
|
||||
// Assert
|
||||
Assert.Equal(1.0, match);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void JsonPartialMatcher_IsMatch_JObjectAsString()
|
||||
{
|
||||
// Assign
|
||||
var matcher = new JsonPartialMatcher("{ \"Id\" : 1, \"Name\" : \"Test\" }");
|
||||
|
||||
// Act
|
||||
var jObject = new JObject
|
||||
{
|
||||
{ "Id", new JValue(1) },
|
||||
{ "Name", new JValue("Test") }
|
||||
};
|
||||
double match = matcher.IsMatch(jObject);
|
||||
|
||||
// Assert
|
||||
Assert.Equal(1.0, match);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void JsonPartialMatcher_IsMatch_WithIgnoreCaseTrue_JObjectAsString()
|
||||
{
|
||||
// Assign
|
||||
var matcher = new JsonPartialMatcher("{ \"Id\" : 1, \"Name\" : \"test\" }", true);
|
||||
|
||||
// Act
|
||||
var jObject = new JObject
|
||||
{
|
||||
{ "Id", new JValue(1) },
|
||||
{ "Name", new JValue("Test") }
|
||||
};
|
||||
double match = matcher.IsMatch(jObject);
|
||||
|
||||
// Assert
|
||||
Assert.Equal(1.0, match);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void JsonPartialMatcher_IsMatch_JObjectAsString_RejectOnMatch()
|
||||
{
|
||||
// Assign
|
||||
var matcher = new JsonPartialMatcher(MatchBehaviour.RejectOnMatch, "{ \"Id\" : 1, \"Name\" : \"Test\" }");
|
||||
|
||||
// Act
|
||||
var jObject = new JObject
|
||||
{
|
||||
{ "Id", new JValue(1) },
|
||||
{ "Name", new JValue("Test") }
|
||||
};
|
||||
double match = matcher.IsMatch(jObject);
|
||||
|
||||
// Assert
|
||||
Assert.Equal(0.0, match);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void JsonPartialMatcher_IsMatch_JObjectWithDateTimeOffsetAsString()
|
||||
{
|
||||
// Assign
|
||||
var matcher = new JsonPartialMatcher("{ \"preferredAt\" : \"2019-11-21T10:32:53.2210009+00:00\" }");
|
||||
|
||||
// Act
|
||||
var jObject = new JObject
|
||||
{
|
||||
{ "preferredAt", new JValue("2019-11-21T10:32:53.2210009+00:00") }
|
||||
};
|
||||
double match = matcher.IsMatch(jObject);
|
||||
|
||||
// Assert
|
||||
Assert.Equal(1.0, match);
|
||||
}
|
||||
|
||||
[Theory]
|
||||
[InlineData("{\"test\":\"abc\"}", "{\"test\":\"abc\",\"other\":\"xyz\"}")]
|
||||
[InlineData("\"test\"", "\"test\"")]
|
||||
[InlineData("123", "123")]
|
||||
[InlineData("[\"test\"]", "[\"test\"]")]
|
||||
[InlineData("[\"test\"]", "[\"test\", \"other\"]")]
|
||||
[InlineData("[123]", "[123]")]
|
||||
[InlineData("[123]", "[123, 456]")]
|
||||
[InlineData("{ \"test\":\"value\" }", "{\"test\":\"value\",\"other\":123}")]
|
||||
[InlineData("{ \"test\":\"value\" }", "{\"test\":\"value\"}")]
|
||||
[InlineData("{\"test\":{\"nested\":\"value\"}}", "{\"test\":{\"nested\":\"value\"}}")]
|
||||
public void JsonPartialMatcher_IsMatch_StringInputValidMatch(string value, string input)
|
||||
{
|
||||
// Assign
|
||||
var matcher = new JsonPartialMatcher(value);
|
||||
|
||||
// Act
|
||||
double match = matcher.IsMatch(input);
|
||||
|
||||
// Assert
|
||||
Assert.Equal(1.0, match);
|
||||
}
|
||||
|
||||
[Theory]
|
||||
[InlineData("\"test\"", null)]
|
||||
[InlineData("\"test1\"", "\"test2\"")]
|
||||
[InlineData("123", "1234")]
|
||||
[InlineData("[\"test\"]", "[\"test1\"]")]
|
||||
[InlineData("[\"test\"]", "[\"test1\", \"test2\"]")]
|
||||
[InlineData("[123]", "[1234]")]
|
||||
[InlineData("{}", "\"test\"")]
|
||||
[InlineData("{ \"test\":\"value\" }", "{\"test\":\"value2\"}")]
|
||||
[InlineData("{ \"test.nested\":\"value\" }", "{\"test\":{\"nested\":\"value1\"}}")]
|
||||
[InlineData("{\"test\":{\"test1\":\"value\"}}", "{\"test\":{\"test1\":\"value1\"}}")]
|
||||
[InlineData("[{ \"test.nested\":\"value\" }]", "[{\"test\":{\"nested\":\"value1\"}}]")]
|
||||
public void JsonPartialMatcher_IsMatch_StringInputWithInvalidMatch(string value, string input)
|
||||
{
|
||||
// Assign
|
||||
var matcher = new JsonPartialMatcher(value);
|
||||
|
||||
// Act
|
||||
double match = matcher.IsMatch(input);
|
||||
|
||||
// Assert
|
||||
Assert.Equal(0.0, match);
|
||||
}
|
||||
|
||||
[Theory]
|
||||
[InlineData("{ \"test.nested\":123 }", "{\"test\":{\"nested\":123}}")]
|
||||
[InlineData("{ \"test.nested\":[123, 456] }", "{\"test\":{\"nested\":[123, 456]}}")]
|
||||
[InlineData("{ \"test.nested\":\"value\" }", "{\"test\":{\"nested\":\"value\"}}")]
|
||||
[InlineData("{ \"['name.with.dot']\":\"value\" }", "{\"name.with.dot\":\"value\"}")]
|
||||
[InlineData("[{ \"test.nested\":\"value\" }]", "[{\"test\":{\"nested\":\"value\"}}]")]
|
||||
[InlineData("[{ \"['name.with.dot']\":\"value\" }]", "[{\"name.with.dot\":\"value\"}]")]
|
||||
public void JsonPartialMatcher_IsMatch_ValueAsJPathValidMatch(string value, string input)
|
||||
{
|
||||
// Assign
|
||||
var matcher = new JsonPartialMatcher(value);
|
||||
|
||||
// Act
|
||||
double match = matcher.IsMatch(input);
|
||||
|
||||
// Assert
|
||||
Assert.Equal(1.0, match);
|
||||
}
|
||||
|
||||
[Theory]
|
||||
[InlineData("{ \"test.nested\":123 }", "{\"test\":{\"nested\":456}}")]
|
||||
[InlineData("{ \"test.nested\":[123, 456] }", "{\"test\":{\"nested\":[1, 2]}}")]
|
||||
[InlineData("{ \"test.nested\":\"value\" }", "{\"test\":{\"nested\":\"value1\"}}")]
|
||||
[InlineData("{ \"['name.with.dot']\":\"value\" }", "{\"name.with.dot\":\"value1\"}")]
|
||||
[InlineData("[{ \"test.nested\":\"value\" }]", "[{\"test\":{\"nested\":\"value1\"}}]")]
|
||||
[InlineData("[{ \"['name.with.dot']\":\"value\" }]", "[{\"name.with.dot\":\"value1\"}]")]
|
||||
public void JsonPartialMatcher_IsMatch_ValueAsJPathInvalidMatch(string value, string input)
|
||||
{
|
||||
// Assign
|
||||
var matcher = new JsonPartialMatcher(value);
|
||||
|
||||
// Act
|
||||
double match = matcher.IsMatch(input);
|
||||
|
||||
// Assert
|
||||
Assert.Equal(0.0, match);
|
||||
}
|
||||
}
|
||||
@@ -3,110 +3,109 @@ using NFluent;
|
||||
using WireMock.Matchers;
|
||||
using Xunit;
|
||||
|
||||
namespace WireMock.Net.Tests.Matchers
|
||||
namespace WireMock.Net.Tests.Matchers;
|
||||
|
||||
public class LinqMatcherTests
|
||||
{
|
||||
public class LinqMatcherTests
|
||||
[Fact]
|
||||
public void LinqMatcher_For_String_SinglePattern_IsMatch_Positive()
|
||||
{
|
||||
[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
|
||||
Check.That(matcher.IsMatch(input)).IsEqualTo(1.0d);
|
||||
}
|
||||
|
||||
[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
|
||||
Check.That(matcher.IsMatch(input)).IsEqualTo(0.0d);
|
||||
}
|
||||
|
||||
[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
|
||||
Check.That(matcher.IsMatch(input)).IsEqualTo(0.0d);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void LinqMatcher_For_Object_IsMatch()
|
||||
{
|
||||
// Assign
|
||||
var input = new
|
||||
{
|
||||
// Assign
|
||||
string input = "2018-08-31 13:59:59";
|
||||
Id = 9,
|
||||
Name = "Test"
|
||||
};
|
||||
|
||||
// Act
|
||||
var matcher = new LinqMatcher("DateTime.Parse(it) > \"2018-08-01 13:50:00\"");
|
||||
// Act
|
||||
var matcher = new LinqMatcher("Id > 1 AND Name == \"Test\"");
|
||||
double match = matcher.IsMatch(input);
|
||||
|
||||
// Assert
|
||||
Check.That(matcher.IsMatch(input)).IsEqualTo(1.0d);
|
||||
}
|
||||
// Assert
|
||||
Assert.Equal(1.0, match);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void LinqMatcher_For_String_IsMatch_Negative()
|
||||
[Fact]
|
||||
public void LinqMatcher_For_JObject_IsMatch()
|
||||
{
|
||||
// Assign
|
||||
var input = new JObject
|
||||
{
|
||||
// Assign
|
||||
string input = "2018-08-31 13:59:59";
|
||||
{ "IntegerId", new JValue(9) },
|
||||
{ "LongId", new JValue(long.MaxValue) },
|
||||
{ "Name", new JValue("Test") }
|
||||
};
|
||||
|
||||
// Act
|
||||
var matcher = new LinqMatcher("DateTime.Parse(it) > \"2019-01-01 00:00:00\"");
|
||||
// Act
|
||||
var matcher = new LinqMatcher("IntegerId > 1 AND LongId > 1 && Name == \"Test\"");
|
||||
double match = matcher.IsMatch(input);
|
||||
|
||||
// Assert
|
||||
Check.That(matcher.IsMatch(input)).IsEqualTo(0.0d);
|
||||
}
|
||||
// Assert
|
||||
Assert.Equal(1.0, match);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void LinqMatcher_For_String_IsMatch_RejectOnMatch()
|
||||
{
|
||||
// Assign
|
||||
string input = "2018-08-31 13:59:59";
|
||||
[Fact]
|
||||
public void LinqMatcher_GetName()
|
||||
{
|
||||
// Assign
|
||||
var matcher = new LinqMatcher("x");
|
||||
|
||||
// Act
|
||||
var matcher = new LinqMatcher(MatchBehaviour.RejectOnMatch, "DateTime.Parse(it) > \"2018-08-01 13:50:00\"");
|
||||
// Act
|
||||
string name = matcher.Name;
|
||||
|
||||
// Assert
|
||||
Check.That(matcher.IsMatch(input)).IsEqualTo(0.0d);
|
||||
}
|
||||
// Assert
|
||||
Check.That(name).Equals("LinqMatcher");
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void LinqMatcher_For_Object_IsMatch()
|
||||
{
|
||||
// Assign
|
||||
var input = new
|
||||
{
|
||||
Id = 9,
|
||||
Name = "Test"
|
||||
};
|
||||
[Fact]
|
||||
public void LinqMatcher_GetPatterns()
|
||||
{
|
||||
// Assign
|
||||
var matcher = new LinqMatcher("x");
|
||||
|
||||
// Act
|
||||
var matcher = new LinqMatcher("Id > 1 AND Name == \"Test\"");
|
||||
double match = matcher.IsMatch(input);
|
||||
// Act
|
||||
var patterns = matcher.GetPatterns();
|
||||
|
||||
// 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);
|
||||
|
||||
// Assert
|
||||
Assert.Equal(1.0, match);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void LinqMatcher_GetName()
|
||||
{
|
||||
// Assign
|
||||
var matcher = new LinqMatcher("x");
|
||||
|
||||
// Act
|
||||
string name = matcher.Name;
|
||||
|
||||
// Assert
|
||||
Check.That(name).Equals("LinqMatcher");
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void LinqMatcher_GetPatterns()
|
||||
{
|
||||
// Assign
|
||||
var matcher = new LinqMatcher("x");
|
||||
|
||||
// Act
|
||||
var patterns = matcher.GetPatterns();
|
||||
|
||||
// Assert
|
||||
Check.That(patterns).ContainsExactly("x");
|
||||
}
|
||||
// Assert
|
||||
Check.That(patterns).ContainsExactly("x");
|
||||
}
|
||||
}
|
||||
@@ -1,25 +1,24 @@
|
||||
using NFluent;
|
||||
using NFluent;
|
||||
using WireMock.Matchers;
|
||||
using Xunit;
|
||||
|
||||
namespace WireMock.Net.Tests.Matchers
|
||||
{
|
||||
public class MatchBehaviourHelperTests
|
||||
{
|
||||
[Fact]
|
||||
public void MatchBehaviourHelper_Convert_AcceptOnMatch()
|
||||
{
|
||||
Check.That(MatchBehaviourHelper.Convert(MatchBehaviour.AcceptOnMatch, 0.0)).IsEqualTo(0.0);
|
||||
Check.That(MatchBehaviourHelper.Convert(MatchBehaviour.AcceptOnMatch, 0.5)).IsEqualTo(0.5);
|
||||
Check.That(MatchBehaviourHelper.Convert(MatchBehaviour.AcceptOnMatch, 1.0)).IsEqualTo(1.0);
|
||||
}
|
||||
namespace WireMock.Net.Tests.Matchers;
|
||||
|
||||
[Fact]
|
||||
public void MatchBehaviourHelper_Convert_RejectOnMatch()
|
||||
{
|
||||
Check.That(MatchBehaviourHelper.Convert(MatchBehaviour.RejectOnMatch, 0.0)).IsEqualTo(1.0);
|
||||
Check.That(MatchBehaviourHelper.Convert(MatchBehaviour.RejectOnMatch, 0.5)).IsEqualTo(0.0);
|
||||
Check.That(MatchBehaviourHelper.Convert(MatchBehaviour.RejectOnMatch, 1.0)).IsEqualTo(0.0);
|
||||
}
|
||||
public class MatchBehaviourHelperTests
|
||||
{
|
||||
[Fact]
|
||||
public void MatchBehaviourHelper_Convert_AcceptOnMatch()
|
||||
{
|
||||
Check.That(MatchBehaviourHelper.Convert(MatchBehaviour.AcceptOnMatch, 0.0)).IsEqualTo(0.0);
|
||||
Check.That(MatchBehaviourHelper.Convert(MatchBehaviour.AcceptOnMatch, 0.5)).IsEqualTo(0.5);
|
||||
Check.That(MatchBehaviourHelper.Convert(MatchBehaviour.AcceptOnMatch, 1.0)).IsEqualTo(1.0);
|
||||
}
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void MatchBehaviourHelper_Convert_RejectOnMatch()
|
||||
{
|
||||
Check.That(MatchBehaviourHelper.Convert(MatchBehaviour.RejectOnMatch, 0.0)).IsEqualTo(1.0);
|
||||
Check.That(MatchBehaviourHelper.Convert(MatchBehaviour.RejectOnMatch, 0.5)).IsEqualTo(0.0);
|
||||
Check.That(MatchBehaviourHelper.Convert(MatchBehaviour.RejectOnMatch, 1.0)).IsEqualTo(0.0);
|
||||
}
|
||||
}
|
||||
@@ -3,82 +3,81 @@ using NFluent;
|
||||
using WireMock.Matchers;
|
||||
using Xunit;
|
||||
|
||||
namespace WireMock.Net.Tests.Matchers
|
||||
namespace WireMock.Net.Tests.Matchers;
|
||||
|
||||
public class NotNullOrEmptyMatcherTests
|
||||
{
|
||||
public class NotNullOrEmptyMatcherTests
|
||||
[Fact]
|
||||
public void NotNullOrEmptyMatcher_GetName()
|
||||
{
|
||||
[Fact]
|
||||
public void NotNullOrEmptyMatcher_GetName()
|
||||
{
|
||||
// Act
|
||||
var matcher = new NotNullOrEmptyMatcher();
|
||||
string name = matcher.Name;
|
||||
// Act
|
||||
var matcher = new NotNullOrEmptyMatcher();
|
||||
string name = matcher.Name;
|
||||
|
||||
// Assert
|
||||
Check.That(name).Equals("NotNullOrEmptyMatcher");
|
||||
}
|
||||
// Assert
|
||||
Check.That(name).Equals("NotNullOrEmptyMatcher");
|
||||
}
|
||||
|
||||
[Theory]
|
||||
[InlineData(null, 0.0)]
|
||||
[InlineData(new byte[0], 0.0)]
|
||||
[InlineData(new byte[] { 48 }, 1.0)]
|
||||
public void NotNullOrEmptyMatcher_IsMatch_ByteArray(byte[] data, double expected)
|
||||
{
|
||||
// Act
|
||||
var matcher = new NotNullOrEmptyMatcher();
|
||||
double result = matcher.IsMatch(data);
|
||||
[Theory]
|
||||
[InlineData(null, 0.0)]
|
||||
[InlineData(new byte[0], 0.0)]
|
||||
[InlineData(new byte[] { 48 }, 1.0)]
|
||||
public void NotNullOrEmptyMatcher_IsMatch_ByteArray(byte[] data, double expected)
|
||||
{
|
||||
// Act
|
||||
var matcher = new NotNullOrEmptyMatcher();
|
||||
double result = matcher.IsMatch(data);
|
||||
|
||||
// Assert
|
||||
result.Should().Be(expected);
|
||||
}
|
||||
// Assert
|
||||
result.Should().Be(expected);
|
||||
}
|
||||
|
||||
[Theory]
|
||||
[InlineData(null, 0.0)]
|
||||
[InlineData("", 0.0)]
|
||||
[InlineData("x", 1.0)]
|
||||
public void NotNullOrEmptyMatcher_IsMatch_String(string @string, double expected)
|
||||
{
|
||||
// Act
|
||||
var matcher = new NotNullOrEmptyMatcher();
|
||||
double result = matcher.IsMatch(@string);
|
||||
[Theory]
|
||||
[InlineData(null, 0.0)]
|
||||
[InlineData("", 0.0)]
|
||||
[InlineData("x", 1.0)]
|
||||
public void NotNullOrEmptyMatcher_IsMatch_String(string @string, double expected)
|
||||
{
|
||||
// Act
|
||||
var matcher = new NotNullOrEmptyMatcher();
|
||||
double result = matcher.IsMatch(@string);
|
||||
|
||||
// Assert
|
||||
result.Should().Be(expected);
|
||||
}
|
||||
// Assert
|
||||
result.Should().Be(expected);
|
||||
}
|
||||
|
||||
[Theory]
|
||||
[InlineData(null, 0.0)]
|
||||
[InlineData("", 0.0)]
|
||||
[InlineData("x", 1.0)]
|
||||
public void NotNullOrEmptyMatcher_IsMatch_StringAsObject(string @string, double expected)
|
||||
{
|
||||
// Act
|
||||
var matcher = new NotNullOrEmptyMatcher();
|
||||
double result = matcher.IsMatch((object)@string);
|
||||
[Theory]
|
||||
[InlineData(null, 0.0)]
|
||||
[InlineData("", 0.0)]
|
||||
[InlineData("x", 1.0)]
|
||||
public void NotNullOrEmptyMatcher_IsMatch_StringAsObject(string @string, double expected)
|
||||
{
|
||||
// Act
|
||||
var matcher = new NotNullOrEmptyMatcher();
|
||||
double result = matcher.IsMatch((object)@string);
|
||||
|
||||
// Assert
|
||||
result.Should().Be(expected);
|
||||
}
|
||||
// Assert
|
||||
result.Should().Be(expected);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void NotNullOrEmptyMatcher_IsMatch_Json()
|
||||
{
|
||||
// Act
|
||||
var matcher = new NotNullOrEmptyMatcher();
|
||||
double result = matcher.IsMatch(new { x = "x" });
|
||||
[Fact]
|
||||
public void NotNullOrEmptyMatcher_IsMatch_Json()
|
||||
{
|
||||
// Act
|
||||
var matcher = new NotNullOrEmptyMatcher();
|
||||
double result = matcher.IsMatch(new { x = "x" });
|
||||
|
||||
// Assert
|
||||
result.Should().Be(1.0);
|
||||
}
|
||||
// Assert
|
||||
result.Should().Be(1.0);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void NotNullOrEmptyMatcher_GetPatterns_Should_Return_EmptyArray()
|
||||
{
|
||||
// Act
|
||||
var patterns = new NotNullOrEmptyMatcher().GetPatterns();
|
||||
[Fact]
|
||||
public void NotNullOrEmptyMatcher_GetPatterns_Should_Return_EmptyArray()
|
||||
{
|
||||
// Act
|
||||
var patterns = new NotNullOrEmptyMatcher().GetPatterns();
|
||||
|
||||
// Assert
|
||||
patterns.Should().BeEmpty();
|
||||
}
|
||||
// Assert
|
||||
patterns.Should().BeEmpty();
|
||||
}
|
||||
}
|
||||
@@ -4,124 +4,123 @@ using NFluent;
|
||||
using WireMock.Matchers;
|
||||
using Xunit;
|
||||
|
||||
namespace WireMock.Net.Tests.Matchers
|
||||
namespace WireMock.Net.Tests.Matchers;
|
||||
|
||||
public class RegexMatcherTests
|
||||
{
|
||||
public class RegexMatcherTests
|
||||
[Fact]
|
||||
public void RegexMatcher_GetName()
|
||||
{
|
||||
[Fact]
|
||||
public void RegexMatcher_GetName()
|
||||
{
|
||||
// Assign
|
||||
var matcher = new RegexMatcher("");
|
||||
// Assign
|
||||
var matcher = new RegexMatcher("");
|
||||
|
||||
// Act
|
||||
string name = matcher.Name;
|
||||
// Act
|
||||
string name = matcher.Name;
|
||||
|
||||
// Assert
|
||||
Check.That(name).Equals("RegexMatcher");
|
||||
}
|
||||
// Assert
|
||||
Check.That(name).Equals("RegexMatcher");
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void RegexMatcher_GetPatterns()
|
||||
{
|
||||
// Assign
|
||||
var matcher = new RegexMatcher("X");
|
||||
[Fact]
|
||||
public void RegexMatcher_GetPatterns()
|
||||
{
|
||||
// Assign
|
||||
var matcher = new RegexMatcher("X");
|
||||
|
||||
// Act
|
||||
var patterns = matcher.GetPatterns();
|
||||
// Act
|
||||
var patterns = matcher.GetPatterns();
|
||||
|
||||
// Assert
|
||||
Check.That(patterns).ContainsExactly("X");
|
||||
}
|
||||
// Assert
|
||||
Check.That(patterns).ContainsExactly("X");
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void RegexMatcher_GetIgnoreCase()
|
||||
{
|
||||
// Act
|
||||
bool case1 = new RegexMatcher("X").IgnoreCase;
|
||||
bool case2 = new RegexMatcher("X", true).IgnoreCase;
|
||||
[Fact]
|
||||
public void RegexMatcher_GetIgnoreCase()
|
||||
{
|
||||
// Act
|
||||
bool case1 = new RegexMatcher("X").IgnoreCase;
|
||||
bool case2 = new RegexMatcher("X", true).IgnoreCase;
|
||||
|
||||
// Assert
|
||||
Check.That(case1).IsFalse();
|
||||
Check.That(case2).IsTrue();
|
||||
}
|
||||
// Assert
|
||||
Check.That(case1).IsFalse();
|
||||
Check.That(case2).IsTrue();
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void RegexMatcher_IsMatch()
|
||||
{
|
||||
// Assign
|
||||
var matcher = new RegexMatcher("H.*o");
|
||||
[Fact]
|
||||
public void RegexMatcher_IsMatch()
|
||||
{
|
||||
// Assign
|
||||
var matcher = new RegexMatcher("H.*o");
|
||||
|
||||
// Act
|
||||
double result = matcher.IsMatch("Hello world!");
|
||||
// Act
|
||||
double result = matcher.IsMatch("Hello world!");
|
||||
|
||||
// Assert
|
||||
Check.That(result).IsEqualTo(1.0d);
|
||||
}
|
||||
// Assert
|
||||
Check.That(result).IsEqualTo(1.0d);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void RegexMatcher_IsMatch_NullInput()
|
||||
{
|
||||
// Assign
|
||||
var matcher = new RegexMatcher("H.*o");
|
||||
[Fact]
|
||||
public void RegexMatcher_IsMatch_NullInput()
|
||||
{
|
||||
// Assign
|
||||
var matcher = new RegexMatcher("H.*o");
|
||||
|
||||
// Act
|
||||
double result = matcher.IsMatch(null);
|
||||
// Act
|
||||
double result = matcher.IsMatch(null);
|
||||
|
||||
// Assert
|
||||
Check.That(result).IsEqualTo(0.0d);
|
||||
}
|
||||
// Assert
|
||||
Check.That(result).IsEqualTo(0.0d);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void RegexMatcher_IsMatch_RegexExtended_Guid()
|
||||
{
|
||||
// Assign
|
||||
var matcher = new RegexMatcher(@"\GUIDB", true);
|
||||
[Fact]
|
||||
public void RegexMatcher_IsMatch_RegexExtended_Guid()
|
||||
{
|
||||
// Assign
|
||||
var matcher = new RegexMatcher(@"\GUIDB", true);
|
||||
|
||||
// Act
|
||||
double result = matcher.IsMatch(Guid.NewGuid().ToString("B"));
|
||||
// Act
|
||||
double result = matcher.IsMatch(Guid.NewGuid().ToString("B"));
|
||||
|
||||
// Assert
|
||||
result.Should().Be(1.0);
|
||||
}
|
||||
// Assert
|
||||
result.Should().Be(1.0);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void RegexMatcher_IsMatch_Regex_Guid()
|
||||
{
|
||||
// Assign
|
||||
var matcher = new RegexMatcher(@"\GUIDB", true, false, false);
|
||||
[Fact]
|
||||
public void RegexMatcher_IsMatch_Regex_Guid()
|
||||
{
|
||||
// Assign
|
||||
var matcher = new RegexMatcher(@"\GUIDB", true, false, false);
|
||||
|
||||
// Act
|
||||
double result = matcher.IsMatch(Guid.NewGuid().ToString("B"));
|
||||
// Act
|
||||
double result = matcher.IsMatch(Guid.NewGuid().ToString("B"));
|
||||
|
||||
// Assert
|
||||
result.Should().Be(0);
|
||||
}
|
||||
// Assert
|
||||
result.Should().Be(0);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void RegexMatcher_IsMatch_IgnoreCase()
|
||||
{
|
||||
// Assign
|
||||
var matcher = new RegexMatcher("H.*o", true);
|
||||
[Fact]
|
||||
public void RegexMatcher_IsMatch_IgnoreCase()
|
||||
{
|
||||
// Assign
|
||||
var matcher = new RegexMatcher("H.*o", true);
|
||||
|
||||
// Act
|
||||
double result = matcher.IsMatch("hello");
|
||||
// Act
|
||||
double result = matcher.IsMatch("hello");
|
||||
|
||||
// Assert
|
||||
Check.That(result).IsEqualTo(1.0d);
|
||||
}
|
||||
// Assert
|
||||
Check.That(result).IsEqualTo(1.0d);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void RegexMatcher_IsMatch_RejectOnMatch()
|
||||
{
|
||||
// Assign
|
||||
var matcher = new RegexMatcher(MatchBehaviour.RejectOnMatch, "h.*o");
|
||||
[Fact]
|
||||
public void RegexMatcher_IsMatch_RejectOnMatch()
|
||||
{
|
||||
// Assign
|
||||
var matcher = new RegexMatcher(MatchBehaviour.RejectOnMatch, "h.*o");
|
||||
|
||||
// Act
|
||||
double result = matcher.IsMatch("hello");
|
||||
// Act
|
||||
double result = matcher.IsMatch("hello");
|
||||
|
||||
// Assert
|
||||
Check.That(result).IsEqualTo(0.0);
|
||||
}
|
||||
// Assert
|
||||
Check.That(result).IsEqualTo(0.0);
|
||||
}
|
||||
}
|
||||
@@ -1,54 +1,53 @@
|
||||
using System.Linq;
|
||||
using System.Linq;
|
||||
using FluentAssertions;
|
||||
using WireMock.Matchers;
|
||||
using WireMock.Matchers.Request;
|
||||
using Xunit;
|
||||
|
||||
namespace WireMock.Net.Tests.Matchers
|
||||
namespace WireMock.Net.Tests.Matchers;
|
||||
|
||||
public class RequestMatchResultTests
|
||||
{
|
||||
public class RequestMatchResultTests
|
||||
[Fact]
|
||||
public void CompareTo_WithDifferentAverageScore_ReturnsBestMatch()
|
||||
{
|
||||
[Fact]
|
||||
public void CompareTo_WithDifferentAverageScore_ReturnsBestMatch()
|
||||
{
|
||||
// Arrange
|
||||
var result1 = new RequestMatchResult();
|
||||
result1.AddScore(typeof(WildcardMatcher), 1);
|
||||
result1.AddScore(typeof(WildcardMatcher), 0.9);
|
||||
// Arrange
|
||||
var result1 = new RequestMatchResult();
|
||||
result1.AddScore(typeof(WildcardMatcher), 1);
|
||||
result1.AddScore(typeof(WildcardMatcher), 0.9);
|
||||
|
||||
var result2 = new RequestMatchResult();
|
||||
result2.AddScore(typeof(LinqMatcher), 1);
|
||||
result2.AddScore(typeof(LinqMatcher), 1);
|
||||
var result2 = new RequestMatchResult();
|
||||
result2.AddScore(typeof(LinqMatcher), 1);
|
||||
result2.AddScore(typeof(LinqMatcher), 1);
|
||||
|
||||
var results = new[] { result1, result2 };
|
||||
var results = new[] { result1, result2 };
|
||||
|
||||
// Act
|
||||
var best = results.OrderBy(x => x).First();
|
||||
// Act
|
||||
var best = results.OrderBy(x => x).First();
|
||||
|
||||
// Assert
|
||||
best.Should().Be(result2);
|
||||
}
|
||||
// Assert
|
||||
best.Should().Be(result2);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void CompareTo_WithSameAverageScoreButMoreMatchers_ReturnsMatchWithMoreMatchers()
|
||||
{
|
||||
// Arrange
|
||||
var result1 = new RequestMatchResult();
|
||||
result1.AddScore(typeof(WildcardMatcher), 1);
|
||||
result1.AddScore(typeof(WildcardMatcher), 1);
|
||||
[Fact]
|
||||
public void CompareTo_WithSameAverageScoreButMoreMatchers_ReturnsMatchWithMoreMatchers()
|
||||
{
|
||||
// Arrange
|
||||
var result1 = new RequestMatchResult();
|
||||
result1.AddScore(typeof(WildcardMatcher), 1);
|
||||
result1.AddScore(typeof(WildcardMatcher), 1);
|
||||
|
||||
var result2 = new RequestMatchResult();
|
||||
result2.AddScore(typeof(LinqMatcher), 1);
|
||||
result2.AddScore(typeof(LinqMatcher), 1);
|
||||
result2.AddScore(typeof(LinqMatcher), 1);
|
||||
var result2 = new RequestMatchResult();
|
||||
result2.AddScore(typeof(LinqMatcher), 1);
|
||||
result2.AddScore(typeof(LinqMatcher), 1);
|
||||
result2.AddScore(typeof(LinqMatcher), 1);
|
||||
|
||||
var results = new[] { result1, result2 };
|
||||
var results = new[] { result1, result2 };
|
||||
|
||||
// Act
|
||||
var best = results.OrderBy(x => x).First();
|
||||
// Act
|
||||
var best = results.OrderBy(x => x).First();
|
||||
|
||||
// Assert
|
||||
best.Should().Be(result2);
|
||||
}
|
||||
// Assert
|
||||
best.Should().Be(result2);
|
||||
}
|
||||
}
|
||||
@@ -2,86 +2,85 @@ using NFluent;
|
||||
using WireMock.Matchers;
|
||||
using Xunit;
|
||||
|
||||
namespace WireMock.Net.Tests.Matchers
|
||||
namespace WireMock.Net.Tests.Matchers;
|
||||
|
||||
public class SimMetricsMatcherTests
|
||||
{
|
||||
public class SimMetricsMatcherTests
|
||||
[Fact]
|
||||
public void SimMetricsMatcher_GetName()
|
||||
{
|
||||
[Fact]
|
||||
public void SimMetricsMatcher_GetName()
|
||||
{
|
||||
// Assign
|
||||
var matcher = new SimMetricsMatcher("X");
|
||||
// Assign
|
||||
var matcher = new SimMetricsMatcher("X");
|
||||
|
||||
// Act
|
||||
string name = matcher.Name;
|
||||
// Act
|
||||
string name = matcher.Name;
|
||||
|
||||
// Assert
|
||||
Check.That(name).Equals("SimMetricsMatcher.Levenstein");
|
||||
}
|
||||
// Assert
|
||||
Check.That(name).Equals("SimMetricsMatcher.Levenstein");
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void SimMetricsMatcher_GetPatterns()
|
||||
{
|
||||
// Assign
|
||||
var matcher = new SimMetricsMatcher("X");
|
||||
[Fact]
|
||||
public void SimMetricsMatcher_GetPatterns()
|
||||
{
|
||||
// Assign
|
||||
var matcher = new SimMetricsMatcher("X");
|
||||
|
||||
// Act
|
||||
var patterns = matcher.GetPatterns();
|
||||
// Act
|
||||
var patterns = matcher.GetPatterns();
|
||||
|
||||
// Assert
|
||||
Check.That(patterns).ContainsExactly("X");
|
||||
}
|
||||
// Assert
|
||||
Check.That(patterns).ContainsExactly("X");
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void SimMetricsMatcher_IsMatch_1()
|
||||
{
|
||||
// Assign
|
||||
var matcher = new SimMetricsMatcher("The cat walks in the street.");
|
||||
[Fact]
|
||||
public void SimMetricsMatcher_IsMatch_1()
|
||||
{
|
||||
// Assign
|
||||
var matcher = new SimMetricsMatcher("The cat walks in the street.");
|
||||
|
||||
// Act
|
||||
double result = matcher.IsMatch("The car drives in the street.");
|
||||
// Act
|
||||
double result = matcher.IsMatch("The car drives in the street.");
|
||||
|
||||
// Assert
|
||||
Check.That(result).IsStrictlyLessThan(1.0).And.IsStrictlyGreaterThan(0.5);
|
||||
}
|
||||
// Assert
|
||||
Check.That(result).IsStrictlyLessThan(1.0).And.IsStrictlyGreaterThan(0.5);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void SimMetricsMatcher_IsMatch_2()
|
||||
{
|
||||
// Assign
|
||||
var matcher = new SimMetricsMatcher("The cat walks in the street.");
|
||||
[Fact]
|
||||
public void SimMetricsMatcher_IsMatch_2()
|
||||
{
|
||||
// Assign
|
||||
var matcher = new SimMetricsMatcher("The cat walks in the street.");
|
||||
|
||||
// Act
|
||||
double result = matcher.IsMatch("Hello");
|
||||
// Act
|
||||
double result = matcher.IsMatch("Hello");
|
||||
|
||||
// Assert
|
||||
Check.That(result).IsStrictlyLessThan(0.1).And.IsStrictlyGreaterThan(0.05);
|
||||
}
|
||||
// Assert
|
||||
Check.That(result).IsStrictlyLessThan(0.1).And.IsStrictlyGreaterThan(0.05);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void SimMetricsMatcher_IsMatch_AcceptOnMatch()
|
||||
{
|
||||
// Assign
|
||||
var matcher = new SimMetricsMatcher("test");
|
||||
[Fact]
|
||||
public void SimMetricsMatcher_IsMatch_AcceptOnMatch()
|
||||
{
|
||||
// Assign
|
||||
var matcher = new SimMetricsMatcher("test");
|
||||
|
||||
// Act
|
||||
double result = matcher.IsMatch("test");
|
||||
// Act
|
||||
double result = matcher.IsMatch("test");
|
||||
|
||||
// Assert
|
||||
Check.That(result).IsEqualTo(1.0);
|
||||
}
|
||||
// Assert
|
||||
Check.That(result).IsEqualTo(1.0);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void SimMetricsMatcher_IsMatch_RejectOnMatch()
|
||||
{
|
||||
// Assign
|
||||
var matcher = new SimMetricsMatcher(MatchBehaviour.RejectOnMatch, "test");
|
||||
[Fact]
|
||||
public void SimMetricsMatcher_IsMatch_RejectOnMatch()
|
||||
{
|
||||
// Assign
|
||||
var matcher = new SimMetricsMatcher(MatchBehaviour.RejectOnMatch, "test");
|
||||
|
||||
// Act
|
||||
double result = matcher.IsMatch("test");
|
||||
// Act
|
||||
double result = matcher.IsMatch("test");
|
||||
|
||||
// Assert
|
||||
Check.That(result).IsEqualTo(0.0);
|
||||
}
|
||||
// Assert
|
||||
Check.That(result).IsEqualTo(0.0);
|
||||
}
|
||||
}
|
||||
@@ -5,135 +5,134 @@ using WireMock.Matchers;
|
||||
using WireMock.Models;
|
||||
using Xunit;
|
||||
|
||||
namespace WireMock.Net.Tests.Matchers
|
||||
namespace WireMock.Net.Tests.Matchers;
|
||||
|
||||
public class WildcardMatcherTest
|
||||
{
|
||||
public class WildcardMatcherTest
|
||||
[Fact]
|
||||
public void WildcardMatcher_IsMatch_With_StringPattern()
|
||||
{
|
||||
[Fact]
|
||||
public void WildcardMatcher_IsMatch_With_StringPattern()
|
||||
// Arrange
|
||||
var pattern = new StringPattern
|
||||
{
|
||||
// Arrange
|
||||
var pattern = new StringPattern
|
||||
{
|
||||
Pattern = "*",
|
||||
PatternAsFile = "pf"
|
||||
};
|
||||
Pattern = "*",
|
||||
PatternAsFile = "pf"
|
||||
};
|
||||
|
||||
// Act
|
||||
var matcher = new WildcardMatcher(pattern);
|
||||
// Act
|
||||
var matcher = new WildcardMatcher(pattern);
|
||||
|
||||
// Assert
|
||||
matcher.IsMatch("a").Should().Be(1.0d);
|
||||
}
|
||||
// Assert
|
||||
matcher.IsMatch("a").Should().Be(1.0d);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void WildcardMatcher_IsMatch_With_StringPatterns()
|
||||
[Fact]
|
||||
public void WildcardMatcher_IsMatch_With_StringPatterns()
|
||||
{
|
||||
// Arrange
|
||||
AnyOf<string, StringPattern> pattern1 = new StringPattern
|
||||
{
|
||||
// Arrange
|
||||
AnyOf<string, StringPattern> pattern1 = new StringPattern
|
||||
{
|
||||
Pattern = "a"
|
||||
};
|
||||
AnyOf<string, StringPattern> pattern2 = new StringPattern
|
||||
{
|
||||
Pattern = "b"
|
||||
};
|
||||
|
||||
// Act
|
||||
var matcher = new WildcardMatcher(new [] { pattern1, pattern2 });
|
||||
|
||||
// Assert
|
||||
matcher.IsMatch("a").Should().Be(1.0d);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void WildcardMatcher_IsMatch_Positive()
|
||||
Pattern = "a"
|
||||
};
|
||||
AnyOf<string, StringPattern> pattern2 = new StringPattern
|
||||
{
|
||||
var tests = new[]
|
||||
{
|
||||
new { p = "*", i = "" },
|
||||
new { p = "?", i = " "},
|
||||
new { p = "*", i = "a "},
|
||||
new { p = "*", i = "ab" },
|
||||
new { p = "?", i = "a" },
|
||||
new { p = "*?", i = "abc" },
|
||||
new { p = "?*", i = "abc" },
|
||||
new { p = "abc", i = "abc" },
|
||||
new { p = "abc*", i = "abc" },
|
||||
new { p = "abc*", i = "abcd" },
|
||||
new { p = "*abc*", i = "abc" },
|
||||
new { p = "*a*bc*", i = "abc" },
|
||||
new { p = "*a*b?", i = "aXXXbc" }
|
||||
};
|
||||
Pattern = "b"
|
||||
};
|
||||
|
||||
foreach (var test in tests)
|
||||
{
|
||||
var matcher = new WildcardMatcher(test.p);
|
||||
matcher.IsMatch(test.i).Should().Be(1.0d, $"Pattern '{test.p}' with value '{test.i}' should be 1.0");
|
||||
}
|
||||
}
|
||||
// Act
|
||||
var matcher = new WildcardMatcher(new [] { pattern1, pattern2 });
|
||||
|
||||
[Fact]
|
||||
public void WildcardMatcher_IsMatch_Negative()
|
||||
// Assert
|
||||
matcher.IsMatch("a").Should().Be(1.0d);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void WildcardMatcher_IsMatch_Positive()
|
||||
{
|
||||
var tests = new[]
|
||||
{
|
||||
var tests = new[]
|
||||
{
|
||||
new { p = "*a", i = "" },
|
||||
new { p = "a*", i = "" },
|
||||
new { p = "?", i = "" },
|
||||
new { p = "*b*", i = "a" },
|
||||
new { p = "b*a", i = "ab" },
|
||||
new { p = "??", i = "a" },
|
||||
new { p = "*?", i = "" },
|
||||
new { p = "??*", i = "a" },
|
||||
new { p = "*abc", i = "abX" },
|
||||
new { p = "*abc*", i = "Xbc" },
|
||||
new { p = "*a*bc*", i = "ac" }
|
||||
};
|
||||
new { p = "*", i = "" },
|
||||
new { p = "?", i = " "},
|
||||
new { p = "*", i = "a "},
|
||||
new { p = "*", i = "ab" },
|
||||
new { p = "?", i = "a" },
|
||||
new { p = "*?", i = "abc" },
|
||||
new { p = "?*", i = "abc" },
|
||||
new { p = "abc", i = "abc" },
|
||||
new { p = "abc*", i = "abc" },
|
||||
new { p = "abc*", i = "abcd" },
|
||||
new { p = "*abc*", i = "abc" },
|
||||
new { p = "*a*bc*", i = "abc" },
|
||||
new { p = "*a*b?", i = "aXXXbc" }
|
||||
};
|
||||
|
||||
foreach (var test in tests)
|
||||
{
|
||||
var matcher = new WildcardMatcher(test.p);
|
||||
Check.That(matcher.IsMatch(test.i)).IsEqualTo(0.0);
|
||||
}
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void WildcardMatcher_GetName()
|
||||
foreach (var test in tests)
|
||||
{
|
||||
// Assign
|
||||
var matcher = new WildcardMatcher("x");
|
||||
|
||||
// Act
|
||||
string name = matcher.Name;
|
||||
|
||||
// Assert
|
||||
Check.That(name).Equals("WildcardMatcher");
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void WildcardMatcher_GetPatterns()
|
||||
{
|
||||
// Assign
|
||||
var matcher = new WildcardMatcher("x");
|
||||
|
||||
// Act
|
||||
var patterns = matcher.GetPatterns();
|
||||
|
||||
// Assert
|
||||
Check.That(patterns).ContainsExactly(new AnyOf<string, StringPattern>("x"));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void WildcardMatcher_IsMatch_RejectOnMatch()
|
||||
{
|
||||
// Assign
|
||||
var matcher = new WildcardMatcher(MatchBehaviour.RejectOnMatch, "m");
|
||||
|
||||
// Act
|
||||
double result = matcher.IsMatch("m");
|
||||
|
||||
Check.That(result).IsEqualTo(0.0);
|
||||
var matcher = new WildcardMatcher(test.p);
|
||||
matcher.IsMatch(test.i).Should().Be(1.0d, $"Pattern '{test.p}' with value '{test.i}' should be 1.0");
|
||||
}
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void WildcardMatcher_IsMatch_Negative()
|
||||
{
|
||||
var tests = new[]
|
||||
{
|
||||
new { p = "*a", i = "" },
|
||||
new { p = "a*", i = "" },
|
||||
new { p = "?", i = "" },
|
||||
new { p = "*b*", i = "a" },
|
||||
new { p = "b*a", i = "ab" },
|
||||
new { p = "??", i = "a" },
|
||||
new { p = "*?", i = "" },
|
||||
new { p = "??*", i = "a" },
|
||||
new { p = "*abc", i = "abX" },
|
||||
new { p = "*abc*", i = "Xbc" },
|
||||
new { p = "*a*bc*", i = "ac" }
|
||||
};
|
||||
|
||||
foreach (var test in tests)
|
||||
{
|
||||
var matcher = new WildcardMatcher(test.p);
|
||||
Check.That(matcher.IsMatch(test.i)).IsEqualTo(0.0);
|
||||
}
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void WildcardMatcher_GetName()
|
||||
{
|
||||
// Assign
|
||||
var matcher = new WildcardMatcher("x");
|
||||
|
||||
// Act
|
||||
string name = matcher.Name;
|
||||
|
||||
// Assert
|
||||
Check.That(name).Equals("WildcardMatcher");
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void WildcardMatcher_GetPatterns()
|
||||
{
|
||||
// Assign
|
||||
var matcher = new WildcardMatcher("x");
|
||||
|
||||
// Act
|
||||
var patterns = matcher.GetPatterns();
|
||||
|
||||
// Assert
|
||||
Check.That(patterns).ContainsExactly(new AnyOf<string, StringPattern>("x"));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void WildcardMatcher_IsMatch_RejectOnMatch()
|
||||
{
|
||||
// Assign
|
||||
var matcher = new WildcardMatcher(MatchBehaviour.RejectOnMatch, "m");
|
||||
|
||||
// Act
|
||||
double result = matcher.IsMatch("m");
|
||||
|
||||
Check.That(result).IsEqualTo(0.0);
|
||||
}
|
||||
}
|
||||
@@ -3,98 +3,97 @@ using NFluent;
|
||||
using WireMock.RegularExpressions;
|
||||
using Xunit;
|
||||
|
||||
namespace WireMock.Net.Tests.RegularExpressions
|
||||
namespace WireMock.Net.Tests.RegularExpressions;
|
||||
|
||||
public class RegexExtendedTests
|
||||
{
|
||||
public class RegexExtendedTests
|
||||
/// <summary>
|
||||
/// Input guid used for testing
|
||||
/// </summary>
|
||||
public Guid InputGuid => Guid.NewGuid();
|
||||
|
||||
[Fact]
|
||||
public void RegexExtended_GuidB_Pattern()
|
||||
{
|
||||
/// <summary>
|
||||
/// Input guid used for testing
|
||||
/// </summary>
|
||||
public Guid InputGuid => Guid.NewGuid();
|
||||
var guidbUpper = @".*\GUIDB.*";
|
||||
var guidbLower = @".*\guidb.*";
|
||||
|
||||
[Fact]
|
||||
public void RegexExtended_GuidB_Pattern()
|
||||
{
|
||||
var guidbUpper = @".*\GUIDB.*";
|
||||
var guidbLower = @".*\guidb.*";
|
||||
var inputLower = InputGuid.ToString("B");
|
||||
var inputUpper = InputGuid.ToString("B").ToUpper();
|
||||
var regexLower = new RegexExtended(guidbLower);
|
||||
var regexUpper = new RegexExtended(guidbUpper);
|
||||
|
||||
var inputLower = InputGuid.ToString("B");
|
||||
var inputUpper = InputGuid.ToString("B").ToUpper();
|
||||
var regexLower = new RegexExtended(guidbLower);
|
||||
var regexUpper = new RegexExtended(guidbUpper);
|
||||
|
||||
Check.That(regexLower.IsMatch(inputLower)).Equals(true);
|
||||
Check.That(regexLower.IsMatch(inputUpper)).Equals(false);
|
||||
Check.That(regexUpper.IsMatch(inputUpper)).Equals(true);
|
||||
Check.That(regexUpper.IsMatch(inputLower)).Equals(false);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void RegexExtended_GuidD_Pattern()
|
||||
{
|
||||
var guiddUpper = @".*\GUIDD.*";
|
||||
var guiddLower = @".*\guidd.*";
|
||||
|
||||
var inputLower = InputGuid.ToString("D");
|
||||
var inputUpper = InputGuid.ToString("D").ToUpper();
|
||||
var regexLower = new RegexExtended(guiddLower);
|
||||
var regexUpper = new RegexExtended(guiddUpper);
|
||||
|
||||
Check.That(regexLower.IsMatch(inputLower)).Equals(true);
|
||||
Check.That(regexLower.IsMatch(inputUpper)).Equals(false);
|
||||
Check.That(regexUpper.IsMatch(inputUpper)).Equals(true);
|
||||
Check.That(regexUpper.IsMatch(inputLower)).Equals(false);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void RegexExtended_GuidN_Pattern()
|
||||
{
|
||||
var guidnUpper = @".*\GUIDN.*";
|
||||
var guidnLower = @".*\guidn.*";
|
||||
|
||||
var inputLower = InputGuid.ToString("N");
|
||||
var inputUpper = InputGuid.ToString("N").ToUpper();
|
||||
var regexLower = new RegexExtended(guidnLower);
|
||||
var regexUpper = new RegexExtended(guidnUpper);
|
||||
|
||||
Check.That(regexLower.IsMatch(inputLower)).Equals(true);
|
||||
Check.That(regexLower.IsMatch(inputUpper)).Equals(false);
|
||||
Check.That(regexUpper.IsMatch(inputUpper)).Equals(true);
|
||||
Check.That(regexUpper.IsMatch(inputLower)).Equals(false);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void RegexExtended_GuidP_Pattern()
|
||||
{
|
||||
var guidpUpper = @".*\GUIDP.*";
|
||||
var guidpLower = @".*\guidp.*";
|
||||
|
||||
var inputLower = InputGuid.ToString("P");
|
||||
var inputUpper = InputGuid.ToString("P").ToUpper();
|
||||
var regexLower = new RegexExtended(guidpLower);
|
||||
var regexUpper = new RegexExtended(guidpUpper);
|
||||
|
||||
Check.That(regexLower.IsMatch(inputLower)).Equals(true);
|
||||
Check.That(regexLower.IsMatch(inputUpper)).Equals(false);
|
||||
Check.That(regexUpper.IsMatch(inputUpper)).Equals(true);
|
||||
Check.That(regexUpper.IsMatch(inputLower)).Equals(false);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void RegexExtended_GuidX_Pattern()
|
||||
{
|
||||
var guidxUpper = @".*\GUIDX.*";
|
||||
var guidxLower = @".*\guidx.*";
|
||||
|
||||
var inputLower = InputGuid.ToString("X");
|
||||
var inputUpper = InputGuid.ToString("X").ToUpper().Replace("X", "x");
|
||||
var regexLower = new RegexExtended(guidxLower);
|
||||
var regexUpper = new RegexExtended(guidxUpper);
|
||||
|
||||
Check.That(regexLower.IsMatch(inputLower)).Equals(true);
|
||||
Check.That(regexLower.IsMatch(inputUpper)).Equals(false);
|
||||
Check.That(regexUpper.IsMatch(inputUpper)).Equals(true);
|
||||
Check.That(regexUpper.IsMatch(inputLower)).Equals(false);
|
||||
}
|
||||
Check.That(regexLower.IsMatch(inputLower)).Equals(true);
|
||||
Check.That(regexLower.IsMatch(inputUpper)).Equals(false);
|
||||
Check.That(regexUpper.IsMatch(inputUpper)).Equals(true);
|
||||
Check.That(regexUpper.IsMatch(inputLower)).Equals(false);
|
||||
}
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void RegexExtended_GuidD_Pattern()
|
||||
{
|
||||
var guiddUpper = @".*\GUIDD.*";
|
||||
var guiddLower = @".*\guidd.*";
|
||||
|
||||
var inputLower = InputGuid.ToString("D");
|
||||
var inputUpper = InputGuid.ToString("D").ToUpper();
|
||||
var regexLower = new RegexExtended(guiddLower);
|
||||
var regexUpper = new RegexExtended(guiddUpper);
|
||||
|
||||
Check.That(regexLower.IsMatch(inputLower)).Equals(true);
|
||||
Check.That(regexLower.IsMatch(inputUpper)).Equals(false);
|
||||
Check.That(regexUpper.IsMatch(inputUpper)).Equals(true);
|
||||
Check.That(regexUpper.IsMatch(inputLower)).Equals(false);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void RegexExtended_GuidN_Pattern()
|
||||
{
|
||||
var guidnUpper = @".*\GUIDN.*";
|
||||
var guidnLower = @".*\guidn.*";
|
||||
|
||||
var inputLower = InputGuid.ToString("N");
|
||||
var inputUpper = InputGuid.ToString("N").ToUpper();
|
||||
var regexLower = new RegexExtended(guidnLower);
|
||||
var regexUpper = new RegexExtended(guidnUpper);
|
||||
|
||||
Check.That(regexLower.IsMatch(inputLower)).Equals(true);
|
||||
Check.That(regexLower.IsMatch(inputUpper)).Equals(false);
|
||||
Check.That(regexUpper.IsMatch(inputUpper)).Equals(true);
|
||||
Check.That(regexUpper.IsMatch(inputLower)).Equals(false);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void RegexExtended_GuidP_Pattern()
|
||||
{
|
||||
var guidpUpper = @".*\GUIDP.*";
|
||||
var guidpLower = @".*\guidp.*";
|
||||
|
||||
var inputLower = InputGuid.ToString("P");
|
||||
var inputUpper = InputGuid.ToString("P").ToUpper();
|
||||
var regexLower = new RegexExtended(guidpLower);
|
||||
var regexUpper = new RegexExtended(guidpUpper);
|
||||
|
||||
Check.That(regexLower.IsMatch(inputLower)).Equals(true);
|
||||
Check.That(regexLower.IsMatch(inputUpper)).Equals(false);
|
||||
Check.That(regexUpper.IsMatch(inputUpper)).Equals(true);
|
||||
Check.That(regexUpper.IsMatch(inputLower)).Equals(false);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void RegexExtended_GuidX_Pattern()
|
||||
{
|
||||
var guidxUpper = @".*\GUIDX.*";
|
||||
var guidxLower = @".*\guidx.*";
|
||||
|
||||
var inputLower = InputGuid.ToString("X");
|
||||
var inputUpper = InputGuid.ToString("X").ToUpper().Replace("X", "x");
|
||||
var regexLower = new RegexExtended(guidxLower);
|
||||
var regexUpper = new RegexExtended(guidxUpper);
|
||||
|
||||
Check.That(regexLower.IsMatch(inputLower)).Equals(true);
|
||||
Check.That(regexLower.IsMatch(inputUpper)).Equals(false);
|
||||
Check.That(regexUpper.IsMatch(inputUpper)).Equals(true);
|
||||
Check.That(regexUpper.IsMatch(inputLower)).Equals(false);
|
||||
}
|
||||
}
|
||||
@@ -1,78 +1,77 @@
|
||||
using System.Collections.Generic;
|
||||
using System.Collections.Generic;
|
||||
using NFluent;
|
||||
using WireMock.Matchers.Request;
|
||||
using WireMock.RequestBuilders;
|
||||
using Xunit;
|
||||
|
||||
namespace WireMock.Net.Tests.RequestBuilders
|
||||
namespace WireMock.Net.Tests.RequestBuilders;
|
||||
|
||||
public class RequestBuilderUsingMethodTests
|
||||
{
|
||||
public class RequestBuilderUsingMethodTests
|
||||
[Fact]
|
||||
public void RequestBuilder_UsingConnect()
|
||||
{
|
||||
[Fact]
|
||||
public void RequestBuilder_UsingConnect()
|
||||
{
|
||||
// Act
|
||||
var requestBuilder = (Request)Request.Create().UsingConnect();
|
||||
// Act
|
||||
var requestBuilder = (Request)Request.Create().UsingConnect();
|
||||
|
||||
// Assert
|
||||
var matchers = requestBuilder.GetPrivateFieldValue<IList<IRequestMatcher>>("_requestMatchers");
|
||||
Check.That(matchers.Count).IsEqualTo(1);
|
||||
Check.That((matchers[0] as RequestMessageMethodMatcher).Methods).ContainsExactly("CONNECT");
|
||||
}
|
||||
// Assert
|
||||
var matchers = requestBuilder.GetPrivateFieldValue<IList<IRequestMatcher>>("_requestMatchers");
|
||||
Check.That(matchers.Count).IsEqualTo(1);
|
||||
Check.That((matchers[0] as RequestMessageMethodMatcher).Methods).ContainsExactly("CONNECT");
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void RequestBuilder_UsingOptions()
|
||||
{
|
||||
// Act
|
||||
var requestBuilder = (Request)Request.Create().UsingOptions();
|
||||
[Fact]
|
||||
public void RequestBuilder_UsingOptions()
|
||||
{
|
||||
// Act
|
||||
var requestBuilder = (Request)Request.Create().UsingOptions();
|
||||
|
||||
// Assert
|
||||
var matchers = requestBuilder.GetPrivateFieldValue<IList<IRequestMatcher>>("_requestMatchers");
|
||||
Check.That(matchers.Count).IsEqualTo(1);
|
||||
Check.That((matchers[0] as RequestMessageMethodMatcher).Methods).ContainsExactly("OPTIONS");
|
||||
}
|
||||
// Assert
|
||||
var matchers = requestBuilder.GetPrivateFieldValue<IList<IRequestMatcher>>("_requestMatchers");
|
||||
Check.That(matchers.Count).IsEqualTo(1);
|
||||
Check.That((matchers[0] as RequestMessageMethodMatcher).Methods).ContainsExactly("OPTIONS");
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void RequestBuilder_UsingPatch()
|
||||
{
|
||||
// Act
|
||||
var requestBuilder = (Request)Request.Create().UsingPatch();
|
||||
[Fact]
|
||||
public void RequestBuilder_UsingPatch()
|
||||
{
|
||||
// Act
|
||||
var requestBuilder = (Request)Request.Create().UsingPatch();
|
||||
|
||||
// Assert
|
||||
var matchers = requestBuilder.GetPrivateFieldValue<IList<IRequestMatcher>>("_requestMatchers");
|
||||
Check.That(matchers.Count).IsEqualTo(1);
|
||||
Check.That((matchers[0] as RequestMessageMethodMatcher).Methods).ContainsExactly("PATCH");
|
||||
}
|
||||
// Assert
|
||||
var matchers = requestBuilder.GetPrivateFieldValue<IList<IRequestMatcher>>("_requestMatchers");
|
||||
Check.That(matchers.Count).IsEqualTo(1);
|
||||
Check.That((matchers[0] as RequestMessageMethodMatcher).Methods).ContainsExactly("PATCH");
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void RequestBuilder_UsingTrace()
|
||||
{
|
||||
// Act
|
||||
var requestBuilder = (Request)Request.Create().UsingTrace();
|
||||
[Fact]
|
||||
public void RequestBuilder_UsingTrace()
|
||||
{
|
||||
// Act
|
||||
var requestBuilder = (Request)Request.Create().UsingTrace();
|
||||
|
||||
// Assert
|
||||
var matchers = requestBuilder.GetPrivateFieldValue<IList<IRequestMatcher>>("_requestMatchers");
|
||||
Check.That(matchers.Count).IsEqualTo(1);
|
||||
Check.That((matchers[0] as RequestMessageMethodMatcher).Methods).ContainsExactly("TRACE");
|
||||
}
|
||||
// Assert
|
||||
var matchers = requestBuilder.GetPrivateFieldValue<IList<IRequestMatcher>>("_requestMatchers");
|
||||
Check.That(matchers.Count).IsEqualTo(1);
|
||||
Check.That((matchers[0] as RequestMessageMethodMatcher).Methods).ContainsExactly("TRACE");
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void RequestBuilder_UsingAnyMethod_ClearsAllOtherMatches()
|
||||
{
|
||||
// Assign
|
||||
var requestBuilder = (Request)Request.Create().UsingGet();
|
||||
[Fact]
|
||||
public void RequestBuilder_UsingAnyMethod_ClearsAllOtherMatches()
|
||||
{
|
||||
// Assign
|
||||
var requestBuilder = (Request)Request.Create().UsingGet();
|
||||
|
||||
// Assert 1
|
||||
var matchers = requestBuilder.GetPrivateFieldValue<IList<IRequestMatcher>>("_requestMatchers");
|
||||
Check.That(matchers.Count).IsEqualTo(1);
|
||||
Check.That(matchers[0]).IsInstanceOfType(typeof(RequestMessageMethodMatcher));
|
||||
// Assert 1
|
||||
var matchers = requestBuilder.GetPrivateFieldValue<IList<IRequestMatcher>>("_requestMatchers");
|
||||
Check.That(matchers.Count).IsEqualTo(1);
|
||||
Check.That(matchers[0]).IsInstanceOfType(typeof(RequestMessageMethodMatcher));
|
||||
|
||||
// Act
|
||||
requestBuilder.UsingAnyMethod();
|
||||
// Act
|
||||
requestBuilder.UsingAnyMethod();
|
||||
|
||||
// Assert 2
|
||||
matchers = requestBuilder.GetPrivateFieldValue<IList<IRequestMatcher>>("_requestMatchers");
|
||||
Check.That(matchers.Count).IsEqualTo(0);
|
||||
}
|
||||
// Assert 2
|
||||
matchers = requestBuilder.GetPrivateFieldValue<IList<IRequestMatcher>>("_requestMatchers");
|
||||
Check.That(matchers.Count).IsEqualTo(0);
|
||||
}
|
||||
}
|
||||
@@ -1,4 +1,4 @@
|
||||
using FluentAssertions;
|
||||
using FluentAssertions;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using WireMock.Matchers;
|
||||
@@ -6,39 +6,38 @@ using WireMock.Matchers.Request;
|
||||
using WireMock.RequestBuilders;
|
||||
using Xunit;
|
||||
|
||||
namespace WireMock.Net.Tests.RequestBuilders
|
||||
namespace WireMock.Net.Tests.RequestBuilders;
|
||||
|
||||
public class RequestBuilderWithBodyTests
|
||||
{
|
||||
public class RequestBuilderWithBodyTests
|
||||
[Fact]
|
||||
public void RequestBuilder_WithBody_IMatcher()
|
||||
{
|
||||
[Fact]
|
||||
public void RequestBuilder_WithBody_IMatcher()
|
||||
{
|
||||
// Assign
|
||||
var matcher = new WildcardMatcher("x");
|
||||
// Assign
|
||||
var matcher = new WildcardMatcher("x");
|
||||
|
||||
// Act
|
||||
var requestBuilder = (Request)Request.Create().WithBody(matcher);
|
||||
// Act
|
||||
var requestBuilder = (Request)Request.Create().WithBody(matcher);
|
||||
|
||||
// Assert
|
||||
var matchers = requestBuilder.GetPrivateFieldValue<IList<IRequestMatcher>>("_requestMatchers");
|
||||
matchers.Should().HaveCount(1);
|
||||
((RequestMessageBodyMatcher)matchers[0]).Matchers.Should().Contain(matcher);
|
||||
}
|
||||
// Assert
|
||||
var matchers = requestBuilder.GetPrivateFieldValue<IList<IRequestMatcher>>("_requestMatchers");
|
||||
matchers.Should().HaveCount(1);
|
||||
((RequestMessageBodyMatcher)matchers[0]).Matchers.Should().Contain(matcher);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void RequestBuilder_WithBody_IMatchers()
|
||||
{
|
||||
// Assign
|
||||
var matcher1 = new WildcardMatcher("x");
|
||||
var matcher2 = new WildcardMatcher("y");
|
||||
[Fact]
|
||||
public void RequestBuilder_WithBody_IMatchers()
|
||||
{
|
||||
// Assign
|
||||
var matcher1 = new WildcardMatcher("x");
|
||||
var matcher2 = new WildcardMatcher("y");
|
||||
|
||||
// Act
|
||||
var requestBuilder = (Request)Request.Create().WithBody(new[] { matcher1, matcher2 }.Cast<IMatcher>().ToArray());
|
||||
// Act
|
||||
var requestBuilder = (Request)Request.Create().WithBody(new[] { matcher1, matcher2 }.Cast<IMatcher>().ToArray());
|
||||
|
||||
// Assert
|
||||
var matchers = requestBuilder.GetPrivateFieldValue<IList<IRequestMatcher>>("_requestMatchers");
|
||||
matchers.Should().HaveCount(1);
|
||||
((RequestMessageBodyMatcher)matchers[0]).Matchers.Should().Contain(new[] { matcher1, matcher2 });
|
||||
}
|
||||
// Assert
|
||||
var matchers = requestBuilder.GetPrivateFieldValue<IList<IRequestMatcher>>("_requestMatchers");
|
||||
matchers.Should().HaveCount(1);
|
||||
((RequestMessageBodyMatcher)matchers[0]).Matchers.Should().Contain(new[] { matcher1, matcher2 });
|
||||
}
|
||||
}
|
||||
@@ -1,48 +1,47 @@
|
||||
using System.Collections.Generic;
|
||||
using System.Collections.Generic;
|
||||
using NFluent;
|
||||
using WireMock.Matchers;
|
||||
using WireMock.Matchers.Request;
|
||||
using WireMock.RequestBuilders;
|
||||
using Xunit;
|
||||
|
||||
namespace WireMock.Net.Tests.RequestBuilders
|
||||
namespace WireMock.Net.Tests.RequestBuilders;
|
||||
|
||||
public class RequestBuilderWithCookieTests
|
||||
{
|
||||
public class RequestBuilderWithCookieTests
|
||||
[Fact]
|
||||
public void RequestBuilder_WithCookie_String_String_Bool_MatchBehaviour()
|
||||
{
|
||||
[Fact]
|
||||
public void RequestBuilder_WithCookie_String_String_Bool_MatchBehaviour()
|
||||
{
|
||||
// Act
|
||||
var requestBuilder = (Request)Request.Create().WithCookie("c", "t", true, MatchBehaviour.AcceptOnMatch);
|
||||
// Act
|
||||
var requestBuilder = (Request)Request.Create().WithCookie("c", "t", true, MatchBehaviour.AcceptOnMatch);
|
||||
|
||||
// Assert
|
||||
var matchers = requestBuilder.GetPrivateFieldValue<IList<IRequestMatcher>>("_requestMatchers");
|
||||
Check.That(matchers.Count).IsEqualTo(1);
|
||||
Check.That(matchers[0]).IsInstanceOfType(typeof(RequestMessageCookieMatcher));
|
||||
}
|
||||
// Assert
|
||||
var matchers = requestBuilder.GetPrivateFieldValue<IList<IRequestMatcher>>("_requestMatchers");
|
||||
Check.That(matchers.Count).IsEqualTo(1);
|
||||
Check.That(matchers[0]).IsInstanceOfType(typeof(RequestMessageCookieMatcher));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void RequestBuilder_WithCookie_String_IStringMatcher()
|
||||
{
|
||||
// Act
|
||||
var requestBuilder = (Request)Request.Create().WithCookie("c", new ExactMatcher("v"));
|
||||
[Fact]
|
||||
public void RequestBuilder_WithCookie_String_IStringMatcher()
|
||||
{
|
||||
// Act
|
||||
var requestBuilder = (Request)Request.Create().WithCookie("c", new ExactMatcher("v"));
|
||||
|
||||
// Assert
|
||||
var matchers = requestBuilder.GetPrivateFieldValue<IList<IRequestMatcher>>("_requestMatchers");
|
||||
Check.That(matchers.Count).IsEqualTo(1);
|
||||
Check.That(matchers[0]).IsInstanceOfType(typeof(RequestMessageCookieMatcher));
|
||||
}
|
||||
// Assert
|
||||
var matchers = requestBuilder.GetPrivateFieldValue<IList<IRequestMatcher>>("_requestMatchers");
|
||||
Check.That(matchers.Count).IsEqualTo(1);
|
||||
Check.That(matchers[0]).IsInstanceOfType(typeof(RequestMessageCookieMatcher));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void RequestBuilder_WithCookie_FuncIDictionary()
|
||||
{
|
||||
// Act
|
||||
var requestBuilder = (Request)Request.Create().WithCookie((IDictionary<string, string> x) => true);
|
||||
[Fact]
|
||||
public void RequestBuilder_WithCookie_FuncIDictionary()
|
||||
{
|
||||
// Act
|
||||
var requestBuilder = (Request)Request.Create().WithCookie((IDictionary<string, string> x) => true);
|
||||
|
||||
// Assert
|
||||
var matchers = requestBuilder.GetPrivateFieldValue<IList<IRequestMatcher>>("_requestMatchers");
|
||||
Check.That(matchers.Count).IsEqualTo(1);
|
||||
Check.That(matchers[0]).IsInstanceOfType(typeof(RequestMessageCookieMatcher));
|
||||
}
|
||||
// Assert
|
||||
var matchers = requestBuilder.GetPrivateFieldValue<IList<IRequestMatcher>>("_requestMatchers");
|
||||
Check.That(matchers.Count).IsEqualTo(1);
|
||||
Check.That(matchers[0]).IsInstanceOfType(typeof(RequestMessageCookieMatcher));
|
||||
}
|
||||
}
|
||||
@@ -1,84 +1,83 @@
|
||||
using System.Collections.Generic;
|
||||
using System.Collections.Generic;
|
||||
using NFluent;
|
||||
using WireMock.Matchers;
|
||||
using WireMock.Matchers.Request;
|
||||
using WireMock.RequestBuilders;
|
||||
using Xunit;
|
||||
|
||||
namespace WireMock.Net.Tests.RequestBuilders
|
||||
namespace WireMock.Net.Tests.RequestBuilders;
|
||||
|
||||
public class RequestBuilderWithHeaderTests
|
||||
{
|
||||
public class RequestBuilderWithHeaderTests
|
||||
[Fact]
|
||||
public void RequestBuilder_WithHeader_String_String_MatchBehaviour()
|
||||
{
|
||||
[Fact]
|
||||
public void RequestBuilder_WithHeader_String_String_MatchBehaviour()
|
||||
{
|
||||
// Act
|
||||
var requestBuilder = (Request)Request.Create().WithHeader("h", "t", MatchBehaviour.AcceptOnMatch);
|
||||
// Act
|
||||
var requestBuilder = (Request)Request.Create().WithHeader("h", "t", MatchBehaviour.AcceptOnMatch);
|
||||
|
||||
// Assert
|
||||
var matchers = requestBuilder.GetPrivateFieldValue<IList<IRequestMatcher>>("_requestMatchers");
|
||||
Check.That(matchers.Count).IsEqualTo(1);
|
||||
Check.That(matchers[0]).IsInstanceOfType(typeof(RequestMessageHeaderMatcher));
|
||||
}
|
||||
// Assert
|
||||
var matchers = requestBuilder.GetPrivateFieldValue<IList<IRequestMatcher>>("_requestMatchers");
|
||||
Check.That(matchers.Count).IsEqualTo(1);
|
||||
Check.That(matchers[0]).IsInstanceOfType(typeof(RequestMessageHeaderMatcher));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void RequestBuilder_WithHeader_String_String_Bool_MatchBehaviour()
|
||||
{
|
||||
// Act
|
||||
var requestBuilder = (Request)Request.Create().WithHeader("h", "t", true, MatchBehaviour.AcceptOnMatch);
|
||||
[Fact]
|
||||
public void RequestBuilder_WithHeader_String_String_Bool_MatchBehaviour()
|
||||
{
|
||||
// Act
|
||||
var requestBuilder = (Request)Request.Create().WithHeader("h", "t", true, MatchBehaviour.AcceptOnMatch);
|
||||
|
||||
// Assert
|
||||
var matchers = requestBuilder.GetPrivateFieldValue<IList<IRequestMatcher>>("_requestMatchers");
|
||||
Check.That(matchers.Count).IsEqualTo(1);
|
||||
Check.That(matchers[0]).IsInstanceOfType(typeof(RequestMessageHeaderMatcher));
|
||||
}
|
||||
// Assert
|
||||
var matchers = requestBuilder.GetPrivateFieldValue<IList<IRequestMatcher>>("_requestMatchers");
|
||||
Check.That(matchers.Count).IsEqualTo(1);
|
||||
Check.That(matchers[0]).IsInstanceOfType(typeof(RequestMessageHeaderMatcher));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void RequestBuilder_WithHeader_String_Strings_MatchBehaviour()
|
||||
{
|
||||
// Act
|
||||
var requestBuilder = (Request)Request.Create().WithHeader("h", new[] { "t1", "t2" }, MatchBehaviour.AcceptOnMatch);
|
||||
[Fact]
|
||||
public void RequestBuilder_WithHeader_String_Strings_MatchBehaviour()
|
||||
{
|
||||
// Act
|
||||
var requestBuilder = (Request)Request.Create().WithHeader("h", new[] { "t1", "t2" }, MatchBehaviour.AcceptOnMatch);
|
||||
|
||||
// Assert
|
||||
var matchers = requestBuilder.GetPrivateFieldValue<IList<IRequestMatcher>>("_requestMatchers");
|
||||
Check.That(matchers.Count).IsEqualTo(1);
|
||||
Check.That(matchers[0]).IsInstanceOfType(typeof(RequestMessageHeaderMatcher));
|
||||
}
|
||||
// Assert
|
||||
var matchers = requestBuilder.GetPrivateFieldValue<IList<IRequestMatcher>>("_requestMatchers");
|
||||
Check.That(matchers.Count).IsEqualTo(1);
|
||||
Check.That(matchers[0]).IsInstanceOfType(typeof(RequestMessageHeaderMatcher));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void RequestBuilder_WithHeader_String_Strings_Bool_MatchBehaviour()
|
||||
{
|
||||
// Act
|
||||
var requestBuilder = (Request)Request.Create().WithHeader("h", new[] { "t1", "t2" }, true, MatchBehaviour.AcceptOnMatch);
|
||||
[Fact]
|
||||
public void RequestBuilder_WithHeader_String_Strings_Bool_MatchBehaviour()
|
||||
{
|
||||
// Act
|
||||
var requestBuilder = (Request)Request.Create().WithHeader("h", new[] { "t1", "t2" }, true, MatchBehaviour.AcceptOnMatch);
|
||||
|
||||
// Assert
|
||||
var matchers = requestBuilder.GetPrivateFieldValue<IList<IRequestMatcher>>("_requestMatchers");
|
||||
Check.That(matchers.Count).IsEqualTo(1);
|
||||
Check.That(matchers[0]).IsInstanceOfType(typeof(RequestMessageHeaderMatcher));
|
||||
}
|
||||
// Assert
|
||||
var matchers = requestBuilder.GetPrivateFieldValue<IList<IRequestMatcher>>("_requestMatchers");
|
||||
Check.That(matchers.Count).IsEqualTo(1);
|
||||
Check.That(matchers[0]).IsInstanceOfType(typeof(RequestMessageHeaderMatcher));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void RequestBuilder_WithHeader_String_IStringMatcher()
|
||||
{
|
||||
// Act
|
||||
var requestBuilder = (Request)Request.Create().WithHeader("h", new ExactMatcher("v"));
|
||||
[Fact]
|
||||
public void RequestBuilder_WithHeader_String_IStringMatcher()
|
||||
{
|
||||
// Act
|
||||
var requestBuilder = (Request)Request.Create().WithHeader("h", new ExactMatcher("v"));
|
||||
|
||||
// Assert
|
||||
var matchers = requestBuilder.GetPrivateFieldValue<IList<IRequestMatcher>>("_requestMatchers");
|
||||
Check.That(matchers.Count).IsEqualTo(1);
|
||||
Check.That(matchers[0]).IsInstanceOfType(typeof(RequestMessageHeaderMatcher));
|
||||
}
|
||||
// Assert
|
||||
var matchers = requestBuilder.GetPrivateFieldValue<IList<IRequestMatcher>>("_requestMatchers");
|
||||
Check.That(matchers.Count).IsEqualTo(1);
|
||||
Check.That(matchers[0]).IsInstanceOfType(typeof(RequestMessageHeaderMatcher));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void RequestBuilder_WithHeader_FuncIDictionary()
|
||||
{
|
||||
// Act
|
||||
var requestBuilder = (Request)Request.Create().WithHeader(x => true);
|
||||
[Fact]
|
||||
public void RequestBuilder_WithHeader_FuncIDictionary()
|
||||
{
|
||||
// Act
|
||||
var requestBuilder = (Request)Request.Create().WithHeader(x => true);
|
||||
|
||||
// Assert
|
||||
var matchers = requestBuilder.GetPrivateFieldValue<IList<IRequestMatcher>>("_requestMatchers");
|
||||
Check.That(matchers.Count).IsEqualTo(1);
|
||||
Check.That(matchers[0]).IsInstanceOfType(typeof(RequestMessageHeaderMatcher));
|
||||
}
|
||||
// Assert
|
||||
var matchers = requestBuilder.GetPrivateFieldValue<IList<IRequestMatcher>>("_requestMatchers");
|
||||
Check.That(matchers.Count).IsEqualTo(1);
|
||||
Check.That(matchers[0]).IsInstanceOfType(typeof(RequestMessageHeaderMatcher));
|
||||
}
|
||||
}
|
||||
@@ -1,60 +1,59 @@
|
||||
using System.Collections.Generic;
|
||||
using System.Collections.Generic;
|
||||
using NFluent;
|
||||
using WireMock.Matchers;
|
||||
using WireMock.Matchers.Request;
|
||||
using WireMock.RequestBuilders;
|
||||
using Xunit;
|
||||
|
||||
namespace WireMock.Net.Tests.RequestBuilders
|
||||
namespace WireMock.Net.Tests.RequestBuilders;
|
||||
|
||||
public class RequestBuilderWithParamTests
|
||||
{
|
||||
public class RequestBuilderWithParamTests
|
||||
[Fact]
|
||||
public void RequestBuilder_WithParam_String_MatchBehaviour()
|
||||
{
|
||||
[Fact]
|
||||
public void RequestBuilder_WithParam_String_MatchBehaviour()
|
||||
{
|
||||
// Act
|
||||
var requestBuilder = (Request)Request.Create().WithParam("p", MatchBehaviour.AcceptOnMatch);
|
||||
// Act
|
||||
var requestBuilder = (Request)Request.Create().WithParam("p", MatchBehaviour.AcceptOnMatch);
|
||||
|
||||
// Assert
|
||||
var matchers = requestBuilder.GetPrivateFieldValue<IList<IRequestMatcher>>("_requestMatchers");
|
||||
Check.That(matchers.Count).IsEqualTo(1);
|
||||
Check.That(matchers[0]).IsInstanceOfType(typeof(RequestMessageParamMatcher));
|
||||
}
|
||||
// Assert
|
||||
var matchers = requestBuilder.GetPrivateFieldValue<IList<IRequestMatcher>>("_requestMatchers");
|
||||
Check.That(matchers.Count).IsEqualTo(1);
|
||||
Check.That(matchers[0]).IsInstanceOfType(typeof(RequestMessageParamMatcher));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void RequestBuilder_WithParam_String_Strings()
|
||||
{
|
||||
// Act
|
||||
var requestBuilder = (Request)Request.Create().WithParam("p", new[] { "v1", "v2" });
|
||||
[Fact]
|
||||
public void RequestBuilder_WithParam_String_Strings()
|
||||
{
|
||||
// Act
|
||||
var requestBuilder = (Request)Request.Create().WithParam("p", new[] { "v1", "v2" });
|
||||
|
||||
// Assert
|
||||
var matchers = requestBuilder.GetPrivateFieldValue<IList<IRequestMatcher>>("_requestMatchers");
|
||||
Check.That(matchers.Count).IsEqualTo(1);
|
||||
Check.That(matchers[0]).IsInstanceOfType(typeof(RequestMessageParamMatcher));
|
||||
}
|
||||
// Assert
|
||||
var matchers = requestBuilder.GetPrivateFieldValue<IList<IRequestMatcher>>("_requestMatchers");
|
||||
Check.That(matchers.Count).IsEqualTo(1);
|
||||
Check.That(matchers[0]).IsInstanceOfType(typeof(RequestMessageParamMatcher));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void RequestBuilder_WithParam_String_IStringMatcher()
|
||||
{
|
||||
// Act
|
||||
var requestBuilder = (Request)Request.Create().WithParam("p", new RegexMatcher("[012]"));
|
||||
[Fact]
|
||||
public void RequestBuilder_WithParam_String_IStringMatcher()
|
||||
{
|
||||
// Act
|
||||
var requestBuilder = (Request)Request.Create().WithParam("p", new RegexMatcher("[012]"));
|
||||
|
||||
// Assert
|
||||
var matchers = requestBuilder.GetPrivateFieldValue<IList<IRequestMatcher>>("_requestMatchers");
|
||||
Check.That(matchers.Count).IsEqualTo(1);
|
||||
Check.That(matchers[0]).IsInstanceOfType(typeof(RequestMessageParamMatcher));
|
||||
}
|
||||
// Assert
|
||||
var matchers = requestBuilder.GetPrivateFieldValue<IList<IRequestMatcher>>("_requestMatchers");
|
||||
Check.That(matchers.Count).IsEqualTo(1);
|
||||
Check.That(matchers[0]).IsInstanceOfType(typeof(RequestMessageParamMatcher));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void RequestBuilder_WithParam_String_MatchBehaviour_IExactMatcher()
|
||||
{
|
||||
// Act
|
||||
var requestBuilder = (Request)Request.Create().WithParam("p", MatchBehaviour.AcceptOnMatch, new ExactMatcher("v"));
|
||||
[Fact]
|
||||
public void RequestBuilder_WithParam_String_MatchBehaviour_IExactMatcher()
|
||||
{
|
||||
// Act
|
||||
var requestBuilder = (Request)Request.Create().WithParam("p", MatchBehaviour.AcceptOnMatch, new ExactMatcher("v"));
|
||||
|
||||
// Assert
|
||||
var matchers = requestBuilder.GetPrivateFieldValue<IList<IRequestMatcher>>("_requestMatchers");
|
||||
Check.That(matchers.Count).IsEqualTo(1);
|
||||
Check.That(matchers[0]).IsInstanceOfType(typeof(RequestMessageParamMatcher));
|
||||
}
|
||||
// Assert
|
||||
var matchers = requestBuilder.GetPrivateFieldValue<IList<IRequestMatcher>>("_requestMatchers");
|
||||
Check.That(matchers.Count).IsEqualTo(1);
|
||||
Check.That(matchers[0]).IsInstanceOfType(typeof(RequestMessageParamMatcher));
|
||||
}
|
||||
}
|
||||
@@ -5,56 +5,55 @@ using WireMock.Matchers.Request;
|
||||
using WireMock.RequestBuilders;
|
||||
using Xunit;
|
||||
|
||||
namespace WireMock.Net.Tests.RequestBuilders
|
||||
namespace WireMock.Net.Tests.RequestBuilders;
|
||||
|
||||
public class RequestBuilderWithUrlTests
|
||||
{
|
||||
public class RequestBuilderWithUrlTests
|
||||
[Fact]
|
||||
public void RequestBuilder_WithUrl_Strings()
|
||||
{
|
||||
[Fact]
|
||||
public void RequestBuilder_WithUrl_Strings()
|
||||
{
|
||||
// Act
|
||||
var requestBuilder = (Request)Request.Create().WithUrl("http://a", "http://b");
|
||||
// Act
|
||||
var requestBuilder = (Request)Request.Create().WithUrl("http://a", "http://b");
|
||||
|
||||
// Assert
|
||||
var matchers = requestBuilder.GetPrivateFieldValue<IList<IRequestMatcher>>("_requestMatchers");
|
||||
Check.That(matchers.Count).IsEqualTo(1);
|
||||
Check.That(matchers[0]).IsInstanceOfType(typeof(RequestMessageUrlMatcher));
|
||||
}
|
||||
// Assert
|
||||
var matchers = requestBuilder.GetPrivateFieldValue<IList<IRequestMatcher>>("_requestMatchers");
|
||||
Check.That(matchers.Count).IsEqualTo(1);
|
||||
Check.That(matchers[0]).IsInstanceOfType(typeof(RequestMessageUrlMatcher));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void RequestBuilder_WithUrl_MatchBehaviour_Strings()
|
||||
{
|
||||
// Act
|
||||
var requestBuilder = (Request)Request.Create().WithUrl(MatchOperator.Or, "http://a", "http://b");
|
||||
[Fact]
|
||||
public void RequestBuilder_WithUrl_MatchBehaviour_Strings()
|
||||
{
|
||||
// Act
|
||||
var requestBuilder = (Request)Request.Create().WithUrl(MatchOperator.Or, "http://a", "http://b");
|
||||
|
||||
// Assert
|
||||
var matchers = requestBuilder.GetPrivateFieldValue<IList<IRequestMatcher>>("_requestMatchers");
|
||||
Check.That(matchers.Count).IsEqualTo(1);
|
||||
Check.That(matchers[0]).IsInstanceOfType(typeof(RequestMessageUrlMatcher));
|
||||
}
|
||||
// Assert
|
||||
var matchers = requestBuilder.GetPrivateFieldValue<IList<IRequestMatcher>>("_requestMatchers");
|
||||
Check.That(matchers.Count).IsEqualTo(1);
|
||||
Check.That(matchers[0]).IsInstanceOfType(typeof(RequestMessageUrlMatcher));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void RequestBuilder_WithUrl_Funcs()
|
||||
{
|
||||
// Act
|
||||
var requestBuilder = (Request) Request.Create().WithUrl(url => true, url => false);
|
||||
[Fact]
|
||||
public void RequestBuilder_WithUrl_Funcs()
|
||||
{
|
||||
// Act
|
||||
var requestBuilder = (Request) Request.Create().WithUrl(url => true, url => false);
|
||||
|
||||
// Assert
|
||||
var matchers = requestBuilder.GetPrivateFieldValue<IList<IRequestMatcher>>("_requestMatchers");
|
||||
Check.That(matchers.Count).IsEqualTo(1);
|
||||
Check.That(matchers[0]).IsInstanceOfType(typeof(RequestMessageUrlMatcher));
|
||||
}
|
||||
// Assert
|
||||
var matchers = requestBuilder.GetPrivateFieldValue<IList<IRequestMatcher>>("_requestMatchers");
|
||||
Check.That(matchers.Count).IsEqualTo(1);
|
||||
Check.That(matchers[0]).IsInstanceOfType(typeof(RequestMessageUrlMatcher));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void RequestBuilder_WithUrl_IStringMatchers()
|
||||
{
|
||||
// Act
|
||||
var requestBuilder = (Request) Request.Create().WithUrl(new ExactMatcher("http://a"), new ExactMatcher("http://b"));
|
||||
[Fact]
|
||||
public void RequestBuilder_WithUrl_IStringMatchers()
|
||||
{
|
||||
// Act
|
||||
var requestBuilder = (Request) Request.Create().WithUrl(new ExactMatcher("http://a"), new ExactMatcher("http://b"));
|
||||
|
||||
// Assert
|
||||
var matchers = requestBuilder.GetPrivateFieldValue<IList<IRequestMatcher>>("_requestMatchers");
|
||||
Check.That(matchers.Count).IsEqualTo(1);
|
||||
Check.That(matchers[0]).IsInstanceOfType(typeof(RequestMessageUrlMatcher));
|
||||
}
|
||||
// Assert
|
||||
var matchers = requestBuilder.GetPrivateFieldValue<IList<IRequestMatcher>>("_requestMatchers");
|
||||
Check.That(matchers.Count).IsEqualTo(1);
|
||||
Check.That(matchers[0]).IsInstanceOfType(typeof(RequestMessageUrlMatcher));
|
||||
}
|
||||
}
|
||||
@@ -1,4 +1,4 @@
|
||||
using System.Collections.Generic;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using Moq;
|
||||
using NFluent;
|
||||
@@ -6,78 +6,77 @@ using WireMock.Matchers.Request;
|
||||
using WireMock.Models;
|
||||
using Xunit;
|
||||
|
||||
namespace WireMock.Net.Tests.RequestMatchers
|
||||
namespace WireMock.Net.Tests.RequestMatchers;
|
||||
|
||||
public class RequestMessageCompositeMatcherTests
|
||||
{
|
||||
public class RequestMessageCompositeMatcherTests
|
||||
private class Helper : RequestMessageCompositeMatcher
|
||||
{
|
||||
private class Helper : RequestMessageCompositeMatcher
|
||||
public Helper(IEnumerable<IRequestMatcher> requestMatchers, CompositeMatcherType type = CompositeMatcherType.And) : base(requestMatchers, type)
|
||||
{
|
||||
public Helper(IEnumerable<IRequestMatcher> requestMatchers, CompositeMatcherType type = CompositeMatcherType.And) : base(requestMatchers, type)
|
||||
{
|
||||
}
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void RequestMessageCompositeMatcher_GetMatchingScore_EmptyArray()
|
||||
{
|
||||
// Assign
|
||||
var requestMessage = new RequestMessage(new UrlDetails("http://localhost"), "GET", "127.0.0.1");
|
||||
var matcher = new Helper(Enumerable.Empty<IRequestMatcher>());
|
||||
|
||||
// Act
|
||||
var result = new RequestMatchResult();
|
||||
double score = matcher.GetMatchingScore(requestMessage, result);
|
||||
|
||||
// Assert
|
||||
Check.That(score).IsEqualTo(0.0d);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void RequestMessageCompositeMatcher_GetMatchingScore_CompositeMatcherType_And()
|
||||
{
|
||||
// Assign
|
||||
var requestMatcher1Mock = new Mock<IRequestMatcher>();
|
||||
requestMatcher1Mock.Setup(rm => rm.GetMatchingScore(It.IsAny<RequestMessage>(), It.IsAny<RequestMatchResult>())).Returns(1.0d);
|
||||
var requestMatcher2Mock = new Mock<IRequestMatcher>();
|
||||
requestMatcher2Mock.Setup(rm => rm.GetMatchingScore(It.IsAny<RequestMessage>(), It.IsAny<RequestMatchResult>())).Returns(0.8d);
|
||||
|
||||
var requestMessage = new RequestMessage(new UrlDetails("http://localhost"), "GET", "127.0.0.1");
|
||||
var matcher = new Helper(new[] { requestMatcher1Mock.Object, requestMatcher2Mock.Object });
|
||||
|
||||
// Act
|
||||
var result = new RequestMatchResult();
|
||||
double score = matcher.GetMatchingScore(requestMessage, result);
|
||||
|
||||
// Assert
|
||||
Check.That(score).IsEqualTo(0.9d);
|
||||
|
||||
// Verify
|
||||
requestMatcher1Mock.Verify(rm => rm.GetMatchingScore(It.IsAny<RequestMessage>(), It.IsAny<RequestMatchResult>()), Times.Once);
|
||||
requestMatcher2Mock.Verify(rm => rm.GetMatchingScore(It.IsAny<RequestMessage>(), It.IsAny<RequestMatchResult>()), Times.Once);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void RequestMessageCompositeMatcher_GetMatchingScore_CompositeMatcherType_Or()
|
||||
{
|
||||
// Assign
|
||||
var requestMatcher1Mock = new Mock<IRequestMatcher>();
|
||||
requestMatcher1Mock.Setup(rm => rm.GetMatchingScore(It.IsAny<RequestMessage>(), It.IsAny<RequestMatchResult>())).Returns(1.0d);
|
||||
var requestMatcher2Mock = new Mock<IRequestMatcher>();
|
||||
requestMatcher2Mock.Setup(rm => rm.GetMatchingScore(It.IsAny<RequestMessage>(), It.IsAny<RequestMatchResult>())).Returns(0.8d);
|
||||
|
||||
var requestMessage = new RequestMessage(new UrlDetails("http://localhost"), "GET", "127.0.0.1");
|
||||
var matcher = new Helper(new[] { requestMatcher1Mock.Object, requestMatcher2Mock.Object }, CompositeMatcherType.Or);
|
||||
|
||||
// Act
|
||||
var result = new RequestMatchResult();
|
||||
double score = matcher.GetMatchingScore(requestMessage, result);
|
||||
|
||||
// Assert
|
||||
Check.That(score).IsEqualTo(1.0d);
|
||||
|
||||
// Verify
|
||||
requestMatcher1Mock.Verify(rm => rm.GetMatchingScore(It.IsAny<RequestMessage>(), It.IsAny<RequestMatchResult>()), Times.Once);
|
||||
requestMatcher2Mock.Verify(rm => rm.GetMatchingScore(It.IsAny<RequestMessage>(), It.IsAny<RequestMatchResult>()), Times.Once);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void RequestMessageCompositeMatcher_GetMatchingScore_EmptyArray()
|
||||
{
|
||||
// Assign
|
||||
var requestMessage = new RequestMessage(new UrlDetails("http://localhost"), "GET", "127.0.0.1");
|
||||
var matcher = new Helper(Enumerable.Empty<IRequestMatcher>());
|
||||
|
||||
// Act
|
||||
var result = new RequestMatchResult();
|
||||
double score = matcher.GetMatchingScore(requestMessage, result);
|
||||
|
||||
// Assert
|
||||
Check.That(score).IsEqualTo(0.0d);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void RequestMessageCompositeMatcher_GetMatchingScore_CompositeMatcherType_And()
|
||||
{
|
||||
// Assign
|
||||
var requestMatcher1Mock = new Mock<IRequestMatcher>();
|
||||
requestMatcher1Mock.Setup(rm => rm.GetMatchingScore(It.IsAny<RequestMessage>(), It.IsAny<RequestMatchResult>())).Returns(1.0d);
|
||||
var requestMatcher2Mock = new Mock<IRequestMatcher>();
|
||||
requestMatcher2Mock.Setup(rm => rm.GetMatchingScore(It.IsAny<RequestMessage>(), It.IsAny<RequestMatchResult>())).Returns(0.8d);
|
||||
|
||||
var requestMessage = new RequestMessage(new UrlDetails("http://localhost"), "GET", "127.0.0.1");
|
||||
var matcher = new Helper(new[] { requestMatcher1Mock.Object, requestMatcher2Mock.Object });
|
||||
|
||||
// Act
|
||||
var result = new RequestMatchResult();
|
||||
double score = matcher.GetMatchingScore(requestMessage, result);
|
||||
|
||||
// Assert
|
||||
Check.That(score).IsEqualTo(0.9d);
|
||||
|
||||
// Verify
|
||||
requestMatcher1Mock.Verify(rm => rm.GetMatchingScore(It.IsAny<RequestMessage>(), It.IsAny<RequestMatchResult>()), Times.Once);
|
||||
requestMatcher2Mock.Verify(rm => rm.GetMatchingScore(It.IsAny<RequestMessage>(), It.IsAny<RequestMatchResult>()), Times.Once);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void RequestMessageCompositeMatcher_GetMatchingScore_CompositeMatcherType_Or()
|
||||
{
|
||||
// Assign
|
||||
var requestMatcher1Mock = new Mock<IRequestMatcher>();
|
||||
requestMatcher1Mock.Setup(rm => rm.GetMatchingScore(It.IsAny<RequestMessage>(), It.IsAny<RequestMatchResult>())).Returns(1.0d);
|
||||
var requestMatcher2Mock = new Mock<IRequestMatcher>();
|
||||
requestMatcher2Mock.Setup(rm => rm.GetMatchingScore(It.IsAny<RequestMessage>(), It.IsAny<RequestMatchResult>())).Returns(0.8d);
|
||||
|
||||
var requestMessage = new RequestMessage(new UrlDetails("http://localhost"), "GET", "127.0.0.1");
|
||||
var matcher = new Helper(new[] { requestMatcher1Mock.Object, requestMatcher2Mock.Object }, CompositeMatcherType.Or);
|
||||
|
||||
// Act
|
||||
var result = new RequestMatchResult();
|
||||
double score = matcher.GetMatchingScore(requestMessage, result);
|
||||
|
||||
// Assert
|
||||
Check.That(score).IsEqualTo(1.0d);
|
||||
|
||||
// Verify
|
||||
requestMatcher1Mock.Verify(rm => rm.GetMatchingScore(It.IsAny<RequestMessage>(), It.IsAny<RequestMatchResult>()), Times.Once);
|
||||
requestMatcher2Mock.Verify(rm => rm.GetMatchingScore(It.IsAny<RequestMessage>(), It.IsAny<RequestMatchResult>()), Times.Once);
|
||||
}
|
||||
}
|
||||
@@ -1,154 +1,153 @@
|
||||
using System.Collections.Generic;
|
||||
using System.Collections.Generic;
|
||||
using NFluent;
|
||||
using WireMock.Matchers;
|
||||
using WireMock.Matchers.Request;
|
||||
using WireMock.Models;
|
||||
using Xunit;
|
||||
|
||||
namespace WireMock.Net.Tests.RequestMatchers
|
||||
namespace WireMock.Net.Tests.RequestMatchers;
|
||||
|
||||
public class RequestMessageCookieMatcherTests
|
||||
{
|
||||
public class RequestMessageCookieMatcherTests
|
||||
[Fact]
|
||||
public void RequestMessageCookieMatcher_GetMatchingScore_AcceptOnMatch_CookieDoesNotExists()
|
||||
{
|
||||
[Fact]
|
||||
public void RequestMessageCookieMatcher_GetMatchingScore_AcceptOnMatch_CookieDoesNotExists()
|
||||
{
|
||||
// Assign
|
||||
var requestMessage = new RequestMessage(new UrlDetails("http://localhost"), "GET", "127.0.0.1");
|
||||
var matcher = new RequestMessageCookieMatcher(MatchBehaviour.AcceptOnMatch, "c", false, "x");
|
||||
// Assign
|
||||
var requestMessage = new RequestMessage(new UrlDetails("http://localhost"), "GET", "127.0.0.1");
|
||||
var matcher = new RequestMessageCookieMatcher(MatchBehaviour.AcceptOnMatch, "c", false, "x");
|
||||
|
||||
// Act
|
||||
var result = new RequestMatchResult();
|
||||
double score = matcher.GetMatchingScore(requestMessage, result);
|
||||
// Act
|
||||
var result = new RequestMatchResult();
|
||||
double score = matcher.GetMatchingScore(requestMessage, result);
|
||||
|
||||
// Assert
|
||||
Check.That(score).IsEqualTo(0.0d);
|
||||
}
|
||||
// Assert
|
||||
Check.That(score).IsEqualTo(0.0d);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void RequestMessageCookieMatcher_GetMatchingScore_RejectOnMatch_CookieDoesNotExists()
|
||||
{
|
||||
// Assign
|
||||
var requestMessage = new RequestMessage(new UrlDetails("http://localhost"), "GET", "127.0.0.1");
|
||||
var matcher = new RequestMessageCookieMatcher(MatchBehaviour.RejectOnMatch, "c", false, "x");
|
||||
[Fact]
|
||||
public void RequestMessageCookieMatcher_GetMatchingScore_RejectOnMatch_CookieDoesNotExists()
|
||||
{
|
||||
// Assign
|
||||
var requestMessage = new RequestMessage(new UrlDetails("http://localhost"), "GET", "127.0.0.1");
|
||||
var matcher = new RequestMessageCookieMatcher(MatchBehaviour.RejectOnMatch, "c", false, "x");
|
||||
|
||||
// Act
|
||||
var result = new RequestMatchResult();
|
||||
double score = matcher.GetMatchingScore(requestMessage, result);
|
||||
// Act
|
||||
var result = new RequestMatchResult();
|
||||
double score = matcher.GetMatchingScore(requestMessage, result);
|
||||
|
||||
// Assert
|
||||
Check.That(score).IsEqualTo(1.0d);
|
||||
}
|
||||
// Assert
|
||||
Check.That(score).IsEqualTo(1.0d);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void RequestMessageCookieMatcher_GetMatchingScore_AcceptOnMatch()
|
||||
{
|
||||
// Assign
|
||||
var cookies = new Dictionary<string, string> { { "h", "x" } };
|
||||
var requestMessage = new RequestMessage(new UrlDetails("http://localhost"), "GET", "127.0.0.1", null, null, cookies);
|
||||
var matcher = new RequestMessageCookieMatcher(MatchBehaviour.AcceptOnMatch, "h", false, "x");
|
||||
[Fact]
|
||||
public void RequestMessageCookieMatcher_GetMatchingScore_AcceptOnMatch()
|
||||
{
|
||||
// Assign
|
||||
var cookies = new Dictionary<string, string> { { "h", "x" } };
|
||||
var requestMessage = new RequestMessage(new UrlDetails("http://localhost"), "GET", "127.0.0.1", null, null, cookies);
|
||||
var matcher = new RequestMessageCookieMatcher(MatchBehaviour.AcceptOnMatch, "h", false, "x");
|
||||
|
||||
// Act
|
||||
var result = new RequestMatchResult();
|
||||
double score = matcher.GetMatchingScore(requestMessage, result);
|
||||
// Act
|
||||
var result = new RequestMatchResult();
|
||||
double score = matcher.GetMatchingScore(requestMessage, result);
|
||||
|
||||
// Assert
|
||||
Check.That(score).IsEqualTo(1.0d);
|
||||
}
|
||||
// Assert
|
||||
Check.That(score).IsEqualTo(1.0d);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void RequestMessageCookieMatcher_GetMatchingScore_RejectOnMatch()
|
||||
{
|
||||
// Assign
|
||||
var cookies = new Dictionary<string, string> { { "h", "x" } };
|
||||
var requestMessage = new RequestMessage(new UrlDetails("http://localhost"), "GET", "127.0.0.1", null, null, cookies);
|
||||
var matcher = new RequestMessageCookieMatcher(MatchBehaviour.RejectOnMatch, "h", false, "x");
|
||||
[Fact]
|
||||
public void RequestMessageCookieMatcher_GetMatchingScore_RejectOnMatch()
|
||||
{
|
||||
// Assign
|
||||
var cookies = new Dictionary<string, string> { { "h", "x" } };
|
||||
var requestMessage = new RequestMessage(new UrlDetails("http://localhost"), "GET", "127.0.0.1", null, null, cookies);
|
||||
var matcher = new RequestMessageCookieMatcher(MatchBehaviour.RejectOnMatch, "h", false, "x");
|
||||
|
||||
// Act
|
||||
var result = new RequestMatchResult();
|
||||
double score = matcher.GetMatchingScore(requestMessage, result);
|
||||
// Act
|
||||
var result = new RequestMatchResult();
|
||||
double score = matcher.GetMatchingScore(requestMessage, result);
|
||||
|
||||
// Assert
|
||||
Check.That(score).IsEqualTo(0.0d);
|
||||
}
|
||||
// Assert
|
||||
Check.That(score).IsEqualTo(0.0d);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void RequestMessageCookieMatcher_GetMatchingScore_IStringMatcher_Match()
|
||||
{
|
||||
// Assign
|
||||
var cookies = new Dictionary<string, string> { { "cook", "x" } };
|
||||
var requestMessage = new RequestMessage(new UrlDetails("http://localhost"), "GET", "127.0.0.1", null, null, cookies);
|
||||
var matcher = new RequestMessageCookieMatcher(MatchBehaviour.AcceptOnMatch, "cook", false, new ExactMatcher("x"));
|
||||
[Fact]
|
||||
public void RequestMessageCookieMatcher_GetMatchingScore_IStringMatcher_Match()
|
||||
{
|
||||
// Assign
|
||||
var cookies = new Dictionary<string, string> { { "cook", "x" } };
|
||||
var requestMessage = new RequestMessage(new UrlDetails("http://localhost"), "GET", "127.0.0.1", null, null, cookies);
|
||||
var matcher = new RequestMessageCookieMatcher(MatchBehaviour.AcceptOnMatch, "cook", false, new ExactMatcher("x"));
|
||||
|
||||
// Act
|
||||
var result = new RequestMatchResult();
|
||||
double score = matcher.GetMatchingScore(requestMessage, result);
|
||||
// Act
|
||||
var result = new RequestMatchResult();
|
||||
double score = matcher.GetMatchingScore(requestMessage, result);
|
||||
|
||||
// Assert
|
||||
Check.That(score).IsEqualTo(1.0d);
|
||||
}
|
||||
// Assert
|
||||
Check.That(score).IsEqualTo(1.0d);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void RequestMessageCookieMatcher_WithMissingCookie_When_RejectOnMatch_Is_True_Should_Match()
|
||||
{
|
||||
// Assign
|
||||
var cookies = new Dictionary<string, string> { { "cook", "x" } };
|
||||
var requestMessage = new RequestMessage(new UrlDetails("http://localhost"), "GET", "127.0.0.1", null, null, cookies);
|
||||
var matcher = new RequestMessageCookieMatcher(MatchBehaviour.RejectOnMatch, "uhuh", false, new ExactMatcher("x"));
|
||||
[Fact]
|
||||
public void RequestMessageCookieMatcher_WithMissingCookie_When_RejectOnMatch_Is_True_Should_Match()
|
||||
{
|
||||
// Assign
|
||||
var cookies = new Dictionary<string, string> { { "cook", "x" } };
|
||||
var requestMessage = new RequestMessage(new UrlDetails("http://localhost"), "GET", "127.0.0.1", null, null, cookies);
|
||||
var matcher = new RequestMessageCookieMatcher(MatchBehaviour.RejectOnMatch, "uhuh", false, new ExactMatcher("x"));
|
||||
|
||||
// Act
|
||||
var result = new RequestMatchResult();
|
||||
double score = matcher.GetMatchingScore(requestMessage, result);
|
||||
// Act
|
||||
var result = new RequestMatchResult();
|
||||
double score = matcher.GetMatchingScore(requestMessage, result);
|
||||
|
||||
// Assert
|
||||
Check.That(score).IsEqualTo(1.0d);
|
||||
}
|
||||
// Assert
|
||||
Check.That(score).IsEqualTo(1.0d);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void RequestMessageCookieMatcher_GetMatchingScore_Func_Match()
|
||||
{
|
||||
// Assign
|
||||
var cookies = new Dictionary<string, string> { { "cook", "x" } };
|
||||
var requestMessage = new RequestMessage(new UrlDetails("http://localhost"), "GET", "127.0.0.1", null, null, cookies);
|
||||
var matcher = new RequestMessageCookieMatcher(x => x.ContainsKey("cook"));
|
||||
[Fact]
|
||||
public void RequestMessageCookieMatcher_GetMatchingScore_Func_Match()
|
||||
{
|
||||
// Assign
|
||||
var cookies = new Dictionary<string, string> { { "cook", "x" } };
|
||||
var requestMessage = new RequestMessage(new UrlDetails("http://localhost"), "GET", "127.0.0.1", null, null, cookies);
|
||||
var matcher = new RequestMessageCookieMatcher(x => x.ContainsKey("cook"));
|
||||
|
||||
// Act
|
||||
var result = new RequestMatchResult();
|
||||
double score = matcher.GetMatchingScore(requestMessage, result);
|
||||
// Act
|
||||
var result = new RequestMatchResult();
|
||||
double score = matcher.GetMatchingScore(requestMessage, result);
|
||||
|
||||
// Assert
|
||||
Check.That(score).IsEqualTo(1.0d);
|
||||
}
|
||||
// Assert
|
||||
Check.That(score).IsEqualTo(1.0d);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void RequestMessageCookieMatcher_GetMatchingScore_CaseIgnoreForCookieValue()
|
||||
{
|
||||
// Assign
|
||||
var cookies = new Dictionary<string, string> { { "cook", "teST" } };
|
||||
var requestMessage = new RequestMessage(new UrlDetails("http://localhost"), "GET", "127.0.0.1", null, null, cookies);
|
||||
var matcher = new RequestMessageCookieMatcher(MatchBehaviour.AcceptOnMatch, "cook", "test", true);
|
||||
[Fact]
|
||||
public void RequestMessageCookieMatcher_GetMatchingScore_CaseIgnoreForCookieValue()
|
||||
{
|
||||
// Assign
|
||||
var cookies = new Dictionary<string, string> { { "cook", "teST" } };
|
||||
var requestMessage = new RequestMessage(new UrlDetails("http://localhost"), "GET", "127.0.0.1", null, null, cookies);
|
||||
var matcher = new RequestMessageCookieMatcher(MatchBehaviour.AcceptOnMatch, "cook", "test", true);
|
||||
|
||||
// Act
|
||||
var result = new RequestMatchResult();
|
||||
double score = matcher.GetMatchingScore(requestMessage, result);
|
||||
// Act
|
||||
var result = new RequestMatchResult();
|
||||
double score = matcher.GetMatchingScore(requestMessage, result);
|
||||
|
||||
// Assert
|
||||
Check.That(score).IsEqualTo(1.0d);
|
||||
}
|
||||
// Assert
|
||||
Check.That(score).IsEqualTo(1.0d);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void RequestMessageCookieMatcher_GetMatchingScore_CaseIgnoreForCookieName()
|
||||
{
|
||||
// Assign
|
||||
var cookies = new Dictionary<string, string> { { "cook", "teST" } };
|
||||
var requestMessage = new RequestMessage(new UrlDetails("http://localhost"), "GET", "127.0.0.1", null, null, cookies);
|
||||
var matcher = new RequestMessageCookieMatcher(MatchBehaviour.AcceptOnMatch, "CooK", "test", true);
|
||||
[Fact]
|
||||
public void RequestMessageCookieMatcher_GetMatchingScore_CaseIgnoreForCookieName()
|
||||
{
|
||||
// Assign
|
||||
var cookies = new Dictionary<string, string> { { "cook", "teST" } };
|
||||
var requestMessage = new RequestMessage(new UrlDetails("http://localhost"), "GET", "127.0.0.1", null, null, cookies);
|
||||
var matcher = new RequestMessageCookieMatcher(MatchBehaviour.AcceptOnMatch, "CooK", "test", true);
|
||||
|
||||
// Act
|
||||
var result = new RequestMatchResult();
|
||||
double score = matcher.GetMatchingScore(requestMessage, result);
|
||||
// Act
|
||||
var result = new RequestMatchResult();
|
||||
double score = matcher.GetMatchingScore(requestMessage, result);
|
||||
|
||||
// Assert
|
||||
Check.That(score).IsEqualTo(1.0d);
|
||||
}
|
||||
// Assert
|
||||
Check.That(score).IsEqualTo(1.0d);
|
||||
}
|
||||
}
|
||||
@@ -7,193 +7,192 @@ using WireMock.Owin;
|
||||
using WireMock.Types;
|
||||
using Xunit;
|
||||
|
||||
namespace WireMock.Net.Tests.RequestMatchers
|
||||
namespace WireMock.Net.Tests.RequestMatchers;
|
||||
|
||||
public class RequestMessageParamMatcherTests
|
||||
{
|
||||
public class RequestMessageParamMatcherTests
|
||||
[Fact]
|
||||
public void RequestMessageParamMatcher_GetMatchingScore_IgnoreCaseKeyWithValuesPresentInUrl_And_With1StringValues_Returns1_0()
|
||||
{
|
||||
[Fact]
|
||||
public void RequestMessageParamMatcher_GetMatchingScore_IgnoreCaseKeyWithValuesPresentInUrl_And_With1StringValues_Returns1_0()
|
||||
// Assign
|
||||
var requestMessage = new RequestMessage(new UrlDetails("http://localhost?key=test1"), "GET", "127.0.0.1");
|
||||
var matcher = new RequestMessageParamMatcher(MatchBehaviour.AcceptOnMatch, "KeY", true, new[] { "test1" });
|
||||
|
||||
// Act
|
||||
var result = new RequestMatchResult();
|
||||
double score = matcher.GetMatchingScore(requestMessage, result);
|
||||
|
||||
// Assert
|
||||
Check.That(score).IsEqualTo(1.0d);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void RequestMessageParamMatcher_GetMatchingScore_KeyWith1ValuePresentInUrl_And_With2Strings_Or_Returns0_5()
|
||||
{
|
||||
// Assign
|
||||
var requestMessage = new RequestMessage(new UrlDetails("http://localhost?key=test1"), "GET", "127.0.0.1");
|
||||
var matcher = new RequestMessageParamMatcher(MatchBehaviour.AcceptOnMatch, "key", false, new[] { "test1", "test2" });
|
||||
|
||||
// Act
|
||||
var result = new RequestMatchResult();
|
||||
double score = matcher.GetMatchingScore(requestMessage, result);
|
||||
|
||||
// Assert
|
||||
Check.That(score).IsEqualTo(0.5d);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void RequestMessageParamMatcher_GetMatchingScore_KeyWith3ValuesPresentInUrl_And_With1ExactStringWith2Patterns_Returns0_66()
|
||||
{
|
||||
// Assign
|
||||
var requestMessage = new RequestMessage(new UrlDetails("http://localhost?key=test1,test2,test3"), "GET", "127.0.0.1");
|
||||
var matcher = new RequestMessageParamMatcher(MatchBehaviour.AcceptOnMatch, "key", false, new IStringMatcher[] { new ExactMatcher("test1", "test2") });
|
||||
|
||||
// Act
|
||||
var result = new RequestMatchResult();
|
||||
double score = matcher.GetMatchingScore(requestMessage, result);
|
||||
|
||||
// Assert
|
||||
Check.That(score).IsCloseTo(0.66d, 0.1d);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void RequestMessageParamMatcher_GetMatchingScore_KeyWith2ValuesPresentInUrl_And_With1ExactStringWith3Patterns_Returns0_66()
|
||||
{
|
||||
// Assign
|
||||
var requestMessage = new RequestMessage(new UrlDetails("http://localhost?key=test1,test2"), "GET", "127.0.0.1");
|
||||
var matcher = new RequestMessageParamMatcher(MatchBehaviour.AcceptOnMatch, "key", false, new IStringMatcher[] { new ExactMatcher("test1", "test2", "test3") });
|
||||
|
||||
// Act
|
||||
var result = new RequestMatchResult();
|
||||
double score = matcher.GetMatchingScore(requestMessage, result);
|
||||
|
||||
// Assert
|
||||
Check.That(score).IsCloseTo(0.66d, 0.1d);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void RequestMessageParamMatcher_GetMatchingScore_KeyWith2ValuesPresentInUrl_And_With2Strings_Returns1_0()
|
||||
{
|
||||
// Assign
|
||||
var requestMessage = new RequestMessage(new UrlDetails("http://localhost?key=test1,test2"), "GET", "127.0.0.1");
|
||||
var matcher = new RequestMessageParamMatcher(MatchBehaviour.AcceptOnMatch, "key", false, new[] { "test1", "test2" });
|
||||
|
||||
// Act
|
||||
var result = new RequestMatchResult();
|
||||
double score = matcher.GetMatchingScore(requestMessage, result);
|
||||
|
||||
// Assert
|
||||
Check.That(score).IsEqualTo(1.0d);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void RequestMessageParamMatcher_GetMatchingScore_KeyWith2ValuesPresentInUrl_And_With2ExactStringMatchers_Returns1_0()
|
||||
{
|
||||
// Assign
|
||||
var requestMessage = new RequestMessage(new UrlDetails("http://localhost?key=test1,test2"), "GET", "127.0.0.1");
|
||||
var matcher = new RequestMessageParamMatcher(MatchBehaviour.AcceptOnMatch, "key", false, new IStringMatcher[] { new ExactMatcher("test1"), new ExactMatcher("test2") });
|
||||
|
||||
// Act
|
||||
var result = new RequestMatchResult();
|
||||
double score = matcher.GetMatchingScore(requestMessage, result);
|
||||
|
||||
// Assert
|
||||
Check.That(score).IsEqualTo(1.0d);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void RequestMessageParamMatcher_GetMatchingScore_KeyWithValuesPresentInUrl_MatchOnKeyWithValues_PartialMatch()
|
||||
{
|
||||
// Assign
|
||||
var requestMessage = new RequestMessage(new UrlDetails("http://localhost?key=test0,test2"), "GET", "127.0.0.1");
|
||||
var matcher = new RequestMessageParamMatcher(MatchBehaviour.AcceptOnMatch, "key", false, new[] { "test1", "test2" });
|
||||
|
||||
// Act
|
||||
var result = new RequestMatchResult();
|
||||
double score = matcher.GetMatchingScore(requestMessage, result);
|
||||
|
||||
// Assert
|
||||
Check.That(score).IsEqualTo(0.5d);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void RequestMessageParamMatcher_GetMatchingScore_OnlyKeyPresentInUrl_MatchOnKeyWithValues_Fails()
|
||||
{
|
||||
// Assign
|
||||
var requestMessage = new RequestMessage(new UrlDetails("http://localhost?key"), "GET", "127.0.0.1");
|
||||
var matcher = new RequestMessageParamMatcher(MatchBehaviour.AcceptOnMatch, "key", false, new[] { "test1", "test2" });
|
||||
|
||||
// Act
|
||||
var result = new RequestMatchResult();
|
||||
double score = matcher.GetMatchingScore(requestMessage, result);
|
||||
|
||||
// Assert
|
||||
Check.That(score).IsEqualTo(0.0d);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void RequestMessageParamMatcher_GetMatchingScore_OnlyKeyPresentInUrl_MatchOnKey()
|
||||
{
|
||||
// Assign
|
||||
var requestMessage = new RequestMessage(new UrlDetails("http://localhost?key"), "GET", "127.0.0.1");
|
||||
var matcher = new RequestMessageParamMatcher(MatchBehaviour.AcceptOnMatch, "key", false);
|
||||
|
||||
// Act
|
||||
var result = new RequestMatchResult();
|
||||
double score = matcher.GetMatchingScore(requestMessage, result);
|
||||
|
||||
// Assert
|
||||
Check.That(score).IsEqualTo(1.0d);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void RequestMessageParamMatcher_GetMatchingScore_OnlyKeyPresentInUrl_MatchOnKeyWithEmptyArray()
|
||||
{
|
||||
// Assign
|
||||
var requestMessage = new RequestMessage(new UrlDetails("http://localhost?key"), "GET", "127.0.0.1");
|
||||
var matcher = new RequestMessageParamMatcher(MatchBehaviour.AcceptOnMatch, "key", false, new string[] { });
|
||||
|
||||
// Act
|
||||
var result = new RequestMatchResult();
|
||||
double score = matcher.GetMatchingScore(requestMessage, result);
|
||||
|
||||
// Assert
|
||||
Check.That(score).IsEqualTo(1.0d);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void RequestMessageParamMatcher_GetMatchingScore_KeyWithValuePresentInUrl_MatchOnKey()
|
||||
{
|
||||
// Assign
|
||||
var requestMessage = new RequestMessage(new UrlDetails("http://localhost?key=frank@contoso.com"), "GET", "127.0.0.1");
|
||||
var matcher = new RequestMessageParamMatcher(MatchBehaviour.AcceptOnMatch, "key", false);
|
||||
|
||||
// Act
|
||||
var result = new RequestMatchResult();
|
||||
double score = matcher.GetMatchingScore(requestMessage, result);
|
||||
|
||||
// Assert
|
||||
Check.That(score).IsEqualTo(1.0d);
|
||||
}
|
||||
|
||||
// Issue #849
|
||||
[Fact]
|
||||
public void RequestMessageParamMatcher_With1ParamContainingComma_Using_QueryParameterMultipleValueSupport_NoComma()
|
||||
{
|
||||
// Assign
|
||||
var options = new WireMockMiddlewareOptions
|
||||
{
|
||||
// Assign
|
||||
var requestMessage = new RequestMessage(new UrlDetails("http://localhost?key=test1"), "GET", "127.0.0.1");
|
||||
var matcher = new RequestMessageParamMatcher(MatchBehaviour.AcceptOnMatch, "KeY", true, new[] { "test1" });
|
||||
QueryParameterMultipleValueSupport = QueryParameterMultipleValueSupport.NoComma
|
||||
};
|
||||
var requestMessage = new RequestMessage(options, new UrlDetails("http://localhost?query=SELECT id, value FROM table WHERE id = 1&test=42"), "GET", "127.0.0.1");
|
||||
var matcher = new RequestMessageParamMatcher(MatchBehaviour.AcceptOnMatch, "query", false, "SELECT id, value FROM table WHERE id = 1");
|
||||
|
||||
// Act
|
||||
var result = new RequestMatchResult();
|
||||
double score = matcher.GetMatchingScore(requestMessage, result);
|
||||
// Act
|
||||
var result = new RequestMatchResult();
|
||||
double score = matcher.GetMatchingScore(requestMessage, result);
|
||||
|
||||
// Assert
|
||||
Check.That(score).IsEqualTo(1.0d);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void RequestMessageParamMatcher_GetMatchingScore_KeyWith1ValuePresentInUrl_And_With2Strings_Or_Returns0_5()
|
||||
{
|
||||
// Assign
|
||||
var requestMessage = new RequestMessage(new UrlDetails("http://localhost?key=test1"), "GET", "127.0.0.1");
|
||||
var matcher = new RequestMessageParamMatcher(MatchBehaviour.AcceptOnMatch, "key", false, new[] { "test1", "test2" });
|
||||
|
||||
// Act
|
||||
var result = new RequestMatchResult();
|
||||
double score = matcher.GetMatchingScore(requestMessage, result);
|
||||
|
||||
// Assert
|
||||
Check.That(score).IsEqualTo(0.5d);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void RequestMessageParamMatcher_GetMatchingScore_KeyWith3ValuesPresentInUrl_And_With1ExactStringWith2Patterns_Returns0_66()
|
||||
{
|
||||
// Assign
|
||||
var requestMessage = new RequestMessage(new UrlDetails("http://localhost?key=test1,test2,test3"), "GET", "127.0.0.1");
|
||||
var matcher = new RequestMessageParamMatcher(MatchBehaviour.AcceptOnMatch, "key", false, new IStringMatcher[] { new ExactMatcher("test1", "test2") });
|
||||
|
||||
// Act
|
||||
var result = new RequestMatchResult();
|
||||
double score = matcher.GetMatchingScore(requestMessage, result);
|
||||
|
||||
// Assert
|
||||
Check.That(score).IsCloseTo(0.66d, 0.1d);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void RequestMessageParamMatcher_GetMatchingScore_KeyWith2ValuesPresentInUrl_And_With1ExactStringWith3Patterns_Returns0_66()
|
||||
{
|
||||
// Assign
|
||||
var requestMessage = new RequestMessage(new UrlDetails("http://localhost?key=test1,test2"), "GET", "127.0.0.1");
|
||||
var matcher = new RequestMessageParamMatcher(MatchBehaviour.AcceptOnMatch, "key", false, new IStringMatcher[] { new ExactMatcher("test1", "test2", "test3") });
|
||||
|
||||
// Act
|
||||
var result = new RequestMatchResult();
|
||||
double score = matcher.GetMatchingScore(requestMessage, result);
|
||||
|
||||
// Assert
|
||||
Check.That(score).IsCloseTo(0.66d, 0.1d);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void RequestMessageParamMatcher_GetMatchingScore_KeyWith2ValuesPresentInUrl_And_With2Strings_Returns1_0()
|
||||
{
|
||||
// Assign
|
||||
var requestMessage = new RequestMessage(new UrlDetails("http://localhost?key=test1,test2"), "GET", "127.0.0.1");
|
||||
var matcher = new RequestMessageParamMatcher(MatchBehaviour.AcceptOnMatch, "key", false, new[] { "test1", "test2" });
|
||||
|
||||
// Act
|
||||
var result = new RequestMatchResult();
|
||||
double score = matcher.GetMatchingScore(requestMessage, result);
|
||||
|
||||
// Assert
|
||||
Check.That(score).IsEqualTo(1.0d);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void RequestMessageParamMatcher_GetMatchingScore_KeyWith2ValuesPresentInUrl_And_With2ExactStringMatchers_Returns1_0()
|
||||
{
|
||||
// Assign
|
||||
var requestMessage = new RequestMessage(new UrlDetails("http://localhost?key=test1,test2"), "GET", "127.0.0.1");
|
||||
var matcher = new RequestMessageParamMatcher(MatchBehaviour.AcceptOnMatch, "key", false, new IStringMatcher[] { new ExactMatcher("test1"), new ExactMatcher("test2") });
|
||||
|
||||
// Act
|
||||
var result = new RequestMatchResult();
|
||||
double score = matcher.GetMatchingScore(requestMessage, result);
|
||||
|
||||
// Assert
|
||||
Check.That(score).IsEqualTo(1.0d);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void RequestMessageParamMatcher_GetMatchingScore_KeyWithValuesPresentInUrl_MatchOnKeyWithValues_PartialMatch()
|
||||
{
|
||||
// Assign
|
||||
var requestMessage = new RequestMessage(new UrlDetails("http://localhost?key=test0,test2"), "GET", "127.0.0.1");
|
||||
var matcher = new RequestMessageParamMatcher(MatchBehaviour.AcceptOnMatch, "key", false, new[] { "test1", "test2" });
|
||||
|
||||
// Act
|
||||
var result = new RequestMatchResult();
|
||||
double score = matcher.GetMatchingScore(requestMessage, result);
|
||||
|
||||
// Assert
|
||||
Check.That(score).IsEqualTo(0.5d);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void RequestMessageParamMatcher_GetMatchingScore_OnlyKeyPresentInUrl_MatchOnKeyWithValues_Fails()
|
||||
{
|
||||
// Assign
|
||||
var requestMessage = new RequestMessage(new UrlDetails("http://localhost?key"), "GET", "127.0.0.1");
|
||||
var matcher = new RequestMessageParamMatcher(MatchBehaviour.AcceptOnMatch, "key", false, new[] { "test1", "test2" });
|
||||
|
||||
// Act
|
||||
var result = new RequestMatchResult();
|
||||
double score = matcher.GetMatchingScore(requestMessage, result);
|
||||
|
||||
// Assert
|
||||
Check.That(score).IsEqualTo(0.0d);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void RequestMessageParamMatcher_GetMatchingScore_OnlyKeyPresentInUrl_MatchOnKey()
|
||||
{
|
||||
// Assign
|
||||
var requestMessage = new RequestMessage(new UrlDetails("http://localhost?key"), "GET", "127.0.0.1");
|
||||
var matcher = new RequestMessageParamMatcher(MatchBehaviour.AcceptOnMatch, "key", false);
|
||||
|
||||
// Act
|
||||
var result = new RequestMatchResult();
|
||||
double score = matcher.GetMatchingScore(requestMessage, result);
|
||||
|
||||
// Assert
|
||||
Check.That(score).IsEqualTo(1.0d);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void RequestMessageParamMatcher_GetMatchingScore_OnlyKeyPresentInUrl_MatchOnKeyWithEmptyArray()
|
||||
{
|
||||
// Assign
|
||||
var requestMessage = new RequestMessage(new UrlDetails("http://localhost?key"), "GET", "127.0.0.1");
|
||||
var matcher = new RequestMessageParamMatcher(MatchBehaviour.AcceptOnMatch, "key", false, new string[] { });
|
||||
|
||||
// Act
|
||||
var result = new RequestMatchResult();
|
||||
double score = matcher.GetMatchingScore(requestMessage, result);
|
||||
|
||||
// Assert
|
||||
Check.That(score).IsEqualTo(1.0d);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void RequestMessageParamMatcher_GetMatchingScore_KeyWithValuePresentInUrl_MatchOnKey()
|
||||
{
|
||||
// Assign
|
||||
var requestMessage = new RequestMessage(new UrlDetails("http://localhost?key=frank@contoso.com"), "GET", "127.0.0.1");
|
||||
var matcher = new RequestMessageParamMatcher(MatchBehaviour.AcceptOnMatch, "key", false);
|
||||
|
||||
// Act
|
||||
var result = new RequestMatchResult();
|
||||
double score = matcher.GetMatchingScore(requestMessage, result);
|
||||
|
||||
// Assert
|
||||
Check.That(score).IsEqualTo(1.0d);
|
||||
}
|
||||
|
||||
// Issue #849
|
||||
[Fact]
|
||||
public void RequestMessageParamMatcher_With1ParamContainingComma_Using_QueryParameterMultipleValueSupport_NoComma()
|
||||
{
|
||||
// Assign
|
||||
var options = new WireMockMiddlewareOptions
|
||||
{
|
||||
QueryParameterMultipleValueSupport = QueryParameterMultipleValueSupport.NoComma
|
||||
};
|
||||
var requestMessage = new RequestMessage(options, new UrlDetails("http://localhost?query=SELECT id, value FROM table WHERE id = 1&test=42"), "GET", "127.0.0.1");
|
||||
var matcher = new RequestMessageParamMatcher(MatchBehaviour.AcceptOnMatch, "query", false, "SELECT id, value FROM table WHERE id = 1");
|
||||
|
||||
// Act
|
||||
var result = new RequestMatchResult();
|
||||
double score = matcher.GetMatchingScore(requestMessage, result);
|
||||
|
||||
// Assert
|
||||
score.Should().Be(1.0);
|
||||
}
|
||||
// Assert
|
||||
score.Should().Be(1.0);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,16 @@
|
||||
{
|
||||
Request: {
|
||||
ClientIP: ::1,
|
||||
Path: /,
|
||||
AbsolutePath: /,
|
||||
Url: http://localhost/,
|
||||
AbsoluteUrl: http://localhost/,
|
||||
Method: post,
|
||||
BodyAsBytes: AA==,
|
||||
DetectedBodyType: Bytes
|
||||
},
|
||||
Response: {
|
||||
BodyAsBytes: AA==,
|
||||
DetectedBodyType: Bytes
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,14 @@
|
||||
{
|
||||
Request: {
|
||||
ClientIP: ::1,
|
||||
Path: /,
|
||||
AbsolutePath: /,
|
||||
Url: http://localhost/,
|
||||
AbsoluteUrl: http://localhost/,
|
||||
Method: get
|
||||
},
|
||||
Response: {
|
||||
BodyAsFile: test,
|
||||
DetectedBodyType: File
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,16 @@
|
||||
{
|
||||
Request: {
|
||||
ClientIP: ::1,
|
||||
Path: /,
|
||||
AbsolutePath: /,
|
||||
Url: http://localhost/,
|
||||
AbsoluteUrl: http://localhost/,
|
||||
Method: post,
|
||||
BodyAsBytes: AA==,
|
||||
DetectedBodyType: Bytes
|
||||
},
|
||||
Response: {
|
||||
Body: Func<IRequestMessage, string>,
|
||||
DetectedBodyType: String
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,16 @@
|
||||
{
|
||||
Request: {
|
||||
ClientIP: ::1,
|
||||
Path: /,
|
||||
AbsolutePath: /,
|
||||
Url: http://localhost/,
|
||||
AbsoluteUrl: http://localhost/,
|
||||
Method: get
|
||||
},
|
||||
Response: {
|
||||
BodyAsFile: test,
|
||||
DetectedBodyType: File,
|
||||
FaultType: EMPTY_RESPONSE,
|
||||
FaultPercentage: 0.5
|
||||
}
|
||||
}
|
||||
@@ -1,7 +1,10 @@
|
||||
using FluentAssertions;
|
||||
using NFluent;
|
||||
#if !(NET452 || NET461)
|
||||
using System.Threading.Tasks;
|
||||
using VerifyTests;
|
||||
using VerifyXunit;
|
||||
using WireMock.Logging;
|
||||
using WireMock.Models;
|
||||
using WireMock.Net.Tests.VerifyExtensions;
|
||||
using WireMock.Owin;
|
||||
using WireMock.ResponseBuilders;
|
||||
using WireMock.Serialization;
|
||||
@@ -11,8 +14,15 @@ using Xunit;
|
||||
|
||||
namespace WireMock.Net.Tests.Serialization;
|
||||
|
||||
[UsesVerify]
|
||||
public class LogEntryMapperTests
|
||||
{
|
||||
private static readonly VerifySettings VerifySettings = new();
|
||||
static LogEntryMapperTests()
|
||||
{
|
||||
VerifySettings.Init<LogEntryMapperTests>();
|
||||
}
|
||||
|
||||
private readonly IWireMockMiddlewareOptions _options = new WireMockMiddlewareOptions();
|
||||
|
||||
private readonly LogEntryMapper _sut;
|
||||
@@ -23,7 +33,7 @@ public class LogEntryMapperTests
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void LogEntryMapper_Map_LogEntry_Check_BodyTypeBytes()
|
||||
public Task LogEntryMapper_Map_LogEntry_Check_BodyTypeBytes()
|
||||
{
|
||||
// Assign
|
||||
var logEntry = new LogEntry
|
||||
@@ -51,23 +61,12 @@ public class LogEntryMapperTests
|
||||
// Act
|
||||
var result = _sut.Map(logEntry);
|
||||
|
||||
// Assert
|
||||
Check.That(result.Request.DetectedBodyType).IsEqualTo("Bytes");
|
||||
Check.That(result.Request.DetectedBodyTypeFromContentType).IsNull();
|
||||
Check.That(result.Request.BodyAsBytes).ContainsExactly(new byte[] { 0 });
|
||||
Check.That(result.Request.Body).IsNull();
|
||||
Check.That(result.Request.BodyAsJson).IsNull();
|
||||
|
||||
Check.That(result.Response.DetectedBodyType).IsEqualTo(BodyType.Bytes);
|
||||
Check.That(result.Response.DetectedBodyTypeFromContentType).IsNull();
|
||||
Check.That(result.Response.BodyAsBytes).ContainsExactly(new byte[] { 0 });
|
||||
Check.That(result.Response.Body).IsNull();
|
||||
Check.That(result.Response.BodyAsJson).IsNull();
|
||||
Check.That(result.Response.BodyAsFile).IsNull();
|
||||
// Verify
|
||||
return Verifier.Verify(result, VerifySettings);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void LogEntryMapper_Map_LogEntry_Check_ResponseBodyTypeFile()
|
||||
public Task LogEntryMapper_Map_LogEntry_Check_ResponseBodyTypeFile()
|
||||
{
|
||||
// Assign
|
||||
var logEntry = new LogEntry
|
||||
@@ -86,23 +85,12 @@ public class LogEntryMapperTests
|
||||
// Act
|
||||
var result = _sut.Map(logEntry);
|
||||
|
||||
// Assert
|
||||
Check.That(result.Request.DetectedBodyType).IsNull();
|
||||
Check.That(result.Request.DetectedBodyTypeFromContentType).IsNull();
|
||||
Check.That(result.Request.BodyAsBytes).IsNull();
|
||||
Check.That(result.Request.Body).IsNull();
|
||||
Check.That(result.Request.BodyAsJson).IsNull();
|
||||
|
||||
Check.That(result.Response.DetectedBodyType).IsEqualTo(BodyType.File);
|
||||
Check.That(result.Response.DetectedBodyTypeFromContentType).IsNull();
|
||||
Check.That(result.Request.BodyAsBytes).IsNull();
|
||||
Check.That(result.Response.Body).IsNull();
|
||||
Check.That(result.Response.BodyAsJson).IsNull();
|
||||
Check.That(result.Response.BodyAsFile).IsEqualTo("test");
|
||||
// Verify
|
||||
return Verifier.Verify(result, VerifySettings);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void LogEntryMapper_Map_LogEntry_WithFault()
|
||||
public Task LogEntryMapper_Map_LogEntry_WithFault()
|
||||
{
|
||||
// Assign
|
||||
var logEntry = new LogEntry
|
||||
@@ -123,13 +111,12 @@ public class LogEntryMapperTests
|
||||
// Act
|
||||
var result = _sut.Map(logEntry);
|
||||
|
||||
// Assert
|
||||
result.Response.FaultType.Should().Be("EMPTY_RESPONSE");
|
||||
result.Response.FaultPercentage.Should().Be(0.5);
|
||||
// Verify
|
||||
return Verifier.Verify(result, VerifySettings);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void LogEntryMapper_Map_LogEntry_WhenFuncIsUsed_And_DoNotSaveDynamicResponseInLogEntry_Is_True_Should_NotSave_StringResponse()
|
||||
public Task LogEntryMapper_Map_LogEntry_WhenFuncIsUsed_And_DoNotSaveDynamicResponseInLogEntry_Is_True_Should_NotSave_StringResponse()
|
||||
{
|
||||
// Assign
|
||||
var options = new WireMockMiddlewareOptions
|
||||
@@ -163,7 +150,8 @@ public class LogEntryMapperTests
|
||||
// Act
|
||||
var result = new LogEntryMapper(options).Map(logEntry);
|
||||
|
||||
// Assert
|
||||
result.Response.Body.Should().Be(isFuncUsed);
|
||||
// Verify
|
||||
return Verifier.Verify(result, VerifySettings);
|
||||
}
|
||||
}
|
||||
}
|
||||
#endif
|
||||
@@ -0,0 +1,127 @@
|
||||
#if !(NET452 || NET461 || NETCOREAPP3_1)
|
||||
using System;
|
||||
using System.Runtime.CompilerServices;
|
||||
using System.Threading.Tasks;
|
||||
using FluentAssertions;
|
||||
using VerifyTests;
|
||||
using VerifyXunit;
|
||||
using WireMock.RequestBuilders;
|
||||
using WireMock.ResponseBuilders;
|
||||
using WireMock.Serialization;
|
||||
using WireMock.Types;
|
||||
using Xunit;
|
||||
|
||||
namespace WireMock.Net.Tests.Serialization;
|
||||
|
||||
[UsesVerify]
|
||||
public partial class MappingConverterTests
|
||||
{
|
||||
|
||||
[ModuleInitializer]
|
||||
public static void ModuleInitializer()
|
||||
{
|
||||
VerifierSettings.DontScrubGuids();
|
||||
VerifierSettings.DontScrubDateTimes();
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public Task ToCSharpCode_With_Builder_And_AddStartIsTrue()
|
||||
{
|
||||
// Assign
|
||||
var mapping = CreateMapping();
|
||||
|
||||
// Act
|
||||
var code = _sut.ToCSharpCode(mapping, new MappingConverterSettings
|
||||
{
|
||||
AddStart = true,
|
||||
ConverterType = MappingConverterType.Builder
|
||||
});
|
||||
|
||||
// Assert
|
||||
code.Should().NotBeEmpty();
|
||||
|
||||
// Verify
|
||||
return Verifier.Verify(code);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public Task ToCSharpCode_With_Builder_And_AddStartIsFalse()
|
||||
{
|
||||
// Assign
|
||||
var mapping = CreateMapping();
|
||||
|
||||
// Act
|
||||
var code = _sut.ToCSharpCode(mapping, new MappingConverterSettings
|
||||
{
|
||||
AddStart = false,
|
||||
ConverterType = MappingConverterType.Builder
|
||||
});
|
||||
|
||||
// Assert
|
||||
code.Should().NotBeEmpty();
|
||||
|
||||
// Verify
|
||||
return Verifier.Verify(code);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public Task ToCSharpCode_With_Server_And_AddStartIsTrue()
|
||||
{
|
||||
// Assign
|
||||
var mapping = CreateMapping();
|
||||
|
||||
// Act
|
||||
var code = _sut.ToCSharpCode(mapping, new MappingConverterSettings
|
||||
{
|
||||
AddStart = true,
|
||||
ConverterType = MappingConverterType.Server
|
||||
});
|
||||
|
||||
// Assert
|
||||
code.Should().NotBeEmpty();
|
||||
|
||||
// Verify
|
||||
return Verifier.Verify(code);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public Task ToCSharpCode_With_Server_And_AddStartIsFalse()
|
||||
{
|
||||
// Assign
|
||||
var mapping = CreateMapping();
|
||||
|
||||
// Act
|
||||
var code = _sut.ToCSharpCode(mapping, new MappingConverterSettings
|
||||
{
|
||||
AddStart = false,
|
||||
ConverterType = MappingConverterType.Server
|
||||
});
|
||||
|
||||
// Assert
|
||||
code.Should().NotBeEmpty();
|
||||
|
||||
// Verify
|
||||
return Verifier.Verify(code);
|
||||
}
|
||||
|
||||
private Mapping CreateMapping()
|
||||
{
|
||||
var guid = new Guid("8e7b9ab7-e18e-4502-8bc9-11e6679811cc");
|
||||
var request = Request.Create()
|
||||
.UsingGet()
|
||||
.WithPath("test_path")
|
||||
.WithParam("q", "42")
|
||||
.WithClientIP("112.123.100.99")
|
||||
.WithHeader("h-key", "h-value")
|
||||
.WithCookie("c-key", "c-value")
|
||||
.WithBody("b");
|
||||
var response = Response.Create()
|
||||
.WithHeader("Keep-Alive", "test")
|
||||
.WithBody("bbb")
|
||||
.WithDelay(12345)
|
||||
.WithTransformer();
|
||||
|
||||
return new Mapping(guid, _updatedAt, string.Empty, string.Empty, null, _settings, request, response, 42, null, null, null, null, null, false, null);
|
||||
}
|
||||
}
|
||||
#endif
|
||||
@@ -0,0 +1,17 @@
|
||||
builder
|
||||
.Given(Request.Create()
|
||||
.UsingMethod("GET")
|
||||
.WithPath("test_path")
|
||||
.WithParam("q", "42")
|
||||
.WithClientIP("112.123.100.99")
|
||||
.WithHeader("h-key", "h-value", true)
|
||||
.WithCookie("c-key", "c-value", true)
|
||||
.WithBody("b")
|
||||
)
|
||||
.WithGuid("8e7b9ab7-e18e-4502-8bc9-11e6679811cc")
|
||||
.RespondWith(Response.Create()
|
||||
.WithHeader("Keep-Alive)", "test")
|
||||
.WithBody("bbb")
|
||||
.WithDelay(12345)
|
||||
.WithTransformer()
|
||||
);
|
||||
@@ -0,0 +1,18 @@
|
||||
var builder = new MappingBuilder();
|
||||
builder
|
||||
.Given(Request.Create()
|
||||
.UsingMethod("GET")
|
||||
.WithPath("test_path")
|
||||
.WithParam("q", "42")
|
||||
.WithClientIP("112.123.100.99")
|
||||
.WithHeader("h-key", "h-value", true)
|
||||
.WithCookie("c-key", "c-value", true)
|
||||
.WithBody("b")
|
||||
)
|
||||
.WithGuid("8e7b9ab7-e18e-4502-8bc9-11e6679811cc")
|
||||
.RespondWith(Response.Create()
|
||||
.WithHeader("Keep-Alive)", "test")
|
||||
.WithBody("bbb")
|
||||
.WithDelay(12345)
|
||||
.WithTransformer()
|
||||
);
|
||||
@@ -0,0 +1,17 @@
|
||||
server
|
||||
.Given(Request.Create()
|
||||
.UsingMethod("GET")
|
||||
.WithPath("test_path")
|
||||
.WithParam("q", "42")
|
||||
.WithClientIP("112.123.100.99")
|
||||
.WithHeader("h-key", "h-value", true)
|
||||
.WithCookie("c-key", "c-value", true)
|
||||
.WithBody("b")
|
||||
)
|
||||
.WithGuid("8e7b9ab7-e18e-4502-8bc9-11e6679811cc")
|
||||
.RespondWith(Response.Create()
|
||||
.WithHeader("Keep-Alive)", "test")
|
||||
.WithBody("bbb")
|
||||
.WithDelay(12345)
|
||||
.WithTransformer()
|
||||
);
|
||||
@@ -0,0 +1,18 @@
|
||||
var server = WireMockServer.Start();
|
||||
server
|
||||
.Given(Request.Create()
|
||||
.UsingMethod("GET")
|
||||
.WithPath("test_path")
|
||||
.WithParam("q", "42")
|
||||
.WithClientIP("112.123.100.99")
|
||||
.WithHeader("h-key", "h-value", true)
|
||||
.WithCookie("c-key", "c-value", true)
|
||||
.WithBody("b")
|
||||
)
|
||||
.WithGuid("8e7b9ab7-e18e-4502-8bc9-11e6679811cc")
|
||||
.RespondWith(Response.Create()
|
||||
.WithHeader("Keep-Alive)", "test")
|
||||
.WithBody("bbb")
|
||||
.WithDelay(12345)
|
||||
.WithTransformer()
|
||||
);
|
||||
@@ -0,0 +1,12 @@
|
||||
{
|
||||
Guid: c8eeaf99-d5c4-4341-8543-4597c3fd40d9,
|
||||
UpdatedAt: 2022-12-04 11:12:13,
|
||||
Title: ,
|
||||
Description: ,
|
||||
Priority: 42,
|
||||
Request: {},
|
||||
Response: {
|
||||
Delay: 1000
|
||||
},
|
||||
UseWebhooksFireAndForget: false
|
||||
}
|
||||
@@ -0,0 +1,17 @@
|
||||
{
|
||||
Guid: c8eeaf99-d5c4-4341-8543-4597c3fd40d9,
|
||||
UpdatedAt: 2022-12-04 11:12:13,
|
||||
Title: ,
|
||||
Description: ,
|
||||
Priority: 42,
|
||||
Request: {},
|
||||
Response: {
|
||||
BodyAsJson: {
|
||||
x: x
|
||||
},
|
||||
UseTransformer: true,
|
||||
TransformerType: Handlebars,
|
||||
TransformerReplaceNodeOptions: Evaluate
|
||||
},
|
||||
UseWebhooksFireAndForget: false
|
||||
}
|
||||
@@ -0,0 +1,13 @@
|
||||
{
|
||||
Guid: c8eeaf99-d5c4-4341-8543-4597c3fd40d9,
|
||||
UpdatedAt: 2022-12-04 11:12:13,
|
||||
Title: ,
|
||||
Description: ,
|
||||
Priority: 42,
|
||||
Request: {},
|
||||
Response: {
|
||||
MinimumRandomDelay: 1000,
|
||||
MaximumRandomDelay: 2000
|
||||
},
|
||||
UseWebhooksFireAndForget: false
|
||||
}
|
||||
@@ -0,0 +1,13 @@
|
||||
{
|
||||
Guid: c8eeaf99-d5c4-4341-8543-4597c3fd40d9,
|
||||
UpdatedAt: 2022-12-04 11:12:13,
|
||||
Title: ,
|
||||
Description: ,
|
||||
Priority: 42,
|
||||
Request: {},
|
||||
Response: {
|
||||
MinimumRandomDelay: 1000,
|
||||
MaximumRandomDelay: 60000
|
||||
},
|
||||
UseWebhooksFireAndForget: false
|
||||
}
|
||||
@@ -0,0 +1,15 @@
|
||||
{
|
||||
Guid: c8eeaf99-d5c4-4341-8543-4597c3fd40d9,
|
||||
UpdatedAt: 2022-12-04 11:12:13,
|
||||
TimeSettings: {
|
||||
Start: 2023-01-14 15:16:17,
|
||||
End: 2023-01-14 15:17:57,
|
||||
TTL: 100
|
||||
},
|
||||
Title: ,
|
||||
Description: ,
|
||||
Priority: 42,
|
||||
Request: {},
|
||||
Response: {},
|
||||
UseWebhooksFireAndForget: false
|
||||
}
|
||||
@@ -0,0 +1,9 @@
|
||||
{
|
||||
Guid: c8eeaf99-d5c4-4341-8543-4597c3fd40d9,
|
||||
UpdatedAt: 2022-12-04 11:12:13,
|
||||
Title: my-title,
|
||||
Description: my-description,
|
||||
Request: {},
|
||||
Response: {},
|
||||
UseWebhooksFireAndForget: false
|
||||
}
|
||||
@@ -0,0 +1,34 @@
|
||||
{
|
||||
Guid: c8eeaf99-d5c4-4341-8543-4597c3fd40d9,
|
||||
UpdatedAt: 2022-12-04 11:12:13,
|
||||
Title: ,
|
||||
Description: ,
|
||||
Request: {},
|
||||
Response: {},
|
||||
Webhooks: [
|
||||
{
|
||||
Request: {
|
||||
Url: https://test1.com,
|
||||
Method: post,
|
||||
Headers: {
|
||||
One: x
|
||||
},
|
||||
Body: 1,
|
||||
TransformerReplaceNodeOptions: EvaluateAndTryToConvert
|
||||
}
|
||||
},
|
||||
{
|
||||
Request: {
|
||||
Url: https://test2.com,
|
||||
Method: post,
|
||||
Headers: {
|
||||
First: x,
|
||||
Second: a, b
|
||||
},
|
||||
Body: 2,
|
||||
TransformerReplaceNodeOptions: EvaluateAndTryToConvert
|
||||
}
|
||||
}
|
||||
],
|
||||
UseWebhooksFireAndForget: true
|
||||
}
|
||||
@@ -0,0 +1,21 @@
|
||||
{
|
||||
Guid: c8eeaf99-d5c4-4341-8543-4597c3fd40d9,
|
||||
UpdatedAt: 2022-12-04 11:12:13,
|
||||
Title: ,
|
||||
Description: ,
|
||||
Request: {},
|
||||
Response: {},
|
||||
Webhook: {
|
||||
Request: {
|
||||
Url: https://test.com,
|
||||
Method: post,
|
||||
Headers: {
|
||||
Multi: a, b,
|
||||
Single: x
|
||||
},
|
||||
Body: b,
|
||||
TransformerReplaceNodeOptions: EvaluateAndTryToConvert
|
||||
}
|
||||
},
|
||||
UseWebhooksFireAndForget: false
|
||||
}
|
||||
@@ -1,7 +1,12 @@
|
||||
#if !(NET452 || NET461 || NETCOREAPP3_1)
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Runtime.CompilerServices;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
using FluentAssertions;
|
||||
using VerifyTests;
|
||||
using VerifyXunit;
|
||||
using WireMock.Models;
|
||||
using WireMock.RequestBuilders;
|
||||
using WireMock.ResponseBuilders;
|
||||
@@ -13,9 +18,10 @@ using Xunit;
|
||||
|
||||
namespace WireMock.Net.Tests.Serialization;
|
||||
|
||||
public class MappingConverterTests
|
||||
public partial class MappingConverterTests
|
||||
{
|
||||
private readonly DateTime _updatedAt = new(2022, 12, 4);
|
||||
private readonly Guid _guid = new("c8eeaf99-d5c4-4341-8543-4597c3fd40d9");
|
||||
private readonly DateTime _updatedAt = new(2022, 12, 4, 11, 12, 13);
|
||||
private readonly WireMockServerSettings _settings = new();
|
||||
|
||||
private readonly MappingConverter _sut;
|
||||
@@ -26,7 +32,7 @@ public class MappingConverterTests
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void ToMappingModel_With_SingleWebHook()
|
||||
public Task ToMappingModel_With_SingleWebHook()
|
||||
{
|
||||
// Assign
|
||||
var request = Request.Create();
|
||||
@@ -53,7 +59,7 @@ public class MappingConverterTests
|
||||
}
|
||||
}
|
||||
};
|
||||
var mapping = new Mapping(Guid.NewGuid(), _updatedAt, string.Empty, string.Empty, null, _settings, request, response, 0, null, null, null, null, webhooks, false, null);
|
||||
var mapping = new Mapping(_guid, _updatedAt, string.Empty, string.Empty, null, _settings, request, response, 0, null, null, null, null, webhooks, false, null);
|
||||
|
||||
// Act
|
||||
var model = _sut.ToMappingModel(mapping);
|
||||
@@ -74,10 +80,13 @@ public class MappingConverterTests
|
||||
model.Webhook.Request.Headers.Should().HaveCount(2);
|
||||
model.Webhook.Request.Body.Should().Be("b");
|
||||
model.Webhook.Request.BodyAsJson.Should().BeNull();
|
||||
|
||||
// Verify
|
||||
return Verifier.Verify(model);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void ToMappingModel_With_MultipleWebHooks()
|
||||
public Task ToMappingModel_With_MultipleWebHooks()
|
||||
{
|
||||
// Assign
|
||||
var request = Request.Create();
|
||||
@@ -123,7 +132,7 @@ public class MappingConverterTests
|
||||
}
|
||||
}
|
||||
};
|
||||
var mapping = new Mapping(Guid.NewGuid(), _updatedAt, string.Empty, string.Empty, null, _settings, request, response, 0, null, null, null, null, webhooks, true, null);
|
||||
var mapping = new Mapping(_guid, _updatedAt, string.Empty, string.Empty, null, _settings, request, response, 0, null, null, null, null, webhooks, true, null);
|
||||
|
||||
// Act
|
||||
var model = _sut.ToMappingModel(mapping);
|
||||
@@ -148,17 +157,20 @@ public class MappingConverterTests
|
||||
model.Webhooks[1].Request.Url.Should().Be("https://test2.com");
|
||||
model.Webhooks[1].Request.Headers.Should().HaveCount(2);
|
||||
model.Webhooks[1].Request.Body.Should().Be("2");
|
||||
|
||||
// Verify
|
||||
return Verifier.Verify(model);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void ToMappingModel_WithTitle_And_Description_ReturnsCorrectModel()
|
||||
public Task ToMappingModel_WithTitle_And_Description_ReturnsCorrectModel()
|
||||
{
|
||||
// Assign
|
||||
var title = "my-title";
|
||||
var description = "my-description";
|
||||
var request = Request.Create();
|
||||
var response = Response.Create();
|
||||
var mapping = new Mapping(Guid.NewGuid(), _updatedAt, title, description, null, _settings, request, response, 0, null, null, null, null, null, false, null);
|
||||
var mapping = new Mapping(_guid, _updatedAt, title, description, null, _settings, request, response, 0, null, null, null, null, null, false, null);
|
||||
|
||||
// Act
|
||||
var model = _sut.ToMappingModel(mapping);
|
||||
@@ -167,15 +179,18 @@ public class MappingConverterTests
|
||||
model.Should().NotBeNull();
|
||||
model.Title.Should().Be(title);
|
||||
model.Description.Should().Be(description);
|
||||
|
||||
// Verify
|
||||
return Verifier.Verify(model);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void ToMappingModel_WithPriority_ReturnsPriority()
|
||||
public Task ToMappingModel_WithPriority_ReturnsPriority()
|
||||
{
|
||||
// Assign
|
||||
var request = Request.Create();
|
||||
var response = Response.Create().WithBodyAsJson(new { x = "x" }).WithTransformer();
|
||||
var mapping = new Mapping(Guid.NewGuid(), _updatedAt, string.Empty, string.Empty, null, _settings, request, response, 42, null, null, null, null, null, false, null);
|
||||
var mapping = new Mapping(_guid, _updatedAt, string.Empty, string.Empty, null, _settings, request, response, 42, null, null, null, null, null, false, null);
|
||||
|
||||
// Act
|
||||
var model = _sut.ToMappingModel(mapping);
|
||||
@@ -184,13 +199,16 @@ public class MappingConverterTests
|
||||
model.Should().NotBeNull();
|
||||
model.Priority.Should().Be(42);
|
||||
model.Response.UseTransformer.Should().BeTrue();
|
||||
|
||||
// Verify
|
||||
return Verifier.Verify(model);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void ToMappingModel_WithTimeSettings_ReturnsCorrectTimeSettings()
|
||||
public Task ToMappingModel_WithTimeSettings_ReturnsCorrectTimeSettings()
|
||||
{
|
||||
// Assign
|
||||
var start = DateTime.Now;
|
||||
var start = new DateTime(2023, 1, 14, 15, 16, 17);
|
||||
var ttl = 100;
|
||||
var end = start.AddSeconds(ttl);
|
||||
var request = Request.Create();
|
||||
@@ -201,7 +219,7 @@ public class MappingConverterTests
|
||||
End = end,
|
||||
TTL = ttl
|
||||
};
|
||||
var mapping = new Mapping(Guid.NewGuid(), _updatedAt, string.Empty, string.Empty, null, _settings, request, response, 42, null, null, null, null, null, false, timeSettings);
|
||||
var mapping = new Mapping(_guid, _updatedAt, string.Empty, string.Empty, null, _settings, request, response, 42, null, null, null, null, null, false, timeSettings);
|
||||
|
||||
// Act
|
||||
var model = _sut.ToMappingModel(mapping);
|
||||
@@ -212,6 +230,9 @@ public class MappingConverterTests
|
||||
model.TimeSettings!.Start.Should().Be(start);
|
||||
model.TimeSettings.End.Should().Be(end);
|
||||
model.TimeSettings.TTL.Should().Be(ttl);
|
||||
|
||||
// Verify
|
||||
return Verifier.Verify(model);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
@@ -241,13 +262,13 @@ public class MappingConverterTests
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void ToMappingModel_WithDelayAsMilleSeconds_ReturnsCorrectModel()
|
||||
public Task ToMappingModel_WithDelayAsMilleSeconds_ReturnsCorrectModel()
|
||||
{
|
||||
// Assign
|
||||
var delay = 1000;
|
||||
var request = Request.Create();
|
||||
var response = Response.Create().WithDelay(delay);
|
||||
var mapping = new Mapping(Guid.NewGuid(), _updatedAt, string.Empty, string.Empty, null, _settings, request, response, 42, null, null, null, null, null, false, null);
|
||||
var mapping = new Mapping(_guid, _updatedAt, string.Empty, string.Empty, null, _settings, request, response, 42, null, null, null, null, null, false, null);
|
||||
|
||||
// Act
|
||||
var model = _sut.ToMappingModel(mapping);
|
||||
@@ -255,16 +276,19 @@ public class MappingConverterTests
|
||||
// Assert
|
||||
model.Should().NotBeNull();
|
||||
model.Response.Delay.Should().Be(delay);
|
||||
|
||||
// Verify
|
||||
return Verifier.Verify(model);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void ToMappingModel_WithRandomMinimumDelay_ReturnsCorrectModel()
|
||||
public Task ToMappingModel_WithRandomMinimumDelay_ReturnsCorrectModel()
|
||||
{
|
||||
// Assign
|
||||
int minimumDelay = 1000;
|
||||
var request = Request.Create();
|
||||
var response = Response.Create().WithRandomDelay(minimumDelay);
|
||||
var mapping = new Mapping(Guid.NewGuid(), _updatedAt, string.Empty, string.Empty, null, _settings, request, response, 42, null, null, null, null, null, false, null);
|
||||
var mapping = new Mapping(_guid, _updatedAt, string.Empty, string.Empty, null, _settings, request, response, 42, null, null, null, null, null, false, null);
|
||||
|
||||
// Act
|
||||
var model = _sut.ToMappingModel(mapping);
|
||||
@@ -274,17 +298,20 @@ public class MappingConverterTests
|
||||
model.Response.Delay.Should().BeNull();
|
||||
model.Response.MinimumRandomDelay.Should().Be(minimumDelay);
|
||||
model.Response.MaximumRandomDelay.Should().Be(60_000);
|
||||
|
||||
// Verify
|
||||
return Verifier.Verify(model);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void ToMappingModel_WithRandomDelay_ReturnsCorrectModel()
|
||||
public Task ToMappingModel_WithRandomDelay_ReturnsCorrectModel()
|
||||
{
|
||||
// Assign
|
||||
int minimumDelay = 1000;
|
||||
int maximumDelay = 2000;
|
||||
var request = Request.Create();
|
||||
var response = Response.Create().WithRandomDelay(minimumDelay, maximumDelay);
|
||||
var mapping = new Mapping(Guid.NewGuid(), _updatedAt, string.Empty, string.Empty, null, _settings, request, response, 42, null, null, null, null, null, false, null);
|
||||
var mapping = new Mapping(_guid, _updatedAt, string.Empty, string.Empty, null, _settings, request, response, 42, null, null, null, null, null, false, null);
|
||||
|
||||
// Act
|
||||
var model = _sut.ToMappingModel(mapping);
|
||||
@@ -294,5 +321,9 @@ public class MappingConverterTests
|
||||
model.Response.Delay.Should().BeNull();
|
||||
model.Response.MinimumRandomDelay.Should().Be(minimumDelay);
|
||||
model.Response.MaximumRandomDelay.Should().Be(maximumDelay);
|
||||
|
||||
// Verify
|
||||
return Verifier.Verify(model);
|
||||
}
|
||||
}
|
||||
}
|
||||
#endif
|
||||
@@ -0,0 +1,75 @@
|
||||
{
|
||||
Guid: ff55ac0a-fea9-4d7b-be74-5e483a2c1305,
|
||||
UpdatedAt: 2022-12-04,
|
||||
Title: my title,
|
||||
Description: my description,
|
||||
Priority: -2000000,
|
||||
Request: {
|
||||
Path: {
|
||||
Matchers: [
|
||||
{
|
||||
Name: WildcardMatcher,
|
||||
Pattern: x,
|
||||
IgnoreCase: false
|
||||
}
|
||||
]
|
||||
},
|
||||
Methods: [
|
||||
POST
|
||||
],
|
||||
Headers: [
|
||||
{
|
||||
Name: Content-Type,
|
||||
Matchers: [
|
||||
{
|
||||
Name: ContentTypeMatcher,
|
||||
Pattern: text/plain,
|
||||
IgnoreCase: false
|
||||
}
|
||||
]
|
||||
}
|
||||
],
|
||||
Cookies: [
|
||||
{
|
||||
Name: c,
|
||||
Matchers: [
|
||||
{
|
||||
Name: WildcardMatcher,
|
||||
Pattern: x,
|
||||
IgnoreCase: true
|
||||
}
|
||||
]
|
||||
}
|
||||
],
|
||||
Params: [
|
||||
{
|
||||
Name: p1,
|
||||
Matchers: [
|
||||
{
|
||||
Name: ExactMatcher,
|
||||
Pattern: p1-v,
|
||||
IgnoreCase: false
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
Name: p2,
|
||||
Matchers: [
|
||||
{
|
||||
Name: ExactMatcher,
|
||||
Pattern: p2-v,
|
||||
IgnoreCase: false
|
||||
}
|
||||
]
|
||||
}
|
||||
],
|
||||
Body: {
|
||||
Matcher: {
|
||||
Name: RegexMatcher,
|
||||
Pattern: <RequestType>Auth</RequestType>,
|
||||
IgnoreCase: false
|
||||
}
|
||||
}
|
||||
},
|
||||
Response: {}
|
||||
}
|
||||
@@ -1,8 +1,10 @@
|
||||
#if !(NET452 || NET461 || NETCOREAPP3_1)
|
||||
using System;
|
||||
using System.Runtime.CompilerServices;
|
||||
using System.Threading.Tasks;
|
||||
using Moq;
|
||||
using Newtonsoft.Json;
|
||||
using System.IO;
|
||||
using FluentAssertions;
|
||||
using VerifyTests;
|
||||
using VerifyXunit;
|
||||
using WireMock.Matchers;
|
||||
using WireMock.RequestBuilders;
|
||||
using WireMock.Serialization;
|
||||
@@ -12,6 +14,7 @@ using Xunit;
|
||||
|
||||
namespace WireMock.Net.Tests.Serialization;
|
||||
|
||||
[UsesVerify]
|
||||
public class ProxyMappingConverterTests
|
||||
{
|
||||
private readonly WireMockServerSettings _settings = new();
|
||||
@@ -33,8 +36,15 @@ public class ProxyMappingConverterTests
|
||||
_sut = new ProxyMappingConverter(_settings, guidUtilsMock.Object, dateTimeUtilsMock.Object);
|
||||
}
|
||||
|
||||
[ModuleInitializer]
|
||||
public static void ModuleInitializer()
|
||||
{
|
||||
VerifierSettings.DontScrubGuids();
|
||||
VerifierSettings.DontScrubDateTimes();
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void ToMapping_UseDefinedRequestMatchers_True()
|
||||
public Task ToMapping_UseDefinedRequestMatchers_True()
|
||||
{
|
||||
// Arrange
|
||||
var proxyAndRecordSettings = new ProxyAndRecordSettings
|
||||
@@ -49,7 +59,7 @@ public class ProxyMappingConverterTests
|
||||
.WithParam("p2", "p2-v")
|
||||
.WithHeader("Content-Type", new ContentTypeMatcher("text/plain"))
|
||||
.WithCookie("c", "x")
|
||||
.WithBody(new RegexMatcher("<RequestType>Auth</RequestType"));
|
||||
.WithBody(new RegexMatcher("<RequestType>Auth</RequestType>"));
|
||||
|
||||
var mappingMock = new Mock<IMapping>();
|
||||
mappingMock.SetupGet(m => m.RequestMatcher).Returns(request);
|
||||
@@ -65,9 +75,9 @@ public class ProxyMappingConverterTests
|
||||
|
||||
// Assert
|
||||
var model = _mappingConverter.ToMappingModel(proxyMapping);
|
||||
var json = JsonConvert.SerializeObject(model, JsonSerializationConstants.JsonSerializerSettingsDefault);
|
||||
var expected = File.ReadAllText(Path.Combine("../../../", "Serialization", "files", "proxy.json"));
|
||||
|
||||
json.Should().Be(expected);
|
||||
// Verify
|
||||
return Verifier.Verify(model);
|
||||
}
|
||||
}
|
||||
}
|
||||
#endif
|
||||
@@ -0,0 +1,21 @@
|
||||
{
|
||||
Request: {
|
||||
Url: https://localhost,
|
||||
Method: get,
|
||||
Headers: {
|
||||
x: [
|
||||
y
|
||||
]
|
||||
},
|
||||
BodyData: {
|
||||
BodyAsJson: {
|
||||
n: 12345
|
||||
},
|
||||
DetectedBodyType: Json,
|
||||
DetectedBodyTypeFromContentType: Bytes
|
||||
},
|
||||
Delay: 4,
|
||||
MinimumRandomDelay: 5,
|
||||
MaximumRandomDelay: 6
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,16 @@
|
||||
{
|
||||
Request: {
|
||||
Url: https://localhost,
|
||||
Method: get,
|
||||
Headers: {
|
||||
x: [
|
||||
y
|
||||
]
|
||||
},
|
||||
BodyData: {
|
||||
BodyAsString: test,
|
||||
DetectedBodyType: String,
|
||||
DetectedBodyTypeFromContentType: Bytes
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,18 @@
|
||||
{
|
||||
Request: {
|
||||
Url: https://localhost,
|
||||
Method: get,
|
||||
Headers: {
|
||||
x: [
|
||||
y
|
||||
]
|
||||
},
|
||||
BodyData: {
|
||||
BodyAsString: test,
|
||||
DetectedBodyType: String,
|
||||
DetectedBodyTypeFromContentType: Bytes
|
||||
},
|
||||
UseTransformer: true,
|
||||
TransformerReplaceNodeOptions: Evaluate
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,16 @@
|
||||
{
|
||||
Request: {
|
||||
Url: https://localhost,
|
||||
Method: get,
|
||||
Headers: {
|
||||
x: y
|
||||
},
|
||||
BodyAsJson: {
|
||||
n: 12345
|
||||
},
|
||||
TransformerReplaceNodeOptions: EvaluateAndTryToConvert,
|
||||
Delay: 4,
|
||||
MinimumRandomDelay: 5,
|
||||
MaximumRandomDelay: 6
|
||||
}
|
||||
}
|
||||
@@ -1,5 +1,9 @@
|
||||
#if !(NET452 || NET461 || NETCOREAPP3_1)
|
||||
using System.Collections.Generic;
|
||||
using FluentAssertions;
|
||||
using System.Runtime.CompilerServices;
|
||||
using System.Threading.Tasks;
|
||||
using VerifyTests;
|
||||
using VerifyXunit;
|
||||
using WireMock.Admin.Mappings;
|
||||
using WireMock.Models;
|
||||
using WireMock.Serialization;
|
||||
@@ -9,10 +13,18 @@ using Xunit;
|
||||
|
||||
namespace WireMock.Net.Tests.Serialization;
|
||||
|
||||
[UsesVerify]
|
||||
public class WebhookMapperTests
|
||||
{
|
||||
[ModuleInitializer]
|
||||
public static void ModuleInitializer()
|
||||
{
|
||||
VerifierSettings.DontScrubGuids();
|
||||
VerifierSettings.DontScrubDateTimes();
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void WebhookMapper_Map_WebhookModel_BodyAsString_And_UseTransformerIsFalse()
|
||||
public Task WebhookMapper_Map_WebhookModel_BodyAsString_And_UseTransformerIsFalse()
|
||||
{
|
||||
// Assign
|
||||
var model = new WebhookModel
|
||||
@@ -32,17 +44,12 @@ public class WebhookMapperTests
|
||||
|
||||
var result = WebhookMapper.Map(model);
|
||||
|
||||
result.Request.Url.Should().Be("https://localhost");
|
||||
result.Request.Method.Should().Be("get");
|
||||
result.Request.Headers.Should().HaveCount(1);
|
||||
result.Request.BodyData!.BodyAsJson.Should().BeNull();
|
||||
result.Request.BodyData.BodyAsString.Should().Be("test");
|
||||
result.Request.BodyData.DetectedBodyType.Should().Be(BodyType.String);
|
||||
result.Request.UseTransformer.Should().BeNull();
|
||||
// Verify
|
||||
return Verifier.Verify(result);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void WebhookMapper_Map_WebhookModel_BodyAsString_And_UseTransformerIsTrue()
|
||||
public Task WebhookMapper_Map_WebhookModel_BodyAsString_And_UseTransformerIsTrue()
|
||||
{
|
||||
// Assign
|
||||
var model = new WebhookModel
|
||||
@@ -62,18 +69,12 @@ public class WebhookMapperTests
|
||||
|
||||
var result = WebhookMapper.Map(model);
|
||||
|
||||
result.Request.Url.Should().Be("https://localhost");
|
||||
result.Request.Method.Should().Be("get");
|
||||
result.Request.Headers.Should().HaveCount(1);
|
||||
result.Request.BodyData!.BodyAsJson.Should().BeNull();
|
||||
result.Request.BodyData.BodyAsString.Should().Be("test");
|
||||
result.Request.BodyData.DetectedBodyType.Should().Be(BodyType.String);
|
||||
result.Request.UseTransformer.Should().BeTrue();
|
||||
result.Request.TransformerType.Should().Be(TransformerType.Handlebars);
|
||||
// Verify
|
||||
return Verifier.Verify(result);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void WebhookMapper_Map_WebhookModel_BodyAsJson()
|
||||
public Task WebhookMapper_Map_WebhookModel_BodyAsJson()
|
||||
{
|
||||
// Assign
|
||||
var model = new WebhookModel
|
||||
@@ -95,19 +96,12 @@ public class WebhookMapperTests
|
||||
|
||||
var result = WebhookMapper.Map(model);
|
||||
|
||||
result.Request.Url.Should().Be("https://localhost");
|
||||
result.Request.Method.Should().Be("get");
|
||||
result.Request.Headers.Should().HaveCount(1);
|
||||
result.Request.BodyData!.BodyAsString.Should().BeNull();
|
||||
result.Request.BodyData.BodyAsJson.Should().NotBeNull();
|
||||
result.Request.BodyData.DetectedBodyType.Should().Be(BodyType.Json);
|
||||
result.Request.Delay.Should().Be(4);
|
||||
result.Request.MinimumRandomDelay.Should().Be(5);
|
||||
result.Request.MaximumRandomDelay.Should().Be(6);
|
||||
// Verify
|
||||
return Verifier.Verify(result);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void WebhookMapper_Map_Webhook_To_Model()
|
||||
public Task WebhookMapper_Map_Webhook_To_Model()
|
||||
{
|
||||
// Assign
|
||||
var webhook = new Webhook
|
||||
@@ -134,12 +128,8 @@ public class WebhookMapperTests
|
||||
|
||||
var result = WebhookMapper.Map(webhook);
|
||||
|
||||
result.Request.Url.Should().Be("https://localhost");
|
||||
result.Request.Method.Should().Be("get");
|
||||
result.Request.Headers.Should().HaveCount(1);
|
||||
result.Request.BodyAsJson.Should().NotBeNull();
|
||||
result.Request.Delay.Should().Be(4);
|
||||
result.Request.MinimumRandomDelay.Should().Be(5);
|
||||
result.Request.MaximumRandomDelay.Should().Be(6);
|
||||
// Verify
|
||||
return Verifier.Verify(result);
|
||||
}
|
||||
}
|
||||
}
|
||||
#endif
|
||||
@@ -1,75 +0,0 @@
|
||||
{
|
||||
"Guid": "ff55ac0a-fea9-4d7b-be74-5e483a2c1305",
|
||||
"UpdatedAt": "2022-12-04T00:00:00",
|
||||
"Title": "my title",
|
||||
"Description": "my description",
|
||||
"Priority": -2000000,
|
||||
"Request": {
|
||||
"Path": {
|
||||
"Matchers": [
|
||||
{
|
||||
"Name": "WildcardMatcher",
|
||||
"Pattern": "x",
|
||||
"IgnoreCase": false
|
||||
}
|
||||
]
|
||||
},
|
||||
"Methods": [
|
||||
"POST"
|
||||
],
|
||||
"Headers": [
|
||||
{
|
||||
"Name": "Content-Type",
|
||||
"Matchers": [
|
||||
{
|
||||
"Name": "ContentTypeMatcher",
|
||||
"Pattern": "text/plain",
|
||||
"IgnoreCase": false
|
||||
}
|
||||
]
|
||||
}
|
||||
],
|
||||
"Cookies": [
|
||||
{
|
||||
"Name": "c",
|
||||
"Matchers": [
|
||||
{
|
||||
"Name": "WildcardMatcher",
|
||||
"Pattern": "x",
|
||||
"IgnoreCase": true
|
||||
}
|
||||
]
|
||||
}
|
||||
],
|
||||
"Params": [
|
||||
{
|
||||
"Name": "p1",
|
||||
"Matchers": [
|
||||
{
|
||||
"Name": "ExactMatcher",
|
||||
"Pattern": "p1-v",
|
||||
"IgnoreCase": false
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"Name": "p2",
|
||||
"Matchers": [
|
||||
{
|
||||
"Name": "ExactMatcher",
|
||||
"Pattern": "p2-v",
|
||||
"IgnoreCase": false
|
||||
}
|
||||
]
|
||||
}
|
||||
],
|
||||
"Body": {
|
||||
"Matcher": {
|
||||
"Name": "RegexMatcher",
|
||||
"Pattern": "<RequestType>Auth</RequestType",
|
||||
"IgnoreCase": false
|
||||
}
|
||||
}
|
||||
},
|
||||
"Response": {}
|
||||
}
|
||||
@@ -9,109 +9,109 @@ using WireMock.Types;
|
||||
using WireMock.Util;
|
||||
using Xunit;
|
||||
|
||||
namespace WireMock.Net.Tests.Util
|
||||
namespace WireMock.Net.Tests.Util;
|
||||
|
||||
public class BodyParserTests
|
||||
{
|
||||
public class BodyParserTests
|
||||
[Theory]
|
||||
[InlineData("application/json", "{ \"x\": 1 }", BodyType.Json, BodyType.Json)]
|
||||
[InlineData("application/json; charset=utf-8", "{ \"x\": 1 }", BodyType.Json, BodyType.Json)]
|
||||
[InlineData("application/json; odata.metadata=minimal", "{ \"x\": 1 }", BodyType.Json, BodyType.Json)]
|
||||
[InlineData("application/vnd.api+json", "{ \"x\": 1 }", BodyType.Json, BodyType.Json)]
|
||||
[InlineData("application/vnd.test+json", "{ \"x\": 1 }", BodyType.Json, BodyType.Json)]
|
||||
public async Task BodyParser_Parse_ContentTypeJson(string contentType, string bodyAsJson, BodyType detectedBodyType, BodyType detectedBodyTypeFromContentType)
|
||||
{
|
||||
[Theory]
|
||||
[InlineData("application/json", "{ \"x\": 1 }", BodyType.Json, BodyType.Json)]
|
||||
[InlineData("application/json; charset=utf-8", "{ \"x\": 1 }", BodyType.Json, BodyType.Json)]
|
||||
[InlineData("application/json; odata.metadata=minimal", "{ \"x\": 1 }", BodyType.Json, BodyType.Json)]
|
||||
[InlineData("application/vnd.api+json", "{ \"x\": 1 }", BodyType.Json, BodyType.Json)]
|
||||
[InlineData("application/vnd.test+json", "{ \"x\": 1 }", BodyType.Json, BodyType.Json)]
|
||||
public async Task BodyParser_Parse_ContentTypeJson(string contentType, string bodyAsJson, BodyType detectedBodyType, BodyType detectedBodyTypeFromContentType)
|
||||
// Arrange
|
||||
var bodyParserSettings = new BodyParserSettings
|
||||
{
|
||||
// Arrange
|
||||
var bodyParserSettings = new BodyParserSettings
|
||||
{
|
||||
Stream = new MemoryStream(Encoding.UTF8.GetBytes(bodyAsJson)),
|
||||
ContentType = contentType,
|
||||
DeserializeJson = true
|
||||
};
|
||||
Stream = new MemoryStream(Encoding.UTF8.GetBytes(bodyAsJson)),
|
||||
ContentType = contentType,
|
||||
DeserializeJson = true
|
||||
};
|
||||
|
||||
// Act
|
||||
var body = await BodyParser.ParseAsync(bodyParserSettings).ConfigureAwait(false);
|
||||
// Act
|
||||
var body = await BodyParser.ParseAsync(bodyParserSettings).ConfigureAwait(false);
|
||||
|
||||
// Assert
|
||||
Check.That(body.BodyAsBytes).IsNotNull();
|
||||
Check.That(body.BodyAsJson).IsNotNull();
|
||||
Check.That(body.BodyAsString).Equals(bodyAsJson);
|
||||
Check.That(body.DetectedBodyType).IsEqualTo(detectedBodyType);
|
||||
Check.That(body.DetectedBodyTypeFromContentType).IsEqualTo(detectedBodyTypeFromContentType);
|
||||
}
|
||||
// Assert
|
||||
Check.That(body.BodyAsBytes).IsNotNull();
|
||||
Check.That(body.BodyAsJson).IsNotNull();
|
||||
Check.That(body.BodyAsString).Equals(bodyAsJson);
|
||||
Check.That(body.DetectedBodyType).IsEqualTo(detectedBodyType);
|
||||
Check.That(body.DetectedBodyTypeFromContentType).IsEqualTo(detectedBodyTypeFromContentType);
|
||||
}
|
||||
|
||||
[Theory]
|
||||
[InlineData("application/xml", "<xml>hello</xml>", BodyType.String, BodyType.String)]
|
||||
[InlineData("something", "hello", BodyType.String, BodyType.Bytes)]
|
||||
public async Task BodyParser_Parse_ContentTypeString(string contentType, string bodyAsString, BodyType detectedBodyType, BodyType detectedBodyTypeFromContentType)
|
||||
[Theory]
|
||||
[InlineData("application/xml", "<xml>hello</xml>", BodyType.String, BodyType.String)]
|
||||
[InlineData("something", "hello", BodyType.String, BodyType.Bytes)]
|
||||
public async Task BodyParser_Parse_ContentTypeString(string contentType, string bodyAsString, BodyType detectedBodyType, BodyType detectedBodyTypeFromContentType)
|
||||
{
|
||||
// Arrange
|
||||
var bodyParserSettings = new BodyParserSettings
|
||||
{
|
||||
// Arrange
|
||||
var bodyParserSettings = new BodyParserSettings
|
||||
{
|
||||
Stream = new MemoryStream(Encoding.UTF8.GetBytes(bodyAsString)),
|
||||
ContentType = contentType,
|
||||
DeserializeJson = true
|
||||
};
|
||||
Stream = new MemoryStream(Encoding.UTF8.GetBytes(bodyAsString)),
|
||||
ContentType = contentType,
|
||||
DeserializeJson = true
|
||||
};
|
||||
|
||||
// Act
|
||||
var body = await BodyParser.ParseAsync(bodyParserSettings).ConfigureAwait(false);
|
||||
// Act
|
||||
var body = await BodyParser.ParseAsync(bodyParserSettings).ConfigureAwait(false);
|
||||
|
||||
// Assert
|
||||
Check.That(body.BodyAsBytes).IsNotNull();
|
||||
Check.That(body.BodyAsJson).IsNull();
|
||||
Check.That(body.BodyAsString).Equals(bodyAsString);
|
||||
Check.That(body.DetectedBodyType).IsEqualTo(detectedBodyType);
|
||||
Check.That(body.DetectedBodyTypeFromContentType).IsEqualTo(detectedBodyTypeFromContentType);
|
||||
}
|
||||
// Assert
|
||||
Check.That(body.BodyAsBytes).IsNotNull();
|
||||
Check.That(body.BodyAsJson).IsNull();
|
||||
Check.That(body.BodyAsString).Equals(bodyAsString);
|
||||
Check.That(body.DetectedBodyType).IsEqualTo(detectedBodyType);
|
||||
Check.That(body.DetectedBodyTypeFromContentType).IsEqualTo(detectedBodyTypeFromContentType);
|
||||
}
|
||||
|
||||
[Theory]
|
||||
[InlineData(new byte[] { 34, 97, 34 }, BodyType.Json)]
|
||||
[InlineData(new byte[] { 97 }, BodyType.String)]
|
||||
[InlineData(new byte[] { 0xFF, 0xD8, 0xFF, 0xE0 }, BodyType.Bytes)]
|
||||
public async Task BodyParser_Parse_DetectedBodyType(byte[] content, BodyType detectedBodyType)
|
||||
[Theory]
|
||||
[InlineData(new byte[] { 34, 97, 34 }, BodyType.Json)]
|
||||
[InlineData(new byte[] { 97 }, BodyType.String)]
|
||||
[InlineData(new byte[] { 0xFF, 0xD8, 0xFF, 0xE0 }, BodyType.Bytes)]
|
||||
public async Task BodyParser_Parse_DetectedBodyType(byte[] content, BodyType detectedBodyType)
|
||||
{
|
||||
// arrange
|
||||
var bodyParserSettings = new BodyParserSettings
|
||||
{
|
||||
// arrange
|
||||
var bodyParserSettings = new BodyParserSettings
|
||||
{
|
||||
Stream = new MemoryStream(content),
|
||||
ContentType = null,
|
||||
DeserializeJson = true
|
||||
};
|
||||
Stream = new MemoryStream(content),
|
||||
ContentType = null,
|
||||
DeserializeJson = true
|
||||
};
|
||||
|
||||
// act
|
||||
var body = await BodyParser.ParseAsync(bodyParserSettings).ConfigureAwait(false);
|
||||
// act
|
||||
var body = await BodyParser.ParseAsync(bodyParserSettings).ConfigureAwait(false);
|
||||
|
||||
// assert
|
||||
Check.That(body.DetectedBodyType).IsEqualTo(detectedBodyType);
|
||||
}
|
||||
// assert
|
||||
Check.That(body.DetectedBodyType).IsEqualTo(detectedBodyType);
|
||||
}
|
||||
|
||||
[Theory]
|
||||
[InlineData(new byte[] { 34, 97, 34 }, BodyType.String)]
|
||||
[InlineData(new byte[] { 97 }, BodyType.String)]
|
||||
[InlineData(new byte[] { 0xFF, 0xD8, 0xFF, 0xE0 }, BodyType.Bytes)]
|
||||
public async Task BodyParser_Parse_DetectedBodyTypeNoJsonParsing(byte[] content, BodyType detectedBodyType)
|
||||
[Theory]
|
||||
[InlineData(new byte[] { 34, 97, 34 }, BodyType.String)]
|
||||
[InlineData(new byte[] { 97 }, BodyType.String)]
|
||||
[InlineData(new byte[] { 0xFF, 0xD8, 0xFF, 0xE0 }, BodyType.Bytes)]
|
||||
public async Task BodyParser_Parse_DetectedBodyTypeNoJsonParsing(byte[] content, BodyType detectedBodyType)
|
||||
{
|
||||
// arrange
|
||||
var bodyParserSettings = new BodyParserSettings
|
||||
{
|
||||
// arrange
|
||||
var bodyParserSettings = new BodyParserSettings
|
||||
{
|
||||
Stream = new MemoryStream(content),
|
||||
ContentType = null,
|
||||
DeserializeJson = false
|
||||
};
|
||||
Stream = new MemoryStream(content),
|
||||
ContentType = null,
|
||||
DeserializeJson = false
|
||||
};
|
||||
|
||||
// act
|
||||
var body = await BodyParser.ParseAsync(bodyParserSettings).ConfigureAwait(false);
|
||||
// act
|
||||
var body = await BodyParser.ParseAsync(bodyParserSettings).ConfigureAwait(false);
|
||||
|
||||
// assert
|
||||
Check.That(body.DetectedBodyType).IsEqualTo(detectedBodyType);
|
||||
}
|
||||
// assert
|
||||
Check.That(body.DetectedBodyType).IsEqualTo(detectedBodyType);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task BodyParser_Parse_WithUTF8EncodingAndContentTypeMultipart_DetectedBodyTypeEqualsString()
|
||||
{
|
||||
// Arrange
|
||||
string contentType = "multipart/form-data";
|
||||
string body = @"
|
||||
[Fact]
|
||||
public async Task BodyParser_Parse_WithUTF8EncodingAndContentTypeMultipart_DetectedBodyTypeEqualsString()
|
||||
{
|
||||
// Arrange
|
||||
string contentType = "multipart/form-data";
|
||||
string body = @"
|
||||
|
||||
-----------------------------9051914041544843365972754266
|
||||
Content-Disposition: form-data; name=""text""
|
||||
@@ -131,163 +131,162 @@ Content-Type: text/html
|
||||
|
||||
-----------------------------9051914041544843365972754266--";
|
||||
|
||||
var bodyParserSettings = new BodyParserSettings
|
||||
{
|
||||
Stream = new MemoryStream(Encoding.UTF8.GetBytes(body)),
|
||||
ContentType = contentType,
|
||||
DeserializeJson = true
|
||||
};
|
||||
|
||||
// Act
|
||||
var result = await BodyParser.ParseAsync(bodyParserSettings).ConfigureAwait(false);
|
||||
|
||||
// Assert
|
||||
Check.That(result.DetectedBodyType).IsEqualTo(BodyType.String);
|
||||
Check.That(result.DetectedBodyTypeFromContentType).IsEqualTo(BodyType.MultiPart);
|
||||
Check.That(result.BodyAsBytes).IsNotNull();
|
||||
Check.That(result.BodyAsJson).IsNull();
|
||||
Check.That(result.BodyAsString).IsNotNull();
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task BodyParser_Parse_WithUTF16EncodingAndContentTypeMultipart_DetectedBodyTypeEqualsString()
|
||||
var bodyParserSettings = new BodyParserSettings
|
||||
{
|
||||
// Arrange
|
||||
string contentType = "multipart/form-data";
|
||||
string body = char.ConvertFromUtf32(0x1D161); //U+1D161 = MUSICAL SYMBOL SIXTEENTH NOTE
|
||||
var bodyParserSettings = new BodyParserSettings
|
||||
{
|
||||
Stream = new MemoryStream(Encoding.UTF8.GetBytes(body)),
|
||||
ContentType = contentType,
|
||||
DeserializeJson = true
|
||||
};
|
||||
Stream = new MemoryStream(Encoding.UTF8.GetBytes(body)),
|
||||
ContentType = contentType,
|
||||
DeserializeJson = true
|
||||
};
|
||||
|
||||
// Act
|
||||
var result = await BodyParser.ParseAsync(bodyParserSettings).ConfigureAwait(false);
|
||||
// Act
|
||||
var result = await BodyParser.ParseAsync(bodyParserSettings).ConfigureAwait(false);
|
||||
|
||||
// Assert
|
||||
Check.That(result.DetectedBodyType).IsEqualTo(BodyType.Bytes);
|
||||
Check.That(result.DetectedBodyTypeFromContentType).IsEqualTo(BodyType.MultiPart);
|
||||
Check.That(result.BodyAsBytes).IsNotNull();
|
||||
Check.That(result.BodyAsJson).IsNull();
|
||||
Check.That(result.BodyAsString).IsNull();
|
||||
}
|
||||
// Assert
|
||||
Check.That(result.DetectedBodyType).IsEqualTo(BodyType.String);
|
||||
Check.That(result.DetectedBodyTypeFromContentType).IsEqualTo(BodyType.MultiPart);
|
||||
Check.That(result.BodyAsBytes).IsNotNull();
|
||||
Check.That(result.BodyAsJson).IsNull();
|
||||
Check.That(result.BodyAsString).IsNotNull();
|
||||
}
|
||||
|
||||
[Theory]
|
||||
[InlineData("hello", BodyType.String, BodyType.Bytes)]
|
||||
public async Task BodyParser_Parse_ContentTypeIsNull(string bodyAsString, BodyType detectedBodyType, BodyType detectedBodyTypeFromContentType)
|
||||
[Fact]
|
||||
public async Task BodyParser_Parse_WithUTF16EncodingAndContentTypeMultipart_DetectedBodyTypeEqualsString()
|
||||
{
|
||||
// Arrange
|
||||
string contentType = "multipart/form-data";
|
||||
string body = char.ConvertFromUtf32(0x1D161); //U+1D161 = MUSICAL SYMBOL SIXTEENTH NOTE
|
||||
var bodyParserSettings = new BodyParserSettings
|
||||
{
|
||||
// Arrange
|
||||
var bodyParserSettings = new BodyParserSettings
|
||||
{
|
||||
Stream = new MemoryStream(Encoding.UTF8.GetBytes(bodyAsString)),
|
||||
ContentType = null,
|
||||
DeserializeJson = true
|
||||
};
|
||||
Stream = new MemoryStream(Encoding.UTF8.GetBytes(body)),
|
||||
ContentType = contentType,
|
||||
DeserializeJson = true
|
||||
};
|
||||
|
||||
// Act
|
||||
var body = await BodyParser.ParseAsync(bodyParserSettings).ConfigureAwait(false);
|
||||
// Act
|
||||
var result = await BodyParser.ParseAsync(bodyParserSettings).ConfigureAwait(false);
|
||||
|
||||
// Assert
|
||||
Check.That(body.BodyAsBytes).IsNotNull();
|
||||
Check.That(body.BodyAsJson).IsNull();
|
||||
Check.That(body.BodyAsString).Equals(bodyAsString);
|
||||
Check.That(body.DetectedBodyType).IsEqualTo(detectedBodyType);
|
||||
Check.That(body.DetectedBodyTypeFromContentType).IsEqualTo(detectedBodyTypeFromContentType);
|
||||
}
|
||||
// Assert
|
||||
Check.That(result.DetectedBodyType).IsEqualTo(BodyType.Bytes);
|
||||
Check.That(result.DetectedBodyTypeFromContentType).IsEqualTo(BodyType.MultiPart);
|
||||
Check.That(result.BodyAsBytes).IsNotNull();
|
||||
Check.That(result.BodyAsJson).IsNull();
|
||||
Check.That(result.BodyAsString).IsNull();
|
||||
}
|
||||
|
||||
[Theory]
|
||||
[InlineData("gzip")]
|
||||
[InlineData("deflate")]
|
||||
public async Task BodyParser_Parse_ContentEncoding_GZip_And_DecompressGzipAndDeflate_Is_True_Should_Decompress(string compression)
|
||||
[Theory]
|
||||
[InlineData("hello", BodyType.String, BodyType.Bytes)]
|
||||
public async Task BodyParser_Parse_ContentTypeIsNull(string bodyAsString, BodyType detectedBodyType, BodyType detectedBodyTypeFromContentType)
|
||||
{
|
||||
// Arrange
|
||||
var bodyParserSettings = new BodyParserSettings
|
||||
{
|
||||
// Arrange
|
||||
var bytes = Encoding.ASCII.GetBytes("0");
|
||||
var compressed = CompressionUtils.Compress(compression, bytes);
|
||||
var bodyParserSettings = new BodyParserSettings
|
||||
{
|
||||
Stream = new MemoryStream(compressed),
|
||||
ContentType = "text/plain",
|
||||
DeserializeJson = false,
|
||||
ContentEncoding = compression.ToUpperInvariant(),
|
||||
DecompressGZipAndDeflate = true
|
||||
};
|
||||
Stream = new MemoryStream(Encoding.UTF8.GetBytes(bodyAsString)),
|
||||
ContentType = null,
|
||||
DeserializeJson = true
|
||||
};
|
||||
|
||||
// Act
|
||||
var result = await BodyParser.ParseAsync(bodyParserSettings).ConfigureAwait(false);
|
||||
// Act
|
||||
var body = await BodyParser.ParseAsync(bodyParserSettings).ConfigureAwait(false);
|
||||
|
||||
// Assert
|
||||
result.DetectedBodyType.Should().Be(BodyType.String);
|
||||
result.DetectedBodyTypeFromContentType.Should().Be(BodyType.String);
|
||||
result.BodyAsBytes.Should().BeEquivalentTo(new byte[] { 48 });
|
||||
result.BodyAsJson.Should().BeNull();
|
||||
result.BodyAsString.Should().Be("0");
|
||||
result.DetectedCompression.Should().Be(compression);
|
||||
}
|
||||
// Assert
|
||||
Check.That(body.BodyAsBytes).IsNotNull();
|
||||
Check.That(body.BodyAsJson).IsNull();
|
||||
Check.That(body.BodyAsString).Equals(bodyAsString);
|
||||
Check.That(body.DetectedBodyType).IsEqualTo(detectedBodyType);
|
||||
Check.That(body.DetectedBodyTypeFromContentType).IsEqualTo(detectedBodyTypeFromContentType);
|
||||
}
|
||||
|
||||
[Theory]
|
||||
[InlineData("gzip")]
|
||||
[InlineData("deflate")]
|
||||
public async Task BodyParser_Parse_ContentEncoding_GZip_And_DecompressGzipAndDeflate_Is_False_Should_Not_Decompress(string compression)
|
||||
[Theory]
|
||||
[InlineData("gzip")]
|
||||
[InlineData("deflate")]
|
||||
public async Task BodyParser_Parse_ContentEncoding_GZip_And_DecompressGzipAndDeflate_Is_True_Should_Decompress(string compression)
|
||||
{
|
||||
// Arrange
|
||||
var bytes = Encoding.ASCII.GetBytes("0");
|
||||
var compressed = CompressionUtils.Compress(compression, bytes);
|
||||
var bodyParserSettings = new BodyParserSettings
|
||||
{
|
||||
// Arrange
|
||||
var bytes = Encoding.ASCII.GetBytes(Guid.NewGuid().ToString());
|
||||
var compressed = CompressionUtils.Compress(compression, bytes);
|
||||
var bodyParserSettings = new BodyParserSettings
|
||||
{
|
||||
Stream = new MemoryStream(compressed),
|
||||
ContentType = "text/plain",
|
||||
DeserializeJson = false,
|
||||
ContentEncoding = compression.ToUpperInvariant(),
|
||||
DecompressGZipAndDeflate = false
|
||||
};
|
||||
Stream = new MemoryStream(compressed),
|
||||
ContentType = "text/plain",
|
||||
DeserializeJson = false,
|
||||
ContentEncoding = compression.ToUpperInvariant(),
|
||||
DecompressGZipAndDeflate = true
|
||||
};
|
||||
|
||||
// Act
|
||||
var result = await BodyParser.ParseAsync(bodyParserSettings).ConfigureAwait(false);
|
||||
// Act
|
||||
var result = await BodyParser.ParseAsync(bodyParserSettings).ConfigureAwait(false);
|
||||
|
||||
// Assert
|
||||
result.BodyAsBytes.Should().BeEquivalentTo(compressed);
|
||||
result.DetectedCompression.Should().BeNull();
|
||||
}
|
||||
// Assert
|
||||
result.DetectedBodyType.Should().Be(BodyType.String);
|
||||
result.DetectedBodyTypeFromContentType.Should().Be(BodyType.String);
|
||||
result.BodyAsBytes.Should().BeEquivalentTo(new byte[] { 48 });
|
||||
result.BodyAsJson.Should().BeNull();
|
||||
result.BodyAsString.Should().Be("0");
|
||||
result.DetectedCompression.Should().Be(compression);
|
||||
}
|
||||
|
||||
[Theory]
|
||||
[InlineData("HEAD", false)]
|
||||
[InlineData("GET", false)]
|
||||
[InlineData("PUT", true)]
|
||||
[InlineData("POST", true)]
|
||||
[InlineData("DELETE", true)]
|
||||
[InlineData("TRACE", false)]
|
||||
[InlineData("OPTIONS", true)]
|
||||
[InlineData("CONNECT", false)]
|
||||
[InlineData("PATCH", true)]
|
||||
public void BodyParser_ShouldParseBodyForMethodAndAllowAllIsFalse_ExpectedResultForKnownMethods(string method, bool resultShouldBe)
|
||||
[Theory]
|
||||
[InlineData("gzip")]
|
||||
[InlineData("deflate")]
|
||||
public async Task BodyParser_Parse_ContentEncoding_GZip_And_DecompressGzipAndDeflate_Is_False_Should_Not_Decompress(string compression)
|
||||
{
|
||||
// Arrange
|
||||
var bytes = Encoding.ASCII.GetBytes(Guid.NewGuid().ToString());
|
||||
var compressed = CompressionUtils.Compress(compression, bytes);
|
||||
var bodyParserSettings = new BodyParserSettings
|
||||
{
|
||||
Check.That(BodyParser.ShouldParseBody(method, false)).Equals(resultShouldBe);
|
||||
}
|
||||
Stream = new MemoryStream(compressed),
|
||||
ContentType = "text/plain",
|
||||
DeserializeJson = false,
|
||||
ContentEncoding = compression.ToUpperInvariant(),
|
||||
DecompressGZipAndDeflate = false
|
||||
};
|
||||
|
||||
[Theory]
|
||||
[InlineData("HEAD")]
|
||||
[InlineData("GET")]
|
||||
[InlineData("PUT")]
|
||||
[InlineData("POST")]
|
||||
[InlineData("DELETE")]
|
||||
[InlineData("TRACE")]
|
||||
[InlineData("OPTIONS")]
|
||||
[InlineData("CONNECT")]
|
||||
[InlineData("PATCH")]
|
||||
[InlineData("REPORT")]
|
||||
[InlineData("SOME-UNKNOWN-METHOD")]
|
||||
public void BodyParser_ShouldParseBodyForMethodAndAllowAllIsTrue_ExpectedResultShouldBeTrue(string method)
|
||||
{
|
||||
Check.That(BodyParser.ShouldParseBody(method, true)).IsTrue();
|
||||
}
|
||||
// Act
|
||||
var result = await BodyParser.ParseAsync(bodyParserSettings).ConfigureAwait(false);
|
||||
|
||||
[Theory]
|
||||
[InlineData("REPORT")]
|
||||
[InlineData("SOME-UNKNOWN-METHOD")]
|
||||
public void BodyParser_ShouldParseBody_DefaultIsTrueForUnknownMethods(string method)
|
||||
{
|
||||
Check.That(BodyParser.ShouldParseBody(method, false)).IsTrue();
|
||||
}
|
||||
// Assert
|
||||
result.BodyAsBytes.Should().BeEquivalentTo(compressed);
|
||||
result.DetectedCompression.Should().BeNull();
|
||||
}
|
||||
|
||||
[Theory]
|
||||
[InlineData("HEAD", false)]
|
||||
[InlineData("GET", false)]
|
||||
[InlineData("PUT", true)]
|
||||
[InlineData("POST", true)]
|
||||
[InlineData("DELETE", true)]
|
||||
[InlineData("TRACE", false)]
|
||||
[InlineData("OPTIONS", true)]
|
||||
[InlineData("CONNECT", false)]
|
||||
[InlineData("PATCH", true)]
|
||||
public void BodyParser_ShouldParseBodyForMethodAndAllowAllIsFalse_ExpectedResultForKnownMethods(string method, bool resultShouldBe)
|
||||
{
|
||||
Check.That(BodyParser.ShouldParseBody(method, false)).Equals(resultShouldBe);
|
||||
}
|
||||
|
||||
[Theory]
|
||||
[InlineData("HEAD")]
|
||||
[InlineData("GET")]
|
||||
[InlineData("PUT")]
|
||||
[InlineData("POST")]
|
||||
[InlineData("DELETE")]
|
||||
[InlineData("TRACE")]
|
||||
[InlineData("OPTIONS")]
|
||||
[InlineData("CONNECT")]
|
||||
[InlineData("PATCH")]
|
||||
[InlineData("REPORT")]
|
||||
[InlineData("SOME-UNKNOWN-METHOD")]
|
||||
public void BodyParser_ShouldParseBodyForMethodAndAllowAllIsTrue_ExpectedResultShouldBeTrue(string method)
|
||||
{
|
||||
Check.That(BodyParser.ShouldParseBody(method, true)).IsTrue();
|
||||
}
|
||||
|
||||
[Theory]
|
||||
[InlineData("REPORT")]
|
||||
[InlineData("SOME-UNKNOWN-METHOD")]
|
||||
public void BodyParser_ShouldParseBody_DefaultIsTrueForUnknownMethods(string method)
|
||||
{
|
||||
Check.That(BodyParser.ShouldParseBody(method, false)).IsTrue();
|
||||
}
|
||||
}
|
||||
@@ -1,30 +1,29 @@
|
||||
using System.Text;
|
||||
using System.Text;
|
||||
using FluentAssertions;
|
||||
using WireMock.Util;
|
||||
using Xunit;
|
||||
|
||||
namespace WireMock.Net.Tests.Util
|
||||
namespace WireMock.Net.Tests.Util;
|
||||
|
||||
public class BytesEncodingUtilsTests
|
||||
{
|
||||
public class BytesEncodingUtilsTests
|
||||
[Fact]
|
||||
public void TryGetEncoding_UTF32()
|
||||
{
|
||||
[Fact]
|
||||
public void TryGetEncoding_UTF32()
|
||||
{
|
||||
var result = BytesEncodingUtils.TryGetEncoding(new byte[] { 0xff, 0xfe, 0x00, 0x00 }, out Encoding encoding);
|
||||
var result = BytesEncodingUtils.TryGetEncoding(new byte[] { 0xff, 0xfe, 0x00, 0x00 }, out Encoding encoding);
|
||||
|
||||
// Assert
|
||||
result.Should().BeTrue();
|
||||
encoding.CodePage.Should().Be(Encoding.UTF32.CodePage);
|
||||
}
|
||||
// Assert
|
||||
result.Should().BeTrue();
|
||||
encoding.CodePage.Should().Be(Encoding.UTF32.CodePage);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void TryGetEncoding_Invalid()
|
||||
{
|
||||
var result = BytesEncodingUtils.TryGetEncoding(new byte[] { 0xff }, out Encoding encoding);
|
||||
[Fact]
|
||||
public void TryGetEncoding_Invalid()
|
||||
{
|
||||
var result = BytesEncodingUtils.TryGetEncoding(new byte[] { 0xff }, out Encoding encoding);
|
||||
|
||||
// Assert
|
||||
result.Should().BeFalse();
|
||||
encoding.Should().BeNull();
|
||||
}
|
||||
// Assert
|
||||
result.Should().BeFalse();
|
||||
encoding.Should().BeNull();
|
||||
}
|
||||
}
|
||||
@@ -1,75 +1,74 @@
|
||||
using FluentAssertions;
|
||||
using FluentAssertions;
|
||||
using System;
|
||||
using System.Net;
|
||||
using WireMock.Util;
|
||||
using Xunit;
|
||||
|
||||
namespace WireMock.Net.Tests.Util
|
||||
namespace WireMock.Net.Tests.Util;
|
||||
|
||||
/// <summary>
|
||||
/// Based on https://raw.githubusercontent.com/tmenier/Flurl/129565361e135e639f1d44a35a78aea4302ac6ca/Test/Flurl.Test/Http/HttpStatusRangeParserTests.cs
|
||||
/// </summary>
|
||||
public class HttpStatusRangeParserTests
|
||||
{
|
||||
/// <summary>
|
||||
/// Based on https://raw.githubusercontent.com/tmenier/Flurl/129565361e135e639f1d44a35a78aea4302ac6ca/Test/Flurl.Test/Http/HttpStatusRangeParserTests.cs
|
||||
/// </summary>
|
||||
public class HttpStatusRangeParserTests
|
||||
[Theory]
|
||||
[InlineData("4**", 399, false)]
|
||||
[InlineData("4**", 400, true)]
|
||||
[InlineData("4**", 499, true)]
|
||||
[InlineData("4**", 500, false)]
|
||||
|
||||
[InlineData("4xx", 399, false)]
|
||||
[InlineData("4xx", 400, true)]
|
||||
[InlineData("4xx", 499, true)]
|
||||
[InlineData("4xx", 500, false)]
|
||||
|
||||
[InlineData("4XX", 399, false)]
|
||||
[InlineData("4XX", 400, true)]
|
||||
[InlineData("4XX", 499, true)]
|
||||
[InlineData("4XX", 500, false)]
|
||||
|
||||
[InlineData("400-499", 399, false)]
|
||||
[InlineData("400-499", 400, true)]
|
||||
[InlineData("400-499", 499, true)]
|
||||
[InlineData("400-499", 500, false)]
|
||||
|
||||
[InlineData("100,3xx,600", 100, true)]
|
||||
[InlineData("100,3xx,600", 101, false)]
|
||||
[InlineData("100,3xx,600", 300, true)]
|
||||
[InlineData("100,3xx,600", 399, true)]
|
||||
[InlineData("100,3xx,600", 400, false)]
|
||||
[InlineData("100,3xx,600", 600, true)]
|
||||
|
||||
[InlineData("400-409,490-499", 399, false)]
|
||||
[InlineData("400-409,490-499", 405, true)]
|
||||
[InlineData("400-409,490-499", 450, false)]
|
||||
[InlineData("400-409,490-499", 495, true)]
|
||||
[InlineData("400-409,490-499", 500, false)]
|
||||
|
||||
[InlineData("*", 0, true)]
|
||||
[InlineData(",,,*", 9999, true)]
|
||||
|
||||
[InlineData("", 0, false)]
|
||||
[InlineData(",,,", 9999, false)]
|
||||
|
||||
[InlineData(null, 399, true)]
|
||||
public void HttpStatusRangeParser_ValidPattern_IsMatch(string pattern, int value, bool expectedResult)
|
||||
{
|
||||
[Theory]
|
||||
[InlineData("4**", 399, false)]
|
||||
[InlineData("4**", 400, true)]
|
||||
[InlineData("4**", 499, true)]
|
||||
[InlineData("4**", 500, false)]
|
||||
HttpStatusRangeParser.IsMatch(pattern, value).Should().Be(expectedResult);
|
||||
}
|
||||
|
||||
[InlineData("4xx", 399, false)]
|
||||
[InlineData("4xx", 400, true)]
|
||||
[InlineData("4xx", 499, true)]
|
||||
[InlineData("4xx", 500, false)]
|
||||
[Fact]
|
||||
public void HttpStatusRangeParser_ValidPattern_HttpStatusCode_IsMatch()
|
||||
{
|
||||
HttpStatusRangeParser.IsMatch("4xx", HttpStatusCode.BadRequest).Should().BeTrue();
|
||||
}
|
||||
|
||||
[InlineData("4XX", 399, false)]
|
||||
[InlineData("4XX", 400, true)]
|
||||
[InlineData("4XX", 499, true)]
|
||||
[InlineData("4XX", 500, false)]
|
||||
|
||||
[InlineData("400-499", 399, false)]
|
||||
[InlineData("400-499", 400, true)]
|
||||
[InlineData("400-499", 499, true)]
|
||||
[InlineData("400-499", 500, false)]
|
||||
|
||||
[InlineData("100,3xx,600", 100, true)]
|
||||
[InlineData("100,3xx,600", 101, false)]
|
||||
[InlineData("100,3xx,600", 300, true)]
|
||||
[InlineData("100,3xx,600", 399, true)]
|
||||
[InlineData("100,3xx,600", 400, false)]
|
||||
[InlineData("100,3xx,600", 600, true)]
|
||||
|
||||
[InlineData("400-409,490-499", 399, false)]
|
||||
[InlineData("400-409,490-499", 405, true)]
|
||||
[InlineData("400-409,490-499", 450, false)]
|
||||
[InlineData("400-409,490-499", 495, true)]
|
||||
[InlineData("400-409,490-499", 500, false)]
|
||||
|
||||
[InlineData("*", 0, true)]
|
||||
[InlineData(",,,*", 9999, true)]
|
||||
|
||||
[InlineData("", 0, false)]
|
||||
[InlineData(",,,", 9999, false)]
|
||||
|
||||
[InlineData(null, 399, true)]
|
||||
public void HttpStatusRangeParser_ValidPattern_IsMatch(string pattern, int value, bool expectedResult)
|
||||
{
|
||||
HttpStatusRangeParser.IsMatch(pattern, value).Should().Be(expectedResult);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void HttpStatusRangeParser_ValidPattern_HttpStatusCode_IsMatch()
|
||||
{
|
||||
HttpStatusRangeParser.IsMatch("4xx", HttpStatusCode.BadRequest).Should().BeTrue();
|
||||
}
|
||||
|
||||
[Theory]
|
||||
[InlineData("-100")]
|
||||
[InlineData("100-")]
|
||||
[InlineData("1yy")]
|
||||
public void HttpStatusRangeParser_InvalidPattern_ThrowsException(string pattern)
|
||||
{
|
||||
Assert.Throws<ArgumentException>(() => HttpStatusRangeParser.IsMatch(pattern, 100));
|
||||
}
|
||||
[Theory]
|
||||
[InlineData("-100")]
|
||||
[InlineData("100-")]
|
||||
[InlineData("1yy")]
|
||||
public void HttpStatusRangeParser_InvalidPattern_ThrowsException(string pattern)
|
||||
{
|
||||
Assert.Throws<ArgumentException>(() => HttpStatusRangeParser.IsMatch(pattern, 100));
|
||||
}
|
||||
}
|
||||
@@ -2,103 +2,102 @@ using FluentAssertions;
|
||||
using WireMock.Util;
|
||||
using Xunit;
|
||||
|
||||
namespace WireMock.Net.Tests.Util
|
||||
namespace WireMock.Net.Tests.Util;
|
||||
|
||||
public class StringUtilsTests
|
||||
{
|
||||
public class StringUtilsTests
|
||||
[Theory]
|
||||
[InlineData("'s")]
|
||||
[InlineData("\"s")]
|
||||
public void StringUtils_TryParseQuotedString_With_UnexpectedUnclosedString_Returns_False(string input)
|
||||
{
|
||||
[Theory]
|
||||
[InlineData("'s")]
|
||||
[InlineData("\"s")]
|
||||
public void StringUtils_TryParseQuotedString_With_UnexpectedUnclosedString_Returns_False(string input)
|
||||
{
|
||||
// Act
|
||||
bool valid = StringUtils.TryParseQuotedString(input, out var result, out var quote);
|
||||
// Act
|
||||
bool valid = StringUtils.TryParseQuotedString(input, out var result, out var quote);
|
||||
|
||||
// Assert
|
||||
valid.Should().BeFalse();
|
||||
}
|
||||
// Assert
|
||||
valid.Should().BeFalse();
|
||||
}
|
||||
|
||||
[Theory]
|
||||
[InlineData("")]
|
||||
[InlineData(null)]
|
||||
[InlineData("x")]
|
||||
public void StringUtils_TryParseQuotedString_With_InvalidStringLength_Returns_False(string input)
|
||||
{
|
||||
// Act
|
||||
bool valid = StringUtils.TryParseQuotedString(input, out var result, out var quote);
|
||||
[Theory]
|
||||
[InlineData("")]
|
||||
[InlineData(null)]
|
||||
[InlineData("x")]
|
||||
public void StringUtils_TryParseQuotedString_With_InvalidStringLength_Returns_False(string input)
|
||||
{
|
||||
// Act
|
||||
bool valid = StringUtils.TryParseQuotedString(input, out var result, out var quote);
|
||||
|
||||
// Assert
|
||||
valid.Should().BeFalse();
|
||||
}
|
||||
// Assert
|
||||
valid.Should().BeFalse();
|
||||
}
|
||||
|
||||
[Theory]
|
||||
[InlineData("xx")]
|
||||
[InlineData(" ")]
|
||||
public void StringUtils_TryParseQuotedString_With_InvalidStringQuoteCharacter_Returns_False(string input)
|
||||
{
|
||||
// Act
|
||||
bool valid = StringUtils.TryParseQuotedString(input, out var result, out var quote);
|
||||
[Theory]
|
||||
[InlineData("xx")]
|
||||
[InlineData(" ")]
|
||||
public void StringUtils_TryParseQuotedString_With_InvalidStringQuoteCharacter_Returns_False(string input)
|
||||
{
|
||||
// Act
|
||||
bool valid = StringUtils.TryParseQuotedString(input, out var result, out var quote);
|
||||
|
||||
// Assert
|
||||
valid.Should().BeFalse();
|
||||
}
|
||||
// Assert
|
||||
valid.Should().BeFalse();
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void StringUtils_TryParseQuotedString_With_UnexpectedUnrecognizedEscapeSequence_Returns_False()
|
||||
{
|
||||
// Arrange
|
||||
string input = new string(new[] { '"', '\\', 'u', '?', '"' });
|
||||
[Fact]
|
||||
public void StringUtils_TryParseQuotedString_With_UnexpectedUnrecognizedEscapeSequence_Returns_False()
|
||||
{
|
||||
// Arrange
|
||||
string input = new string(new[] { '"', '\\', 'u', '?', '"' });
|
||||
|
||||
// Act
|
||||
bool valid = StringUtils.TryParseQuotedString(input, out var result, out var quote);
|
||||
// Act
|
||||
bool valid = StringUtils.TryParseQuotedString(input, out var result, out var quote);
|
||||
|
||||
// Assert
|
||||
valid.Should().BeFalse();
|
||||
}
|
||||
// Assert
|
||||
valid.Should().BeFalse();
|
||||
}
|
||||
|
||||
[Theory]
|
||||
[InlineData("''", "")]
|
||||
[InlineData("'s'", "s")]
|
||||
[InlineData("'\\\\'", "\\")]
|
||||
[InlineData("'\\n'", "\n")]
|
||||
public void StringUtils_TryParseQuotedString_SingleQuotedString(string input, string expectedResult)
|
||||
{
|
||||
// Act
|
||||
bool valid = StringUtils.TryParseQuotedString(input, out var result, out var quote);
|
||||
[Theory]
|
||||
[InlineData("''", "")]
|
||||
[InlineData("'s'", "s")]
|
||||
[InlineData("'\\\\'", "\\")]
|
||||
[InlineData("'\\n'", "\n")]
|
||||
public void StringUtils_TryParseQuotedString_SingleQuotedString(string input, string expectedResult)
|
||||
{
|
||||
// Act
|
||||
bool valid = StringUtils.TryParseQuotedString(input, out var result, out var quote);
|
||||
|
||||
// Assert
|
||||
valid.Should().BeTrue();
|
||||
result.Should().Be(expectedResult);
|
||||
quote.Should().Be('\'');
|
||||
}
|
||||
// Assert
|
||||
valid.Should().BeTrue();
|
||||
result.Should().Be(expectedResult);
|
||||
quote.Should().Be('\'');
|
||||
}
|
||||
|
||||
[Theory]
|
||||
[InlineData("\"\"", "")]
|
||||
[InlineData("\"\\\\\"", "\\")]
|
||||
[InlineData("\"\\n\"", "\n")]
|
||||
[InlineData("\"\\\\n\"", "\\n")]
|
||||
[InlineData("\"\\\\new\"", "\\new")]
|
||||
[InlineData("\"[]\"", "[]")]
|
||||
[InlineData("\"()\"", "()")]
|
||||
[InlineData("\"(\\\"\\\")\"", "(\"\")")]
|
||||
[InlineData("\"/\"", "/")]
|
||||
[InlineData("\"a\"", "a")]
|
||||
[InlineData("\"This \\\"is\\\" a test.\"", "This \"is\" a test.")]
|
||||
[InlineData(@"""This \""is\"" b test.""", @"This ""is"" b test.")]
|
||||
[InlineData("\"ab\\\"cd\"", "ab\"cd")]
|
||||
[InlineData("\"\\\"\"", "\"")]
|
||||
[InlineData("\"\\\"\\\"\"", "\"\"")]
|
||||
[InlineData("\"AB YZ 19 \uD800\udc05 \u00e4\"", "AB YZ 19 \uD800\udc05 \u00e4")]
|
||||
[InlineData("\"\\\\\\\\192.168.1.1\\\\audio\\\\new\"", "\\\\192.168.1.1\\audio\\new")]
|
||||
public void StringUtils_TryParseQuotedString_DoubleQuotedString(string input, string expectedResult)
|
||||
{
|
||||
// Act
|
||||
bool valid = StringUtils.TryParseQuotedString(input, out var result, out var quote);
|
||||
[Theory]
|
||||
[InlineData("\"\"", "")]
|
||||
[InlineData("\"\\\\\"", "\\")]
|
||||
[InlineData("\"\\n\"", "\n")]
|
||||
[InlineData("\"\\\\n\"", "\\n")]
|
||||
[InlineData("\"\\\\new\"", "\\new")]
|
||||
[InlineData("\"[]\"", "[]")]
|
||||
[InlineData("\"()\"", "()")]
|
||||
[InlineData("\"(\\\"\\\")\"", "(\"\")")]
|
||||
[InlineData("\"/\"", "/")]
|
||||
[InlineData("\"a\"", "a")]
|
||||
[InlineData("\"This \\\"is\\\" a test.\"", "This \"is\" a test.")]
|
||||
[InlineData(@"""This \""is\"" b test.""", @"This ""is"" b test.")]
|
||||
[InlineData("\"ab\\\"cd\"", "ab\"cd")]
|
||||
[InlineData("\"\\\"\"", "\"")]
|
||||
[InlineData("\"\\\"\\\"\"", "\"\"")]
|
||||
[InlineData("\"AB YZ 19 \uD800\udc05 \u00e4\"", "AB YZ 19 \uD800\udc05 \u00e4")]
|
||||
[InlineData("\"\\\\\\\\192.168.1.1\\\\audio\\\\new\"", "\\\\192.168.1.1\\audio\\new")]
|
||||
public void StringUtils_TryParseQuotedString_DoubleQuotedString(string input, string expectedResult)
|
||||
{
|
||||
// Act
|
||||
bool valid = StringUtils.TryParseQuotedString(input, out var result, out var quote);
|
||||
|
||||
// Assert
|
||||
valid.Should().BeTrue();
|
||||
result.Should().Be(expectedResult);
|
||||
quote.Should().Be('"');
|
||||
}
|
||||
// Assert
|
||||
valid.Should().BeTrue();
|
||||
result.Should().Be(expectedResult);
|
||||
quote.Should().Be('"');
|
||||
}
|
||||
}
|
||||
@@ -1,4 +1,4 @@
|
||||
using System;
|
||||
using System;
|
||||
#if NET452
|
||||
using Microsoft.Owin;
|
||||
#else
|
||||
@@ -8,50 +8,49 @@ using NFluent;
|
||||
using WireMock.Util;
|
||||
using Xunit;
|
||||
|
||||
namespace WireMock.Net.Tests.Util
|
||||
namespace WireMock.Net.Tests.Util;
|
||||
|
||||
public class UrlUtilsTests
|
||||
{
|
||||
public class UrlUtilsTests
|
||||
[Fact]
|
||||
public void UriUtils_CreateUri_WithValidPathString()
|
||||
{
|
||||
[Fact]
|
||||
public void UriUtils_CreateUri_WithValidPathString()
|
||||
{
|
||||
// Assign
|
||||
Uri uri = new Uri("https://localhost:1234/a/b?x=0");
|
||||
// Assign
|
||||
Uri uri = new Uri("https://localhost:1234/a/b?x=0");
|
||||
|
||||
// Act
|
||||
var result = UrlUtils.Parse(uri, new PathString("/a"));
|
||||
// Act
|
||||
var result = UrlUtils.Parse(uri, new PathString("/a"));
|
||||
|
||||
// Assert
|
||||
Check.That(result.Url.ToString()).Equals("https://localhost:1234/b?x=0");
|
||||
Check.That(result.AbsoluteUrl.ToString()).Equals("https://localhost:1234/a/b?x=0");
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void UriUtils_CreateUri_WithEmptyPathString()
|
||||
{
|
||||
// Assign
|
||||
Uri uri = new Uri("https://localhost:1234/a/b?x=0");
|
||||
|
||||
// Act
|
||||
var result = UrlUtils.Parse(uri, new PathString());
|
||||
|
||||
// Assert
|
||||
Check.That(result.Url.ToString()).Equals("https://localhost:1234/a/b?x=0");
|
||||
Check.That(result.AbsoluteUrl.ToString()).Equals("https://localhost:1234/a/b?x=0");
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void UriUtils_CreateUri_WithDifferentPathString()
|
||||
{
|
||||
// Assign
|
||||
Uri uri = new Uri("https://localhost:1234/a/b?x=0");
|
||||
|
||||
// Act
|
||||
var result = UrlUtils.Parse(uri, new PathString("/test"));
|
||||
|
||||
// Assert
|
||||
Check.That(result.Url.ToString()).Equals("https://localhost:1234/a/b?x=0");
|
||||
Check.That(result.AbsoluteUrl.ToString()).Equals("https://localhost:1234/a/b?x=0");
|
||||
}
|
||||
// Assert
|
||||
Check.That(result.Url.ToString()).Equals("https://localhost:1234/b?x=0");
|
||||
Check.That(result.AbsoluteUrl.ToString()).Equals("https://localhost:1234/a/b?x=0");
|
||||
}
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void UriUtils_CreateUri_WithEmptyPathString()
|
||||
{
|
||||
// Assign
|
||||
Uri uri = new Uri("https://localhost:1234/a/b?x=0");
|
||||
|
||||
// Act
|
||||
var result = UrlUtils.Parse(uri, new PathString());
|
||||
|
||||
// Assert
|
||||
Check.That(result.Url.ToString()).Equals("https://localhost:1234/a/b?x=0");
|
||||
Check.That(result.AbsoluteUrl.ToString()).Equals("https://localhost:1234/a/b?x=0");
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void UriUtils_CreateUri_WithDifferentPathString()
|
||||
{
|
||||
// Assign
|
||||
Uri uri = new Uri("https://localhost:1234/a/b?x=0");
|
||||
|
||||
// Act
|
||||
var result = UrlUtils.Parse(uri, new PathString("/test"));
|
||||
|
||||
// Assert
|
||||
Check.That(result.Url.ToString()).Equals("https://localhost:1234/a/b?x=0");
|
||||
Check.That(result.AbsoluteUrl.ToString()).Equals("https://localhost:1234/a/b?x=0");
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,15 @@
|
||||
#if !(NET452 || NET461)
|
||||
using VerifyTests;
|
||||
|
||||
namespace WireMock.Net.Tests.VerifyExtensions;
|
||||
|
||||
internal static class VerifySettingsExtensions
|
||||
{
|
||||
public static void Init<T>(this VerifySettings verifySettings)
|
||||
{
|
||||
verifySettings.DontScrubDateTimes();
|
||||
verifySettings.DontScrubDateTimes();
|
||||
verifySettings.UseDirectory($"{typeof(T).Name}.Verify");
|
||||
}
|
||||
}
|
||||
#endif
|
||||
@@ -24,6 +24,18 @@
|
||||
<DefineConstants>NETFRAMEWORK</DefineConstants>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<!-- https://stackoverflow.com/questions/59406201/filenesting-not-working-for-class-or-shared-library-projects -->
|
||||
<ProjectCapability Include="ConfigurableFileNesting" />
|
||||
<ProjectCapability Include="ConfigurableFileNestingFeatureEnabled" />
|
||||
</ItemGroup>
|
||||
|
||||
<!--<ItemGroup>
|
||||
<Compile Update="**\*.*.verified.txt">
|
||||
<DependentUpon>$([System.String]::Copy((Filename)*.cs))</DependentUpon>
|
||||
</Compile>
|
||||
</ItemGroup>-->
|
||||
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\..\src\WireMock.Net.Abstractions\WireMock.Net.Abstractions.csproj" />
|
||||
<ProjectReference Include="..\..\src\WireMock.Net.FluentAssertions\WireMock.Net.FluentAssertions.csproj" />
|
||||
@@ -41,12 +53,6 @@
|
||||
</PackageReference>
|
||||
<PackageReference Include="CultureAwareTesting.xUnit" Version="0.0.1" />
|
||||
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.4.0" />
|
||||
<PackageReference Include="xunit" Version="2.4.1" />
|
||||
<PackageReference Include="xunit.core" Version="2.4.1" />
|
||||
<PackageReference Include="xunit.runner.visualstudio" Version="2.4.3">
|
||||
<PrivateAssets>all</PrivateAssets>
|
||||
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
|
||||
</PackageReference>
|
||||
<PackageReference Include="coverlet.collector" Version="3.2.0">
|
||||
<PrivateAssets>all</PrivateAssets>
|
||||
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
|
||||
@@ -66,10 +72,23 @@
|
||||
<PackageReference Include="Microsoft.Owin.Host.HttpListener" Version="3.1.0" />
|
||||
<PackageReference Include="System.ValueTuple" Version="4.5.0" />
|
||||
<PackageReference Include="FluentAssertions" Version="5.10.3" />
|
||||
<PackageReference Include="xunit" Version="2.4.1" />
|
||||
<PackageReference Include="xunit.core" Version="2.4.1" />
|
||||
<PackageReference Include="xunit.runner.visualstudio" Version="2.4.3">
|
||||
<PrivateAssets>all</PrivateAssets>
|
||||
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
|
||||
</PackageReference>
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup Condition="'$(TargetFramework)' != 'net452' and '$(TargetFramework)' != 'net461'">
|
||||
<PackageReference Include="FluentAssertions" Version="6.7.0" />
|
||||
<PackageReference Include="FluentAssertions" Version="6.9.0" />
|
||||
<PackageReference Include="xunit" Version="2.4.2" />
|
||||
<PackageReference Include="xunit.core" Version="2.4.2" />
|
||||
<PackageReference Include="xunit.runner.visualstudio" Version="2.4.5">
|
||||
<PrivateAssets>all</PrivateAssets>
|
||||
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
|
||||
</PackageReference>
|
||||
<PackageReference Include="Verify.Xunit" Version="19.6.0" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup Condition="'$(TargetFramework)' != 'net452'">
|
||||
@@ -81,9 +100,6 @@
|
||||
<None Update="responsebody.json">
|
||||
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
|
||||
</None>
|
||||
<None Update="Serialization\files\proxy.json">
|
||||
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
|
||||
</None>
|
||||
<None Update="__admin\mappings.org\*.json">
|
||||
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
|
||||
</None>
|
||||
@@ -108,7 +124,6 @@
|
||||
|
||||
<ItemGroup>
|
||||
<Folder Include="Pact\files\" />
|
||||
<Folder Include="Serialization\files\" />
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
||||
@@ -146,7 +146,7 @@ public class WireMockServerAdminTests
|
||||
|
||||
string responseBodyFilePath = Path.Combine(GetCurrentFolder(), "responsebody.json");
|
||||
|
||||
dynamic jsonObj = JsonConvert.DeserializeObject(json);
|
||||
dynamic jsonObj = JsonConvert.DeserializeObject(json)!;
|
||||
jsonObj["Response"]["BodyAsFile"] = responseBodyFilePath;
|
||||
|
||||
string output = JsonConvert.SerializeObject(jsonObj, Formatting.Indented);
|
||||
|
||||
@@ -1,65 +1,65 @@
|
||||
using System;
|
||||
using System;
|
||||
using FluentAssertions;
|
||||
using WireMock.Admin.Mappings;
|
||||
using WireMock.Server;
|
||||
using Xunit;
|
||||
|
||||
namespace WireMock.Net.Tests.WithMapping
|
||||
namespace WireMock.Net.Tests.WithMapping;
|
||||
|
||||
public class WireMockServerWithMappingTests
|
||||
{
|
||||
public class WireMockServerWithMappingTests
|
||||
[Fact]
|
||||
public void WireMockServer_WithMappingAsModel_Should_Add_Mapping()
|
||||
{
|
||||
[Fact]
|
||||
public void WireMockServer_WithMappingAsModel_Should_Add_Mapping()
|
||||
// Arrange
|
||||
var guid = Guid.NewGuid();
|
||||
var pattern = "hello wiremock";
|
||||
var path = "/foo";
|
||||
var response = "OK";
|
||||
var mapping = new MappingModel
|
||||
{
|
||||
// Arrange
|
||||
var guid = Guid.NewGuid();
|
||||
var pattern = "hello wiremock";
|
||||
var path = "/foo";
|
||||
var response = "OK";
|
||||
var mapping = new MappingModel
|
||||
Guid = guid,
|
||||
Request = new RequestModel
|
||||
{
|
||||
Guid = guid,
|
||||
Request = new RequestModel
|
||||
Path = path,
|
||||
Body = new BodyModel
|
||||
{
|
||||
Path = path,
|
||||
Body = new BodyModel
|
||||
Matcher = new MatcherModel
|
||||
{
|
||||
Matcher = new MatcherModel
|
||||
{
|
||||
Name = "ExactMatcher",
|
||||
Pattern = pattern
|
||||
}
|
||||
Name = "ExactMatcher",
|
||||
Pattern = pattern
|
||||
}
|
||||
},
|
||||
Response = new ResponseModel
|
||||
{
|
||||
Body = response,
|
||||
StatusCode = 201
|
||||
}
|
||||
};
|
||||
},
|
||||
Response = new ResponseModel
|
||||
{
|
||||
Body = response,
|
||||
StatusCode = 201
|
||||
}
|
||||
};
|
||||
|
||||
var server = WireMockServer.Start();
|
||||
var server = WireMockServer.Start();
|
||||
|
||||
// Act
|
||||
server.WithMapping(mapping);
|
||||
// Act
|
||||
server.WithMapping(mapping);
|
||||
|
||||
// Assert
|
||||
server.MappingModels.Should().HaveCount(1).And.Contain(m =>
|
||||
m.Guid == guid &&
|
||||
//((PathModel)m.Request.Path).Matchers.OfType<WildcardMatcher>().First().GetPatterns().First() == "/foo*"
|
||||
// m.Request.Body.Matchers.OfType<ExactMatcher>().First().GetPatterns().First() == pattern &&
|
||||
m.Response.Body == response &&
|
||||
(int)m.Response.StatusCode == 201
|
||||
);
|
||||
// Assert
|
||||
server.MappingModels.Should().HaveCount(1).And.Contain(m =>
|
||||
m.Guid == guid &&
|
||||
//((PathModel)m.Request.Path).Matchers.OfType<WildcardMatcher>().First().GetPatterns().First() == "/foo*"
|
||||
// m.Request.Body.Matchers.OfType<ExactMatcher>().First().GetPatterns().First() == pattern &&
|
||||
m.Response.Body == response &&
|
||||
(int?)m.Response.StatusCode == 201
|
||||
);
|
||||
|
||||
server.Stop();
|
||||
}
|
||||
server.Stop();
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void WireMockServer_WithMappingAsJson_Should_Add_Mapping()
|
||||
{
|
||||
// Arrange
|
||||
var mapping = @"{
|
||||
[Fact]
|
||||
public void WireMockServer_WithMappingAsJson_Should_Add_Mapping()
|
||||
{
|
||||
// Arrange
|
||||
var mapping = @"{
|
||||
""Guid"": ""532889c2-f84d-4dc8-b847-9ea2c6aca7d5"",
|
||||
""Request"": {
|
||||
""Path"": ""/pet"",
|
||||
@@ -78,25 +78,25 @@ namespace WireMock.Net.Tests.WithMapping
|
||||
}
|
||||
}";
|
||||
|
||||
var server = WireMockServer.Start();
|
||||
var server = WireMockServer.Start();
|
||||
|
||||
// Act
|
||||
server.WithMapping(mapping);
|
||||
// Act
|
||||
server.WithMapping(mapping);
|
||||
|
||||
// Assert
|
||||
server.MappingModels.Should().HaveCount(1).And.Contain(m =>
|
||||
m.Guid == Guid.Parse("532889c2-f84d-4dc8-b847-9ea2c6aca7d5") &&
|
||||
(int)m.Response.StatusCode == 201
|
||||
);
|
||||
// Assert
|
||||
server.MappingModels.Should().HaveCount(1).And.Contain(m =>
|
||||
m.Guid == Guid.Parse("532889c2-f84d-4dc8-b847-9ea2c6aca7d5") &&
|
||||
(int?)m.Response.StatusCode == 201
|
||||
);
|
||||
|
||||
server.Stop();
|
||||
}
|
||||
server.Stop();
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void WireMockServer_WithMappingsAsJson_Should_Add_Mapping()
|
||||
{
|
||||
// Arrange
|
||||
var mapping = @"[
|
||||
[Fact]
|
||||
public void WireMockServer_WithMappingsAsJson_Should_Add_Mapping()
|
||||
{
|
||||
// Arrange
|
||||
var mapping = @"[
|
||||
{
|
||||
""Guid"": ""532889c2-f84d-4dc8-b847-9ea2c6aca7d1"",
|
||||
""Request"": {
|
||||
@@ -117,15 +117,14 @@ namespace WireMock.Net.Tests.WithMapping
|
||||
}
|
||||
]";
|
||||
|
||||
var server = WireMockServer.Start();
|
||||
var server = WireMockServer.Start();
|
||||
|
||||
// Act
|
||||
server.WithMapping(mapping);
|
||||
// Act
|
||||
server.WithMapping(mapping);
|
||||
|
||||
// Assert
|
||||
server.MappingModels.Should().HaveCount(2);
|
||||
// Assert
|
||||
server.MappingModels.Should().HaveCount(2);
|
||||
|
||||
server.Stop();
|
||||
}
|
||||
server.Stop();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user