| | | 1 | | using System; |
| | | 2 | | using System.Threading.Tasks; |
| | | 3 | | using JetBrains.Annotations; |
| | | 4 | | using WireMock.Matchers.Request; |
| | | 5 | | |
| | | 6 | | namespace WireMock |
| | | 7 | | { |
| | | 8 | | /// <summary> |
| | | 9 | | /// The Mapping. |
| | | 10 | | /// </summary> |
| | | 11 | | public class Mapping |
| | | 12 | | { |
| | | 13 | | /// <summary> |
| | | 14 | | /// Gets the unique identifier. |
| | | 15 | | /// </summary> |
| | | 16 | | /// <value> |
| | | 17 | | /// The unique identifier. |
| | | 18 | | /// </value> |
| | 35 | 19 | | public Guid Guid { get; } |
| | | 20 | | |
| | | 21 | | /// <summary> |
| | | 22 | | /// Gets the unique title. |
| | | 23 | | /// </summary> |
| | | 24 | | /// <value> |
| | | 25 | | /// The unique title. |
| | | 26 | | /// </value> |
| | 9 | 27 | | public string Title { get; } |
| | | 28 | | |
| | | 29 | | /// <summary> |
| | | 30 | | /// Gets the priority. |
| | | 31 | | /// </summary> |
| | | 32 | | /// <value> |
| | | 33 | | /// The priority. |
| | | 34 | | /// </value> |
| | 12 | 35 | | public int Priority { get; } |
| | | 36 | | |
| | | 37 | | /// <summary> |
| | | 38 | | /// The Request matcher. |
| | | 39 | | /// </summary> |
| | 13 | 40 | | public IRequestMatcher RequestMatcher { get; } |
| | | 41 | | |
| | | 42 | | /// <summary> |
| | | 43 | | /// The Provider. |
| | | 44 | | /// </summary> |
| | 18 | 45 | | public IResponseProvider Provider { get; } |
| | | 46 | | |
| | | 47 | | /// <summary> |
| | | 48 | | /// Initializes a new instance of the <see cref="Mapping"/> class. |
| | | 49 | | /// </summary> |
| | | 50 | | /// <param name="guid">The unique identifier.</param> |
| | | 51 | | /// <param name="title">The unique title (can be null_.</param> |
| | | 52 | | /// <param name="requestMatcher">The request matcher.</param> |
| | | 53 | | /// <param name="provider">The provider.</param> |
| | | 54 | | /// <param name="priority">The priority for this mapping.</param> |
| | 17 | 55 | | public Mapping(Guid guid, [CanBeNull] string title, IRequestMatcher requestMatcher, IResponseProvider provider, |
| | 17 | 56 | | { |
| | 17 | 57 | | Priority = priority; |
| | 17 | 58 | | Guid = guid; |
| | 17 | 59 | | Title = title; |
| | 17 | 60 | | RequestMatcher = requestMatcher; |
| | 17 | 61 | | Provider = provider; |
| | 17 | 62 | | } |
| | | 63 | | |
| | | 64 | | /// <summary> |
| | | 65 | | /// The response to. |
| | | 66 | | /// </summary> |
| | | 67 | | /// <param name="requestMessage">The request message.</param> |
| | | 68 | | /// <returns>The <see cref="Task"/>.</returns> |
| | | 69 | | public async Task<ResponseMessage> ResponseTo(RequestMessage requestMessage) |
| | 7 | 70 | | { |
| | 7 | 71 | | return await Provider.ProvideResponse(requestMessage); |
| | 7 | 72 | | } |
| | | 73 | | |
| | | 74 | | /// <summary> |
| | | 75 | | /// Determines whether the RequestMessage is handled. |
| | | 76 | | /// </summary> |
| | | 77 | | /// <param name="requestMessage">The request message.</param> |
| | | 78 | | /// <returns>The <see cref="RequestMatchResult"/>.</returns> |
| | | 79 | | public RequestMatchResult IsRequestHandled(RequestMessage requestMessage) |
| | 10 | 80 | | { |
| | 10 | 81 | | var result = new RequestMatchResult(); |
| | | 82 | | |
| | 10 | 83 | | RequestMatcher.GetMatchingScore(requestMessage, result); |
| | | 84 | | |
| | 10 | 85 | | return result; |
| | 10 | 86 | | } |
| | | 87 | | |
| | | 88 | | /// <summary> |
| | | 89 | | /// Gets a value indicating whether this mapping is an Admin Interface. |
| | | 90 | | /// </summary> |
| | | 91 | | /// <value> |
| | | 92 | | /// <c>true</c> if this mapping is an Admin Interface; otherwise, <c>false</c>. |
| | | 93 | | /// </value> |
| | 7 | 94 | | public bool IsAdminInterface => Provider is DynamicResponseProvider; |
| | | 95 | | } |
| | | 96 | | } |