Skip to content

Commit 321b598

Browse files
committed
Merge branch 'master' into stef-fluent
2 parents 95c43a3 + 30ee768 commit 321b598

File tree

7 files changed

+45
-32
lines changed

7 files changed

+45
-32
lines changed

CHANGELOG.md

+4
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
# 1.5.46 (23 December 2023)
2+
- [#1044](https://github.com/WireMock-Net/WireMock.Net/pull/1044) - WireMockServerSettingsParser [refactor] contributed by [StefH](https://github.com/StefH)
3+
- [#1046](https://github.com/WireMock-Net/WireMock.Net/pull/1046) - Change FindRequestByMappingGuidAsync to return a collection of entries contributed by [tlevesque-ueat](https://github.com/tlevesque-ueat)
4+
15
# 1.5.45 (21 December 2023)
26
- [#1036](https://github.com/WireMock-Net/WireMock.Net/pull/1036) - Update Handlebars Transformer logic (ReplaceNodeOptions) [feature] contributed by [StefH](https://github.com/StefH)
37
- [#1043](https://github.com/WireMock-Net/WireMock.Net/pull/1043) - FindRequestByMappingGuidAsync [feature] contributed by [StefH](https://github.com/StefH)

Directory.Build.props

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
</PropertyGroup>
55

66
<PropertyGroup>
7-
<VersionPrefix>1.5.45</VersionPrefix>
7+
<VersionPrefix>1.5.46</VersionPrefix>
88
<PackageIcon>WireMock.Net-Logo.png</PackageIcon>
99
<PackageProjectUrl>https://github.com/WireMock-Net/WireMock.Net</PackageProjectUrl>
1010
<PackageLicenseExpression>Apache-2.0</PackageLicenseExpression>

Generate-ReleaseNotes.cmd

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
rem https://github.com/StefH/GitHubReleaseNotes
22

3-
SET version=1.5.45
3+
SET version=1.5.46
44

55
GitHubReleaseNotes --output CHANGELOG.md --skip-empty-releases --exclude-labels question invalid doc duplicate --version %version% --token %GH_TOKEN%
66

PackageReleaseNotes.txt

+3-4
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
1-
# 1.5.45 (21 December 2023)
2-
- #1036 Update Handlebars Transformer logic (ReplaceNodeOptions) [feature]
3-
- #1043 FindRequestByMappingGuidAsync [feature]
4-
- #1039 [Admin API] Find a request that matched a given mapping [feature]
1+
# 1.5.46 (23 December 2023)
2+
- #1044 WireMockServerSettingsParser [refactor]
3+
- #1046 Change FindRequestByMappingGuidAsync to return a collection of entries
54

65
The full release notes can be found here: https://github.com/WireMock-Net/WireMock.Net/blob/master/CHANGELOG.md

src/WireMock.Net.RestClient/IWireMockAdminApi.cs

+3-3
Original file line numberDiff line numberDiff line change
@@ -201,12 +201,12 @@ public interface IWireMockAdminApi
201201
Task<IList<LogEntryModel>> FindRequestsAsync([Body] RequestModel model, CancellationToken cancellationToken = default);
202202

203203
/// <summary>
204-
/// Find a request based on the Mapping Guid.
204+
/// Find requests based on the Mapping Guid.
205205
/// </summary>
206206
/// <param name="mappingGuid">The Mapping Guid</param>
207207
/// <param name="cancellationToken">The optional cancellationToken.</param>
208208
[Get("requests/find")]
209-
Task<LogEntryModel?> FindRequestByMappingGuidAsync([Query] Guid mappingGuid, CancellationToken cancellationToken = default);
209+
Task<IList<LogEntryModel>> FindRequestsByMappingGuidAsync([Query] Guid mappingGuid, CancellationToken cancellationToken = default);
210210

211211
/// <summary>
212212
/// Get all scenarios
@@ -304,4 +304,4 @@ public interface IWireMockAdminApi
304304
/// <param name="cancellationToken">The optional cancellationToken.</param>
305305
[Post("openapi/save")]
306306
Task<StatusModel> OpenApiSaveAsync([Body] string text, CancellationToken cancellationToken = default);
307-
}
307+
}

src/WireMock.Net/Server/WireMockServer.Admin.cs

+7-11
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ private void InitAdmin()
9999

100100
// __admin/requests/find
101101
Given(Request.Create().WithPath(AdminRequests + "/find").UsingPost()).AtPriority(WireMockConstants.AdminPriority).RespondWith(new DynamicResponseProvider(RequestsFind));
102-
Given(Request.Create().WithPath(AdminRequests + "/find").UsingGet().WithParam("mappingGuid", new NotNullOrEmptyMatcher())).AtPriority(WireMockConstants.AdminPriority).RespondWith(new DynamicResponseProvider(RequestFindByMappingGuid));
102+
Given(Request.Create().WithPath(AdminRequests + "/find").UsingGet().WithParam("mappingGuid", new NotNullOrEmptyMatcher())).AtPriority(WireMockConstants.AdminPriority).RespondWith(new DynamicResponseProvider(RequestsFindByMappingGuid));
103103

104104
// __admin/scenarios
105105
Given(Request.Create().WithPath(AdminScenarios).UsingGet()).AtPriority(WireMockConstants.AdminPriority).RespondWith(new DynamicResponseProvider(ScenariosGet));
@@ -602,21 +602,17 @@ private IResponseMessage RequestsFind(IRequestMessage requestMessage)
602602
return ToJson(result);
603603
}
604604

605-
private IResponseMessage RequestFindByMappingGuid(IRequestMessage requestMessage)
605+
private IResponseMessage RequestsFindByMappingGuid(IRequestMessage requestMessage)
606606
{
607607
if (requestMessage.Query != null &&
608608
requestMessage.Query.TryGetValue("mappingGuid", out var value) &&
609609
Guid.TryParse(value.ToString(), out var mappingGuid)
610610
)
611611
{
612-
var logEntry = LogEntries.SingleOrDefault(le => !le.RequestMessage.Path.StartsWith("/__admin/") && le.MappingGuid == mappingGuid);
613-
if (logEntry != null)
614-
{
615-
var logEntryMapper = new LogEntryMapper(_options);
616-
return ToJson(logEntryMapper.Map(logEntry));
617-
}
618-
619-
return ResponseMessageBuilder.Create(HttpStatusCode.OK);
612+
var logEntries = LogEntries.Where(le => !le.RequestMessage.Path.StartsWith("/__admin/") && le.MappingGuid == mappingGuid);
613+
var logEntryMapper = new LogEntryMapper(_options);
614+
var result = logEntries.Select(logEntryMapper.Map);
615+
return ToJson(result);
620616
}
621617

622618
return ResponseMessageBuilder.Create(HttpStatusCode.BadRequest);
@@ -833,4 +829,4 @@ private static T[] DeserializeObjectToArray<T>(object value)
833829
var singleResult = ((JObject)value).ToObject<T>();
834830
return new[] { singleResult! };
835831
}
836-
}
832+
}

