From 04bcca6e14a737584e5fbf2d3a23382f5e826a58 Mon Sep 17 00:00:00 2001 From: Stef Heyenrath Date: Sun, 30 Sep 2018 11:25:14 +0200 Subject: [PATCH] Refactor (#208) --- ...ireMock.Net.WebApplication.NETCore2.csproj | 1 + src/WireMock.Net/Http/HttpClientHelper.cs | 2 +- .../ClientCertificateHelper.cs | 4 +- src/WireMock.Net/IMapping.cs | 16 ++--- src/WireMock.Net/Mapping.cs | 61 +++++-------------- 5 files changed, 26 insertions(+), 58 deletions(-) diff --git a/examples/WireMock.Net.WebApplication/WireMock.Net.WebApplication.NETCore2.csproj b/examples/WireMock.Net.WebApplication/WireMock.Net.WebApplication.NETCore2.csproj index e4844cb6e..7bf0b35c1 100644 --- a/examples/WireMock.Net.WebApplication/WireMock.Net.WebApplication.NETCore2.csproj +++ b/examples/WireMock.Net.WebApplication/WireMock.Net.WebApplication.NETCore2.csproj @@ -6,6 +6,7 @@ WireMock.Net.WebApplication.Program WireMock.Net.WebApplication WireMock.Net.WebApplication + efcf4a18-fd7c-4622-825d-336d65290599 diff --git a/src/WireMock.Net/Http/HttpClientHelper.cs b/src/WireMock.Net/Http/HttpClientHelper.cs index aa0b74764..883cb8975 100644 --- a/src/WireMock.Net/Http/HttpClientHelper.cs +++ b/src/WireMock.Net/Http/HttpClientHelper.cs @@ -71,7 +71,7 @@ public static async Task SendAsync([NotNull] HttpClient client, // Call the URL var httpResponseMessage = await client.SendAsync(httpRequestMessage, HttpCompletionOption.ResponseContentRead); - // Parse httpResponseMessage + // Create ResponseMessage return await HttpResponseMessageHelper.Create(httpResponseMessage, requiredUri, originalUri); } } diff --git a/src/WireMock.Net/HttpsCertificate/ClientCertificateHelper.cs b/src/WireMock.Net/HttpsCertificate/ClientCertificateHelper.cs index 85c12b215..bd81e4146 100644 --- a/src/WireMock.Net/HttpsCertificate/ClientCertificateHelper.cs +++ b/src/WireMock.Net/HttpsCertificate/ClientCertificateHelper.cs @@ -1,5 +1,4 @@ -using System; -using System.IO; +using System.IO; using System.Security.Cryptography.X509Certificates; namespace WireMock.HttpsCertificate @@ -26,6 +25,7 @@ public static X509Certificate2 GetCertificate(string thumbprintOrSubjectName) throw new FileNotFoundException("No certificate found with specified Thumbprint or SubjectName.", thumbprintOrSubjectName); } } + // Use the first matching certificate. return matchingCertificates[0]; } diff --git a/src/WireMock.Net/IMapping.cs b/src/WireMock.Net/IMapping.cs index 10e93db82..4dca9571b 100644 --- a/src/WireMock.Net/IMapping.cs +++ b/src/WireMock.Net/IMapping.cs @@ -65,6 +65,14 @@ public interface IMapping /// bool IsStartState { get; } + /// + /// Gets a value indicating whether this mapping is an Admin Interface. + /// + /// + /// true if this mapping is an Admin Interface; otherwise, false. + /// + bool IsAdminInterface { get; } + /// /// ResponseToAsync /// @@ -79,13 +87,5 @@ public interface IMapping /// The Next State. /// The . RequestMatchResult GetRequestMatchResult(RequestMessage requestMessage, [CanBeNull] string nextState); - - /// - /// Gets a value indicating whether this mapping is an Admin Interface. - /// - /// - /// true if this mapping is an Admin Interface; otherwise, false. - /// - bool IsAdminInterface { get; } } } \ No newline at end of file diff --git a/src/WireMock.Net/Mapping.cs b/src/WireMock.Net/Mapping.cs index edb6a099f..b35a47c3a 100644 --- a/src/WireMock.Net/Mapping.cs +++ b/src/WireMock.Net/Mapping.cs @@ -14,55 +14,39 @@ public class Mapping : IMapping /// public Guid Guid { get; } - /// - /// Gets the unique title. - /// + /// public string Title { get; } - /// - /// The full filename path for this mapping (only defined for static mappings). - /// + /// public string Path { get; set; } - /// - /// Gets the priority. - /// + /// public int Priority { get; } - /// - /// Scenario. - /// + /// [CanBeNull] public string Scenario { get; } - /// - /// Execution state condition for the current mapping. - /// + /// [CanBeNull] public string ExecutionConditionState { get; } - /// - /// The next state which will be signaled after the current mapping execution. - /// In case the value is null, state will not be changed. - /// + /// [CanBeNull] public string NextState { get; } - /// - /// The Request matcher. - /// + /// public IRequestMatcher RequestMatcher { get; } - /// - /// The Provider. - /// + /// public IResponseProvider Provider { get; } - /// - /// Is State started ? - /// + /// public bool IsStartState => Scenario == null || Scenario != null && NextState != null && ExecutionConditionState == null; + /// + public bool IsAdminInterface => Provider is DynamicResponseProvider || Provider is DynamicAsyncResponseProvider || Provider is ProxyAsyncResponseProvider; + /// /// Initializes a new instance of the class. /// @@ -88,22 +72,13 @@ public Mapping(Guid guid, [CanBeNull] string title, [CanBeNull] string path, IRe NextState = nextState; } - /// - /// The response to. - /// - /// The request message. - /// The . + /// public async Task ResponseToAsync(RequestMessage requestMessage) { return await Provider.ProvideResponseAsync(requestMessage); } - /// - /// Gets the RequestMatchResult based on the RequestMessage. - /// - /// The request message. - /// The Next State. - /// The . + /// public RequestMatchResult GetRequestMatchResult(RequestMessage requestMessage, [CanBeNull] string nextState) { var result = new RequestMatchResult(); @@ -126,13 +101,5 @@ public RequestMatchResult GetRequestMatchResult(RequestMessage requestMessage, [ return result; } - - /// - /// Gets a value indicating whether this mapping is an Admin Interface. - /// - /// - /// true if this mapping is an Admin Interface; otherwise, false. - /// - public bool IsAdminInterface => Provider is DynamicResponseProvider || Provider is DynamicAsyncResponseProvider || Provider is ProxyAsyncResponseProvider; } } \ No newline at end of file