mirror of
https://github.com/wiremock/WireMock.Net.git
synced 2026-02-22 00:37:50 +01:00
pact
This commit is contained in:
@@ -5,11 +5,11 @@ namespace WireMock.Pact.Models.V2;
|
||||
|
||||
public class Interaction
|
||||
{
|
||||
public string? Description { get; set; }
|
||||
public required string Description { get; set; }
|
||||
|
||||
public string? ProviderState { get; set; }
|
||||
|
||||
public PactRequest Request { get; set; } = new();
|
||||
public required PactRequest Request { get; set; }
|
||||
|
||||
public PactResponse Response { get; set; } = new();
|
||||
public required PactResponse Response { get; set; }
|
||||
}
|
||||
@@ -8,20 +8,20 @@ public class MatchingRule
|
||||
/// <summary>
|
||||
/// type or regex
|
||||
/// </summary>
|
||||
public string Match { get; set; } = "type";
|
||||
public required string Match { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Used for Match = "type"
|
||||
/// </summary>
|
||||
public string Min { get; set; }
|
||||
public string? Min { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Used for Match = "type"
|
||||
/// </summary>
|
||||
public string Max { get; set; }
|
||||
public string? Max { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Used for Match = "regex"
|
||||
/// </summary>
|
||||
public string Regex { get; set; }
|
||||
public string? Regex { get; set; }
|
||||
}
|
||||
@@ -5,7 +5,7 @@ namespace WireMock.Pact.Models.V2;
|
||||
|
||||
public class Metadata
|
||||
{
|
||||
public string PactSpecificationVersion { get; set; }
|
||||
public required string PactSpecificationVersion { get; set; }
|
||||
|
||||
public PactSpecification PactSpecification { get; set; } = new PactSpecification();
|
||||
public required PactSpecification PactSpecification { get; set; }
|
||||
}
|
||||
@@ -1,17 +1,15 @@
|
||||
// Copyright © WireMock.Net
|
||||
|
||||
#pragma warning disable CS1591
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace WireMock.Pact.Models.V2;
|
||||
|
||||
public class Pact
|
||||
{
|
||||
public Pacticipant Consumer { get; set; }
|
||||
public required Pacticipant Consumer { get; set; }
|
||||
|
||||
public List<Interaction> Interactions { get; set; } = new List<Interaction>();
|
||||
public required List<Interaction> Interactions { get; set; } = [];
|
||||
|
||||
public Metadata Metadata { get; set; }
|
||||
public Metadata? Metadata { get; set; }
|
||||
|
||||
public Pacticipant Provider { get; set; }
|
||||
public required Pacticipant Provider { get; set; }
|
||||
}
|
||||
@@ -1,7 +1,6 @@
|
||||
// Copyright © WireMock.Net
|
||||
|
||||
#pragma warning disable CS1591
|
||||
using System.Collections.Generic;
|
||||
using WireMock.Constants;
|
||||
|
||||
namespace WireMock.Pact.Models.V2;
|
||||
@@ -10,9 +9,9 @@ public class PactRequest
|
||||
{
|
||||
public IDictionary<string, string>? Headers { get; set; }
|
||||
|
||||
public string Method { get; set; } = HttpRequestMethod.GET;
|
||||
public required string Method { get; set; } = HttpRequestMethod.GET;
|
||||
|
||||
public string? Path { get; set; } = "/";
|
||||
public required string Path { get; set; } = "/";
|
||||
|
||||
public string? Query { get; set; }
|
||||
|
||||
|
||||
@@ -1,8 +1,6 @@
|
||||
// Copyright © WireMock.Net
|
||||
|
||||
#pragma warning disable CS1591
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace WireMock.Pact.Models.V2;
|
||||
|
||||
public class PactResponse
|
||||
@@ -11,5 +9,5 @@ public class PactResponse
|
||||
|
||||
public IDictionary<string, string>? Headers { get; set; }
|
||||
|
||||
public int Status { get; set; } = 200;
|
||||
public required int Status { get; set; }
|
||||
}
|
||||
@@ -5,9 +5,9 @@ namespace WireMock.Pact.Models.V2;
|
||||
|
||||
public class PactRust
|
||||
{
|
||||
public string Ffi { get; set; }
|
||||
public required string Ffi { get; set; }
|
||||
|
||||
public string Mockserver { get; set; }
|
||||
public required string Mockserver { get; set; }
|
||||
|
||||
public string Models { get; set; }
|
||||
public required string Models { get; set; }
|
||||
}
|
||||
@@ -5,5 +5,5 @@ namespace WireMock.Pact.Models.V2;
|
||||
|
||||
public class PactSpecification
|
||||
{
|
||||
public string Version { get; set; } = "2.0";
|
||||
public required string Version { get; set; } = "2.0";
|
||||
}
|
||||
@@ -5,5 +5,5 @@ namespace WireMock.Pact.Models.V2;
|
||||
|
||||
public class Pacticipant
|
||||
{
|
||||
public string Name { get; set; }
|
||||
public required string Name { get; set; }
|
||||
}
|
||||
@@ -7,7 +7,7 @@ namespace WireMock.Pact.Models.V2;
|
||||
|
||||
public class ProviderState
|
||||
{
|
||||
public string Name { get; set; }
|
||||
public required string Name { get; set; }
|
||||
|
||||
public IDictionary<string, string> Params { get; set; }
|
||||
public IDictionary<string, string>? Params { get; set; }
|
||||
}
|
||||
@@ -1,8 +1,5 @@
|
||||
// Copyright © WireMock.Net
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using WireMock.Admin.Mappings;
|
||||
using WireMock.Extensions;
|
||||
using WireMock.Pact.Models.V2;
|
||||
@@ -28,7 +25,8 @@ internal static class PactMapper
|
||||
var pact = new Pact.Models.V2.Pact
|
||||
{
|
||||
Consumer = new Pacticipant { Name = consumer },
|
||||
Provider = new Pacticipant { Name = provider }
|
||||
Provider = new Pacticipant { Name = provider },
|
||||
Interactions = []
|
||||
};
|
||||
|
||||
foreach (var mapping in server.MappingModels.OrderBy(m => m.Guid))
|
||||
@@ -42,7 +40,7 @@ internal static class PactMapper
|
||||
|
||||
var interaction = new Interaction
|
||||
{
|
||||
Description = !string.IsNullOrWhiteSpace(mapping.Description) ? mapping.Description : mapping.Title ?? string.Empty,
|
||||
Description = mapping.Description ?? mapping.Title ?? string.Empty,
|
||||
Request = MapRequest(mapping.Request, path),
|
||||
Response = MapResponse(mapping.Response)
|
||||
};
|
||||
@@ -65,13 +63,8 @@ internal static class PactMapper
|
||||
};
|
||||
}
|
||||
|
||||
private static PactResponse MapResponse(ResponseModel? response)
|
||||
private static PactResponse MapResponse(ResponseModel response)
|
||||
{
|
||||
if (response == null)
|
||||
{
|
||||
return new PactResponse();
|
||||
}
|
||||
|
||||
return new PactResponse
|
||||
{
|
||||
Status = MapStatusCode(response.StatusCode),
|
||||
|
||||
Reference in New Issue
Block a user