Skip to content

Commit

Permalink
.
Browse files Browse the repository at this point in the history
  • Loading branch information
StefH committed Dec 29, 2023
1 parent 90ca499 commit 8436a84
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 17 deletions.
7 changes: 7 additions & 0 deletions src/WireMock.Net/Server/IRespondWithAProvider.cs
Original file line number Diff line number Diff line change
Expand Up @@ -184,4 +184,11 @@ IRespondWithAProvider WithWebhook(
/// <param name="probability">The probability when this request should be matched. Value is between 0 and 1.</param>
/// <returns>The <see cref="IRespondWithAProvider"/>.</returns>
IRespondWithAProvider WithProbability(double probability);

/// <summary>
/// Add a Grpc ProtoDefinition which is used for the request and the response.
/// </summary>
/// <param name="protoDefinition">The proto definition as a string.</param>
/// <returns>The <see cref="IRespondWithAProvider"/>.</returns>
IRespondWithAProvider WithProtoDefinition(string protoDefinition);
}
33 changes: 17 additions & 16 deletions src/WireMock.Net/Server/RespondWithAProvider.cs
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,8 @@ internal class RespondWithAProvider : IRespondWithAProvider

public object? Data { get; private set; }

public string? ProtoDefinition { get; private set; }

/// <summary>
/// Initializes a new instance of the <see cref="RespondWithAProvider"/> class.
/// </summary>
Expand Down Expand Up @@ -76,7 +78,8 @@ public RespondWithAProvider(
/// <param name="provider">The provider.</param>
public void RespondWith(IResponseProvider provider)
{
var mapping = new Mapping(
var mapping = new Mapping
(
Guid,
_dateTimeUtils.UtcNow,
_title,
Expand All @@ -94,13 +97,13 @@ public void RespondWith(IResponseProvider provider)
_useWebhookFireAndForget,
TimeSettings,
Data,
_probability);
_probability
);

_registrationCallback(mapping, _saveToFile);
}

/// <inheritdoc />
[PublicAPI]
public IRespondWithAProvider WithData(object data)
{
Data = data;
Expand All @@ -117,7 +120,6 @@ public IRespondWithAProvider WithGuid(string guid)
public IRespondWithAProvider WithGuid(Guid guid)
{
Guid = guid;

return this;
}

Expand All @@ -133,31 +135,27 @@ public IRespondWithAProvider WithTitle(string title)
public IRespondWithAProvider WithDescription(string description)
{
_description = description;

return this;
}

/// <see cref="IRespondWithAProvider.WithPath"/>
public IRespondWithAProvider WithPath(string path)
{
_path = path;

return this;
}

/// <inheritdoc />
public IRespondWithAProvider AtPriority(int priority)
{
_priority = priority;

return this;
}

/// <inheritdoc />
public IRespondWithAProvider InScenario(string scenario)
{
_scenario = scenario;

_scenario = Guard.NotNullOrWhiteSpace(scenario);
return this;
}

Expand Down Expand Up @@ -209,20 +207,17 @@ public IRespondWithAProvider WillSetStateTo(int state, int? times = 1)
/// <inheritdoc />
public IRespondWithAProvider WithTimeSettings(ITimeSettings timeSettings)
{
Guard.NotNull(timeSettings, nameof(timeSettings));

TimeSettings = timeSettings;
TimeSettings = Guard.NotNull(timeSettings);

return this;
}

/// <inheritdoc />
public IRespondWithAProvider WithWebhook(params IWebhook[] webhooks)
{
Guard.HasNoNulls(webhooks, nameof(webhooks));
Guard.HasNoNulls(webhooks);

Webhooks = webhooks;

return this;
}

Expand Down Expand Up @@ -283,14 +278,19 @@ public IRespondWithAProvider WithWebhook(
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 protoDefinition)
{
ProtoDefinition = Guard.NotNullOrWhiteSpace(protoDefinition);
return this;
}

Expand All @@ -299,7 +299,8 @@ private static IWebhook InitWebhook(
string method,
IDictionary<string, WireMockList<string>>? headers,
bool useTransformer,
TransformerType transformerType)
TransformerType transformerType
)
{
return new Webhook
{
Expand Down
2 changes: 1 addition & 1 deletion test/WireMock.Net.Tests/Grpc/WireMockServerTests.Grpc.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ namespace WireMock.Net.Tests;
public partial class WireMockServerTests
{
[Fact]
public async Task WireMockServer_WithBodyAsProtoBuf_UsingGrpcGeneratedClient()
public async Task WireMockServer_WithBodyAsProtoBuf_InlineProtoDefinition_UsingGrpcGeneratedClient()
{
// Arrange
using var server = WireMockServer.Start(useHttp2: true);
Expand Down

0 comments on commit 8436a84

Please sign in to comment.