-
-
Notifications
You must be signed in to change notification settings - Fork 213
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
15 changed files
with
577 additions
and
166 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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,96 +1,141 @@ | ||
using System; | ||
using System.Threading.Tasks; | ||
using JetBrains.Annotations; | ||
using WireMock.Matchers.Request; | ||
|
||
namespace WireMock | ||
{ | ||
/// <summary> | ||
/// The Mapping. | ||
/// </summary> | ||
public class Mapping | ||
{ | ||
/// <summary> | ||
/// Gets the unique identifier. | ||
/// </summary> | ||
/// <value> | ||
/// The unique identifier. | ||
/// </value> | ||
public Guid Guid { get; } | ||
|
||
/// <summary> | ||
/// Gets the unique title. | ||
/// </summary> | ||
/// <value> | ||
/// The unique title. | ||
/// </value> | ||
public string Title { get; } | ||
|
||
/// <summary> | ||
/// Gets the priority. | ||
/// </summary> | ||
/// <value> | ||
/// The priority. | ||
/// </value> | ||
public int Priority { get; } | ||
|
||
/// <summary> | ||
/// The Request matcher. | ||
/// </summary> | ||
public IRequestMatcher RequestMatcher { get; } | ||
|
||
/// <summary> | ||
/// The Provider. | ||
/// </summary> | ||
public IResponseProvider Provider { get; } | ||
|
||
/// <summary> | ||
/// Initializes a new instance of the <see cref="Mapping"/> class. | ||
/// </summary> | ||
/// <param name="guid">The unique identifier.</param> | ||
/// <param name="title">The unique title (can be null_.</param> | ||
/// <param name="requestMatcher">The request matcher.</param> | ||
/// <param name="provider">The provider.</param> | ||
/// <param name="priority">The priority for this mapping.</param> | ||
public Mapping(Guid guid, [CanBeNull] string title, IRequestMatcher requestMatcher, IResponseProvider provider, int priority) | ||
{ | ||
Priority = priority; | ||
Guid = guid; | ||
Title = title; | ||
RequestMatcher = requestMatcher; | ||
Provider = provider; | ||
} | ||
|
||
/// <summary> | ||
/// The response to. | ||
/// </summary> | ||
/// <param name="requestMessage">The request message.</param> | ||
/// <returns>The <see cref="ResponseMessage"/>.</returns> | ||
public async Task<ResponseMessage> ResponseToAsync(RequestMessage requestMessage) | ||
{ | ||
return await Provider.ProvideResponseAsync(requestMessage); | ||
} | ||
|
||
/// <summary> | ||
/// Determines whether the RequestMessage is handled. | ||
/// </summary> | ||
/// <param name="requestMessage">The request message.</param> | ||
/// <returns>The <see cref="RequestMatchResult"/>.</returns> | ||
public RequestMatchResult IsRequestHandled(RequestMessage requestMessage) | ||
{ | ||
var result = new RequestMatchResult(); | ||
|
||
RequestMatcher.GetMatchingScore(requestMessage, result); | ||
|
||
return result; | ||
} | ||
|
||
/// <summary> | ||
/// Gets a value indicating whether this mapping is an Admin Interface. | ||
/// </summary> | ||
/// <value> | ||
/// <c>true</c> if this mapping is an Admin Interface; otherwise, <c>false</c>. | ||
/// </value> | ||
public bool IsAdminInterface => Provider is DynamicResponseProvider || Provider is DynamicAsyncResponseProvider || Provider is ProxyAsyncResponseProvider; | ||
} | ||
using System; | ||
using System.Threading.Tasks; | ||
using JetBrains.Annotations; | ||
using WireMock.Matchers.Request; | ||
|
||
namespace WireMock | ||
{ | ||
/// <summary> | ||
/// The Mapping. | ||
/// </summary> | ||
public class Mapping | ||
{ | ||
/// <summary> | ||
/// Gets the unique identifier. | ||
/// </summary> | ||
/// <value> | ||
/// The unique identifier. | ||
/// </value> | ||
public Guid Guid { get; } | ||
|
||
/// <summary> | ||
/// Gets the unique title. | ||
/// </summary> | ||
/// <value> | ||
/// The unique title. | ||
/// </value> | ||
public string Title { get; } | ||
|
||
/// <summary> | ||
/// Gets the priority. | ||
/// </summary> | ||
/// <value> | ||
/// The priority. | ||
/// </value> | ||
public int Priority { get; } | ||
|
||
/// <summary> | ||
/// Scenario. | ||
/// </summary> | ||
[CanBeNull] | ||
public string Scenario { get; } | ||
|
||
/// <summary> | ||
/// Execution state condition for the current mapping. | ||
/// </summary> | ||
[CanBeNull] | ||
public object ExecutionConditionState { get; } | ||
|
||
/// <summary> | ||
/// The next state which will be signaled after the current mapping execution. | ||
/// In case the value is null state will not be changed. | ||
/// </summary> | ||
[CanBeNull] | ||
public object NextState { get; } | ||
|
||
/// <summary> | ||
/// The Request matcher. | ||
/// </summary> | ||
public IRequestMatcher RequestMatcher { get; } | ||
|
||
/// <summary> | ||
/// The Provider. | ||
/// </summary> | ||
public IResponseProvider Provider { get; } | ||
|
||
/// <summary> | ||
/// Is State started ? | ||
/// </summary> | ||
public bool IsStartState => Scenario == null || Scenario != null && NextState != null && ExecutionConditionState == null; | ||
|
||
/// <summary> | ||
/// Initializes a new instance of the <see cref="Mapping"/> class. | ||
/// </summary> | ||
/// <param name="guid">The unique identifier.</param> | ||
/// <param name="title">The unique title (can be null_.</param> | ||
/// <param name="requestMatcher">The request matcher.</param> | ||
/// <param name="provider">The provider.</param> | ||
/// <param name="priority">The priority for this mapping.</param> | ||
/// <param name="scenario">The scenario. [Optional]</param> | ||
/// <param name="executionConditionState">State in which the current mapping can occur. [Optional]</param> | ||
/// <param name="nextState">The next state which will occur after the current mapping execution. [Optional]</param> | ||
public Mapping(Guid guid, [CanBeNull] string title, IRequestMatcher requestMatcher, IResponseProvider provider, int priority, [CanBeNull] string scenario, [CanBeNull] object executionConditionState, [CanBeNull] object nextState) | ||
{ | ||
Guid = guid; | ||
Title = title; | ||
RequestMatcher = requestMatcher; | ||
Provider = provider; | ||
Priority = priority; | ||
Scenario = scenario; | ||
ExecutionConditionState = executionConditionState; | ||
NextState = nextState; | ||
} | ||
|
||
/// <summary> | ||
/// The response to. | ||
/// </summary> | ||
/// <param name="requestMessage">The request message.</param> | ||
/// <returns>The <see cref="ResponseMessage"/>.</returns> | ||
public async Task<ResponseMessage> ResponseToAsync(RequestMessage requestMessage) | ||
{ | ||
return await Provider.ProvideResponseAsync(requestMessage); | ||
} | ||
|
||
/// <summary> | ||
/// Gets the RequestMatchResult based on the RequestMessage. | ||
/// </summary> | ||
/// <param name="requestMessage">The request message.</param> | ||
/// <param name="nextState">The Next State.</param> | ||
/// <returns>The <see cref="RequestMatchResult"/>.</returns> | ||
public RequestMatchResult GetRequestMatchResult(RequestMessage requestMessage, [CanBeNull] object nextState) | ||
{ | ||
var result = new RequestMatchResult(); | ||
|
||
RequestMatcher.GetMatchingScore(requestMessage, result); | ||
|
||
// Only check state if Scenario is defined | ||
if (Scenario != null) | ||
{ | ||
var matcher = new RequestMessageScenarioAndStateMatcher(nextState, ExecutionConditionState); | ||
matcher.GetMatchingScore(requestMessage, result); | ||
//// If ExecutionConditionState is null, this means that request is the start from a scenario. So just return. | ||
//if (ExecutionConditionState != null) | ||
//{ | ||
// // ExecutionConditionState is not null, so get score for matching with the nextState. | ||
// var matcher = new RequestMessageScenarioAndStateMatcher(nextState, ExecutionConditionState); | ||
// matcher.GetMatchingScore(requestMessage, result); | ||
//} | ||
} | ||
|
||
return result; | ||
} | ||
|
||
/// <summary> | ||
/// Gets a value indicating whether this mapping is an Admin Interface. | ||
/// </summary> | ||
/// <value> | ||
/// <c>true</c> if this mapping is an Admin Interface; otherwise, <c>false</c>. | ||
/// </value> | ||
public bool IsAdminInterface => Provider is DynamicResponseProvider || Provider is DynamicAsyncResponseProvider || Provider is ProxyAsyncResponseProvider; | ||
} | ||
} |
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
Oops, something went wrong.