Add WithBody with IDictionary (form-urlencoded values) (#903)

* .

* x

* fx

* fix

* f

* tests

* fix tests

* add tst
This commit is contained in:
Stef Heyenrath
2023-03-17 17:08:45 +01:00
committed by GitHub
parent 19701f5260
commit 78b94d2ebc
13 changed files with 286 additions and 106 deletions

View File

@@ -1,4 +1,5 @@
using System;
using System.Collections.Generic;
using System.Text;
using FluentAssertions;
using Newtonsoft.Json;
@@ -55,11 +56,31 @@ namespace WireMock.Net.Tests
Check.That(requestBuilder.GetMatchingScore(request, requestMatchResult)).IsEqualTo(1.0);
}
[Fact]
public void Request_WithBody_FuncFormUrlEncoded()
{
// Assign
var requestBuilder = Request.Create().UsingAnyMethod().WithBody((IDictionary<string, string>? values) => values != null);
// Act
var body = new BodyData
{
BodyAsFormUrlEncoded = new Dictionary<string, string>(),
DetectedBodyTypeFromContentType = BodyType.FormUrlEncoded,
DetectedBodyType = BodyType.FormUrlEncoded
};
var request = new RequestMessage(new UrlDetails("http://localhost/foo"), "POST", ClientIp, body);
// Assert
var requestMatchResult = new RequestMatchResult();
Check.That(requestBuilder.GetMatchingScore(request, requestMatchResult)).IsEqualTo(1.0);
}
[Fact]
public void Request_WithBody_FuncBodyData()
{
// Assign
var requestBuilder = Request.Create().UsingAnyMethod().WithBody((IBodyData b) => b != null);
var requestBuilder = Request.Create().UsingAnyMethod().WithBody((IBodyData? b) => b != null);
// Act
var body = new BodyData
@@ -78,7 +99,7 @@ namespace WireMock.Net.Tests
public void Request_WithBody_FuncByteArray()
{
// Assign
var requestBuilder = Request.Create().UsingAnyMethod().WithBody((byte[] b) => b != null);
var requestBuilder = Request.Create().UsingAnyMethod().WithBody((byte[]? b) => b != null);
// Act
var body = new BodyData