test/WireMock.Net.Tests/WireMockAdminApiTests.cs

+26-12
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
#if !(NET452 || NET461 || NETCOREAPP3_1)
22
using System;
3+
using System.Collections.Generic;
34
using System.IO;
45
using System.Linq;
56
using System.Net;
@@ -25,6 +26,7 @@
2526
using WireMock.ResponseBuilders;
2627
using WireMock.Server;
2728
using WireMock.Settings;
29+
using WireMock.Types;
2830
using Xunit;
2931

3032
namespace WireMock.Net.Tests;
@@ -254,7 +256,7 @@ public async Task IWireMockAdminApi_FindRequestsAsync()
254256
}
255257

256258
[Fact]
257-
public async Task IWireMockAdminApi_FindRequestByMappingGuidAsync_Found()
259+
public async Task IWireMockAdminApi_FindRequestsByMappingGuidAsync_Found()
258260
{
259261
// Arrange
260262
var mappingGuid = Guid.NewGuid();
@@ -269,21 +271,33 @@ public async Task IWireMockAdminApi_FindRequestByMappingGuidAsync_Found()
269271
.RespondWith(Response.Create());
270272

271273
var serverUrl = "http://localhost:" + server.Ports[0];
272-
await new HttpClient().GetAsync(serverUrl + "/foo").ConfigureAwait(false);
274+
using var client = new HttpClient();
275+
await client.GetAsync(serverUrl + "/foo").ConfigureAwait(false);
276+
await client.GetAsync(serverUrl + "/foo?bar=baz").ConfigureAwait(false);
273277
var api = RestClient.For<IWireMockAdminApi>(serverUrl);
274278

275279
// Act
276-
var logEntryModel = await api.FindRequestByMappingGuidAsync(mappingGuid).ConfigureAwait(false);
280+
var logEntryModels = await api.FindRequestsByMappingGuidAsync(mappingGuid).ConfigureAwait(false);
277281

278282
// Assert
279-
logEntryModel.Should().NotBeNull();
280-
logEntryModel!.Request.Method.Should().Be("GET");
281-
logEntryModel!.Request.Body.Should().BeNull();
282-
logEntryModel!.Request.Path.Should().Be("/foo");
283+
logEntryModels.Should().HaveCount(2);
284+
logEntryModels[0].Should().NotBeNull();
285+
logEntryModels[0]!.Request.Method.Should().Be("GET");
286+
logEntryModels[0]!.Request.Body.Should().BeNull();
287+
logEntryModels[0]!.Request.Path.Should().Be("/foo");
288+
logEntryModels[0]!.Request.Query.Should().BeNullOrEmpty();
289+
logEntryModels[1].Should().NotBeNull();
290+
logEntryModels[1]!.Request.Method.Should().Be("GET");
291+
logEntryModels[1]!.Request.Body.Should().BeNull();
292+
logEntryModels[1]!.Request.Path.Should().Be("/foo");
293+
logEntryModels[1]!.Request.Query.Should().BeEquivalentTo(new Dictionary<string, WireMockList<string>>
294+
{
295+
{"bar", new WireMockList<string>("baz")}
296+
});
283297
}
284298

