Set description when converting MappingModel to IRespondWithAProvider (#1317)

Adding a mapping with a description to `WireMockServer.WithMapping`
did not include the description to the resulting
`IRespondWithAProvider`, which means that calling
`WireMockServer.SavePact` does not populate the description in the
contract file.

This PR includes the description when mapping from `MappingModel` to
`IRespondWithAProvider`.
This commit is contained in:
Dom Light
2025-06-14 10:13:04 +01:00
committed by GitHub
parent acd6592562
commit 70a9180af4
2 changed files with 11 additions and 2 deletions

View File

@@ -76,6 +76,11 @@ public partial class WireMockServer
respondProvider = respondProvider.WithTitle(mappingModel.Title!);
}
if (!string.IsNullOrEmpty(mappingModel.Description))
{
respondProvider = respondProvider.WithDescription(mappingModel.Description!);
}
if (mappingModel.Priority != null)
{
respondProvider = respondProvider.AtPriority(mappingModel.Priority.Value);

View File

@@ -62,13 +62,15 @@ public partial class WireMockAdminApiTests
{
Request = new RequestModel { Path = "/1" },
Response = new ResponseModel { Body = "txt 1" },
Title = "test 1"
Title = "test 1",
Description = "description 1"
};
var model2 = new MappingModel
{
Request = new RequestModel { Path = "/2" },
Response = new ResponseModel { Body = "txt 2" },
Title = "test 2"
Title = "test 2",
Description = "description 2"
};
var result = await api.PostMappingsAsync(new[] { model1, model2 }).ConfigureAwait(false);
@@ -77,6 +79,8 @@ public partial class WireMockAdminApiTests
Check.That(result.Status).IsNotNull();
Check.That(result.Guid).IsNull();
Check.That(server.Mappings.Where(m => !m.IsAdminInterface)).HasSize(2);
Check.That(server.Mappings.Single(x => x.Title == "test 1").Description).IsEqualTo("description 1");
Check.That(server.Mappings.Single(x => x.Title == "test 2").Description).IsEqualTo("description 2");
server.Stop();
}