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,5 +1,5 @@
using FluentAssertions;
using System.Collections.Generic;
using FluentAssertions;
using WireMock.Types;
using WireMock.Util;
using Xunit;
@@ -8,6 +8,36 @@ namespace WireMock.Net.Tests.Util;
public class QueryStringParserTests
{
public static IEnumerable<object?[]> QueryStringTestData => new List<object?[]>
{
new object?[] { null, false, false, null },
new object?[] { string.Empty, false, true, new Dictionary<string, string>() },
new object?[] { "test", false, true, new Dictionary<string, string>() },
new object?[] { "&", false, true, new Dictionary<string, string>() },
new object?[] { "&&", false, true, new Dictionary<string, string>() },
new object?[] { "a=", false, true, new Dictionary<string, string> { { "a", "" } } },
new object?[] { "&a", false, true, new Dictionary<string, string>() },
new object?[] { "&a=", false, true, new Dictionary<string, string> { { "a", "" } } },
new object?[] { "&key1=value1", false, true, new Dictionary<string, string> { { "key1", "value1" } } },
new object?[] { "key1=value1", false, true, new Dictionary<string, string> { { "key1", "value1" } } },
new object?[] { "key1=value1&key2=value2", false, true, new Dictionary<string, string> { { "key1", "value1" }, { "key2", "value2" } } },
new object?[] { "key1=value1&key2=value2&", false, true, new Dictionary<string, string> { { "key1", "value1" }, { "key2", "value2" } } },
new object?[] { "key1=value1&&key2=value2", false, true, new Dictionary<string, string> { { "key1", "value1" }, { "key2", "value2" } } },
new object?[] { "&key1=value1&key2=value2&&", false, true, new Dictionary<string, string> { { "key1", "value1" }, { "key2", "value2" } } },
};
[Theory]
[MemberData(nameof(QueryStringTestData))]
public void TryParse_Should_Parse_QueryString(string queryString, bool caseIgnore, bool expectedResult, IDictionary<string, string> expectedOutput)
{
// Act
var result = QueryStringParser.TryParse(queryString, caseIgnore, out var actual);
// Assert
result.Should().Be(expectedResult);
actual.Should().BeEquivalentTo(expectedOutput);
}
[Fact]
public void Parse_WithNullString()
{