285299
[Fact]
286-
public async Task IWireMockAdminApi_FindRequestByMappingGuidAsync_NotFound()
300+
public async Task IWireMockAdminApi_FindRequestsByMappingGuidAsync_NotFound()
287301
{
288302
// Arrange
289303
var server = WireMockServer.Start(new WireMockServerSettings
@@ -301,14 +315,14 @@ public async Task IWireMockAdminApi_FindRequestByMappingGuidAsync_NotFound()
301315
var api = RestClient.For<IWireMockAdminApi>(serverUrl);
302316

303317
// Act
304-
var logEntryModel = await api.FindRequestByMappingGuidAsync(Guid.NewGuid()).ConfigureAwait(false);
318+
var logEntryModels = await api.FindRequestsByMappingGuidAsync(Guid.NewGuid()).ConfigureAwait(false);
305319

306320
// Assert
307-
logEntryModel.Should().BeNull();
321+
logEntryModels.Should().BeEmpty();
308322
}
309323

310324
[Fact]
311-
public async Task IWireMockAdminApi_FindRequestByMappingGuidAsync_Invalid_ShouldReturnBadRequest()
325+
public async Task IWireMockAdminApi_FindRequestsByMappingGuidAsync_Invalid_ShouldReturnBadRequest()
312326
{
313327
// Arrange
314328
var server = WireMockServer.Start(new WireMockServerSettings
@@ -1001,4 +1015,4 @@ public async Task IWireMockAdminApi_OpenApiSave_Yml()
10011015
server.Stop();
10021016
}
10031017
}
1004-
#endif
1018+
#endif

0 commit comments

Comments
 (0)