| | | 1 | | using System; |
| | | 2 | | using WireMock.Matchers.Request; |
| | | 3 | | |
| | | 4 | | namespace WireMock.Server |
| | | 5 | | { |
| | | 6 | | /// <summary> |
| | | 7 | | /// The respond with a provider. |
| | | 8 | | /// </summary> |
| | | 9 | | internal class RespondWithAProvider : IRespondWithAProvider |
| | | 10 | | { |
| | | 11 | | private int _priority; |
| | | 12 | | private Guid? _guid; |
| | | 13 | | private string _title; |
| | | 14 | | |
| | | 15 | | /// <summary> |
| | | 16 | | /// The _registration callback. |
| | | 17 | | /// </summary> |
| | | 18 | | private readonly RegistrationCallback _registrationCallback; |
| | | 19 | | |
| | | 20 | | /// <summary> |
| | | 21 | | /// The _request matcher. |
| | | 22 | | /// </summary> |
| | | 23 | | private readonly IRequestMatcher _requestMatcher; |
| | | 24 | | |
| | | 25 | | /// <summary> |
| | | 26 | | /// Initializes a new instance of the <see cref="RespondWithAProvider"/> class. |
| | | 27 | | /// </summary> |
| | | 28 | | /// <param name="registrationCallback">The registration callback.</param> |
| | | 29 | | /// <param name="requestMatcher">The request matcher.</param> |
| | 17 | 30 | | public RespondWithAProvider(RegistrationCallback registrationCallback, IRequestMatcher requestMatcher) |
| | 17 | 31 | | { |
| | 17 | 32 | | _registrationCallback = registrationCallback; |
| | 17 | 33 | | _requestMatcher = requestMatcher; |
| | 17 | 34 | | } |
| | | 35 | | |
| | | 36 | | /// <summary> |
| | | 37 | | /// The respond with. |
| | | 38 | | /// </summary> |
| | | 39 | | /// <param name="provider"> |
| | | 40 | | /// The provider. |
| | | 41 | | /// </param> |
| | | 42 | | public void RespondWith(IResponseProvider provider) |
| | 17 | 43 | | { |
| | 17 | 44 | | var mappingGuid = _guid ?? Guid.NewGuid(); |
| | 17 | 45 | | _registrationCallback(new Mapping(mappingGuid, _title, _requestMatcher, provider, _priority)); |
| | 17 | 46 | | } |
| | | 47 | | |
| | | 48 | | /// <summary> |
| | | 49 | | /// Define a unique identifier for this mapping. |
| | | 50 | | /// </summary> |
| | | 51 | | /// <param name="guid">The unique identifier.</param> |
| | | 52 | | /// <returns>The <see cref="IRespondWithAProvider"/>.</returns> |
| | | 53 | | public IRespondWithAProvider WithGuid(string guid) |
| | 0 | 54 | | { |
| | 0 | 55 | | return WithGuid(Guid.Parse(guid)); |
| | 0 | 56 | | } |
| | | 57 | | |
| | | 58 | | /// <summary> |
| | | 59 | | /// Define a unique identifier for this mapping. |
| | | 60 | | /// </summary> |
| | | 61 | | /// <param name="guid">The unique identifier.</param> |
| | | 62 | | /// <returns>The <see cref="IRespondWithAProvider"/>.</returns> |
| | | 63 | | public IRespondWithAProvider WithGuid(Guid guid) |
| | 7 | 64 | | { |
| | 7 | 65 | | _guid = guid; |
| | | 66 | | |
| | 7 | 67 | | return this; |
| | 7 | 68 | | } |
| | | 69 | | |
| | | 70 | | /// <summary> |
| | | 71 | | /// Define a unique identifier for this mapping. |
| | | 72 | | /// </summary> |
| | | 73 | | /// <param name="title">The unique identifier.</param> |
| | | 74 | | /// <returns>The <see cref="IRespondWithAProvider"/>.</returns> |
| | | 75 | | public IRespondWithAProvider WithTitle(string title) |
| | 2 | 76 | | { |
| | 2 | 77 | | _title = title; |
| | | 78 | | |
| | 2 | 79 | | return this; |
| | 2 | 80 | | } |
| | | 81 | | |
| | | 82 | | /// <summary> |
| | | 83 | | /// Define the priority for this mapping. |
| | | 84 | | /// </summary> |
| | | 85 | | /// <param name="priority">The priority.</param> |
| | | 86 | | /// <returns>The <see cref="IRespondWithAProvider"/>.</returns> |
| | | 87 | | public IRespondWithAProvider AtPriority(int priority) |
| | 6 | 88 | | { |
| | 6 | 89 | | _priority = priority; |
| | | 90 | | |
| | 6 | 91 | | return this; |
| | 6 | 92 | | } |
| | | 93 | | } |
| | | 94 | | } |