-
-
Notifications
You must be signed in to change notification settings - Fork 201
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
147 additions
and
51 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
44 changes: 26 additions & 18 deletions
44
src/WireMock.Net/ResponseBuilders/ICallbackResponseBuilder.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,19 +1,27 @@ | ||
using System; | ||
using JetBrains.Annotations; | ||
using WireMock.ResponseProviders; | ||
|
||
namespace WireMock.ResponseBuilders | ||
{ | ||
/// <summary> | ||
/// The CallbackResponseBuilder interface. | ||
/// </summary> | ||
public interface ICallbackResponseBuilder : IResponseProvider | ||
{ | ||
/// <summary> | ||
/// The callback builder | ||
/// </summary> | ||
/// <returns>The <see cref="IResponseBuilder"/>.</returns> | ||
[PublicAPI] | ||
IResponseBuilder WithCallback([NotNull] Func<RequestMessage, ResponseMessage> callbackHandler); | ||
} | ||
using System; | ||
using System.Threading.Tasks; | ||
using JetBrains.Annotations; | ||
using WireMock.ResponseProviders; | ||
|
||
namespace WireMock.ResponseBuilders | ||
{ | ||
/// <summary> | ||
/// The CallbackResponseBuilder interface. | ||
/// </summary> | ||
public interface ICallbackResponseBuilder : IResponseProvider | ||
{ | ||
/// <summary> | ||
/// The callback builder | ||
/// </summary> | ||
/// <returns>The <see cref="IResponseBuilder"/>.</returns> | ||
[PublicAPI] | ||
IResponseBuilder WithCallback([NotNull] Func<RequestMessage, ResponseMessage> callbackHandler); | ||
|
||
/// <summary> | ||
/// The async callback builder | ||
/// </summary> | ||
/// <returns>The <see cref="IResponseBuilder"/>.</returns> | ||
[PublicAPI] | ||
IResponseBuilder WithCallback([NotNull] Func<RequestMessage, Task<ResponseMessage>> callbackHandler); | ||
} | ||
} |
60 changes: 60 additions & 0 deletions
60
src/WireMock.Net/ResponseBuilders/Response.WithCallback.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
using System; | ||
using System.Threading.Tasks; | ||
using WireMock.Validation; | ||
|
||
namespace WireMock.ResponseBuilders | ||
{ | ||
public partial class Response | ||
{ | ||
/// <summary> | ||
/// A delegate to execute to generate the response. | ||
/// </summary> | ||
public Func<RequestMessage, ResponseMessage> Callback { get; private set; } | ||
|
||
/// <summary> | ||
/// A delegate to execute to generate the response async. | ||
/// </summary> | ||
public Func<RequestMessage, Task<ResponseMessage>> CallbackAsync { get; private set; } | ||
|
||
/// <summary> | ||
/// Defines if the method WithCallback(...) is used. | ||
/// </summary> | ||
public bool WithCallbackUsed { get; private set; } | ||
|
||
/// <inheritdoc cref="ICallbackResponseBuilder.WithCallback(Func{RequestMessage, ResponseMessage})"/> | ||
public IResponseBuilder WithCallback(Func<RequestMessage, ResponseMessage> callbackHandler) | ||
{ | ||
Check.NotNull(callbackHandler, nameof(callbackHandler)); | ||
|
||
return WithCallbackInternal(true, callbackHandler); | ||
} | ||
|
||
/// <inheritdoc cref="ICallbackResponseBuilder.WithCallback(Func{RequestMessage, Task{ResponseMessage}})"/> | ||
public IResponseBuilder WithCallback(Func<RequestMessage, Task<ResponseMessage>> callbackHandler) | ||
{ | ||
Check.NotNull(callbackHandler, nameof(callbackHandler)); | ||
|
||
return WithCallbackInternal(true, callbackHandler); | ||
} | ||
|
||
private IResponseBuilder WithCallbackInternal(bool withCallbackUsed, Func<RequestMessage, ResponseMessage> callbackHandler) | ||
{ | ||
Check.NotNull(callbackHandler, nameof(callbackHandler)); | ||
|
||
WithCallbackUsed = withCallbackUsed; | ||
Callback = callbackHandler; | ||
|
||
return this; | ||
} | ||
|
||
private IResponseBuilder WithCallbackInternal(bool withCallbackUsed, Func<RequestMessage, Task<ResponseMessage>> callbackHandler) | ||
{ | ||
Check.NotNull(callbackHandler, nameof(callbackHandler)); | ||
|
||
WithCallbackUsed = withCallbackUsed; | ||
CallbackAsync = callbackHandler; | ||
|
||
return this; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters