mirror of
https://github.com/wiremock/WireMock.Net.git
synced 2026-04-25 17:58:33 +02:00
Add Grpc ProtoBuf support (request-response) (#1047)
* ProtoBuf
* .
* x
* ---
* x
* fx
* ...
* sc
* ...
* .
* groen
* x
* fix tests
* ok!?
* fix tests
* fix tests
* !
* x
* 6
* .
* x
* ivaluematcher
* transformer
* .
* sc
* .
* mapping
* x
* tra
* com
* ...
* .
* .
* .
* AddProtoDefinition
* .
* set
* grpahj
* .
* .
* IdOrText
* ...
* async
* async2
* .
* t
* nuget
* <PackageReference Include="ProtoBufJsonConverter" Version="0.2.0-preview-04" />
* http version
* tests
* .WithHttpVersion("2")
* <PackageReference Include="ProtoBufJsonConverter" Version="0.2.0" />
* HttpVersionParser
This commit is contained in:
@@ -2,7 +2,6 @@
|
||||
// For more details see 'mock4net/LICENSE.txt' and 'mock4net/readme.md' in this project root.
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using JetBrains.Annotations;
|
||||
using Stef.Validation;
|
||||
using WireMock.Matchers.Request;
|
||||
using WireMock.Models;
|
||||
@@ -34,6 +33,8 @@ internal class RespondWithAProvider : IRespondWithAProvider
|
||||
private int _timesInSameState = 1;
|
||||
private bool? _useWebhookFireAndForget;
|
||||
private double? _probability;
|
||||
private IdOrText? _protoDefinition;
|
||||
private GraphQLSchemaDetails? _graphQLSchemaDetails;
|
||||
|
||||
public Guid Guid { get; private set; }
|
||||
|
||||
@@ -76,7 +77,8 @@ internal class RespondWithAProvider : IRespondWithAProvider
|
||||
/// <param name="provider">The provider.</param>
|
||||
public void RespondWith(IResponseProvider provider)
|
||||
{
|
||||
var mapping = new Mapping(
|
||||
var mapping = new Mapping
|
||||
(
|
||||
Guid,
|
||||
_dateTimeUtils.UtcNow,
|
||||
_title,
|
||||
@@ -93,14 +95,23 @@ internal class RespondWithAProvider : IRespondWithAProvider
|
||||
Webhooks,
|
||||
_useWebhookFireAndForget,
|
||||
TimeSettings,
|
||||
Data,
|
||||
_probability);
|
||||
Data
|
||||
);
|
||||
|
||||
if (_probability != null)
|
||||
{
|
||||
mapping.WithProbability(_probability.Value);
|
||||
}
|
||||
|
||||
if (_protoDefinition != null)
|
||||
{
|
||||
mapping.WithProtoDefinition(_protoDefinition.Value);
|
||||
}
|
||||
|
||||
_registrationCallback(mapping, _saveToFile);
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
[PublicAPI]
|
||||
public IRespondWithAProvider WithData(object data)
|
||||
{
|
||||
Data = data;
|
||||
@@ -117,7 +128,6 @@ internal class RespondWithAProvider : IRespondWithAProvider
|
||||
public IRespondWithAProvider WithGuid(Guid guid)
|
||||
{
|
||||
Guid = guid;
|
||||
|
||||
return this;
|
||||
}
|
||||
|
||||
@@ -133,7 +143,6 @@ internal class RespondWithAProvider : IRespondWithAProvider
|
||||
public IRespondWithAProvider WithDescription(string description)
|
||||
{
|
||||
_description = description;
|
||||
|
||||
return this;
|
||||
}
|
||||
|
||||
@@ -141,7 +150,6 @@ internal class RespondWithAProvider : IRespondWithAProvider
|
||||
public IRespondWithAProvider WithPath(string path)
|
||||
{
|
||||
_path = path;
|
||||
|
||||
return this;
|
||||
}
|
||||
|
||||
@@ -149,15 +157,13 @@ internal class RespondWithAProvider : IRespondWithAProvider
|
||||
public IRespondWithAProvider AtPriority(int priority)
|
||||
{
|
||||
_priority = priority;
|
||||
|
||||
return this;
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public IRespondWithAProvider InScenario(string scenario)
|
||||
{
|
||||
_scenario = scenario;
|
||||
|
||||
_scenario = Guard.NotNullOrWhiteSpace(scenario);
|
||||
return this;
|
||||
}
|
||||
|
||||
@@ -209,9 +215,7 @@ internal class RespondWithAProvider : IRespondWithAProvider
|
||||
/// <inheritdoc />
|
||||
public IRespondWithAProvider WithTimeSettings(ITimeSettings timeSettings)
|
||||
{
|
||||
Guard.NotNull(timeSettings, nameof(timeSettings));
|
||||
|
||||
TimeSettings = timeSettings;
|
||||
TimeSettings = Guard.NotNull(timeSettings);
|
||||
|
||||
return this;
|
||||
}
|
||||
@@ -219,10 +223,9 @@ internal class RespondWithAProvider : IRespondWithAProvider
|
||||
/// <inheritdoc />
|
||||
public IRespondWithAProvider WithWebhook(params IWebhook[] webhooks)
|
||||
{
|
||||
Guard.HasNoNulls(webhooks, nameof(webhooks));
|
||||
Guard.HasNoNulls(webhooks);
|
||||
|
||||
Webhooks = webhooks;
|
||||
|
||||
return this;
|
||||
}
|
||||
|
||||
@@ -283,13 +286,45 @@ internal class RespondWithAProvider : IRespondWithAProvider
|
||||
public IRespondWithAProvider WithWebhookFireAndForget(bool useWebhooksFireAndForget)
|
||||
{
|
||||
_useWebhookFireAndForget = useWebhooksFireAndForget;
|
||||
|
||||
return this;
|
||||
}
|
||||
|
||||
public IRespondWithAProvider WithProbability(double probability)
|
||||
{
|
||||
_probability = Guard.Condition(probability, p => p is >= 0 and <= 1.0);
|
||||
return this;
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public IRespondWithAProvider WithProtoDefinition(string protoDefinitionOrId)
|
||||
{
|
||||
Guard.NotNullOrWhiteSpace(protoDefinitionOrId);
|
||||
|
||||
if (_settings.ProtoDefinitions?.TryGetValue(protoDefinitionOrId, out var protoDefinition) == true)
|
||||
{
|
||||
_protoDefinition = new (protoDefinitionOrId, protoDefinition);
|
||||
}
|
||||
else
|
||||
{
|
||||
_protoDefinition = new(null, protoDefinitionOrId);
|
||||
}
|
||||
|
||||
return this;
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public IRespondWithAProvider WithGraphQLSchema(string graphQLSchemaOrId, IDictionary<string, Type>? customScalars = null)
|
||||
{
|
||||
Guard.NotNullOrWhiteSpace(graphQLSchemaOrId);
|
||||
|
||||
if (_settings.GraphQLSchemas?.TryGetValue(graphQLSchemaOrId, out _graphQLSchemaDetails) != true)
|
||||
{
|
||||
_graphQLSchemaDetails = new GraphQLSchemaDetails
|
||||
{
|
||||
SchemaAsString = graphQLSchemaOrId,
|
||||
CustomScalars = customScalars
|
||||
};
|
||||
}
|
||||
|
||||
return this;
|
||||
}
|
||||
@@ -299,7 +334,8 @@ internal class RespondWithAProvider : IRespondWithAProvider
|
||||
string method,
|
||||
IDictionary<string, WireMockList<string>>? headers,
|
||||
bool useTransformer,
|
||||
TransformerType transformerType)
|
||||
TransformerType transformerType
|
||||
)
|
||||
{
|
||||
return new Webhook
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user