Skip to content

Commit

Permalink
Refactor (#208)
Browse files Browse the repository at this point in the history
  • Loading branch information
StefH committed Sep 30, 2018
1 parent ada50d8 commit 04bcca6
Show file tree
Hide file tree
Showing 5 changed files with 26 additions and 58 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
<StartupObject>WireMock.Net.WebApplication.Program</StartupObject>
<AssemblyName>WireMock.Net.WebApplication</AssemblyName>
<RootNamespace>WireMock.Net.WebApplication</RootNamespace>
<UserSecretsId>efcf4a18-fd7c-4622-825d-336d65290599</UserSecretsId>
</PropertyGroup>

<ItemGroup Condition=" '$(TargetFramework)' == 'netcoreapp2.0'">
Expand Down
2 changes: 1 addition & 1 deletion src/WireMock.Net/Http/HttpClientHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ public static async Task<ResponseMessage> 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);
}
}
Expand Down
4 changes: 2 additions & 2 deletions src/WireMock.Net/HttpsCertificate/ClientCertificateHelper.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
using System;
using System.IO;
using System.IO;
using System.Security.Cryptography.X509Certificates;

namespace WireMock.HttpsCertificate
Expand All @@ -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];
}
Expand Down
16 changes: 8 additions & 8 deletions src/WireMock.Net/IMapping.cs
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,14 @@ public interface IMapping
/// </summary>
bool IsStartState { get; }

/// <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>
bool IsAdminInterface { get; }

/// <summary>
/// ResponseToAsync
/// </summary>
Expand All @@ -79,13 +87,5 @@ public interface IMapping
/// <param name="nextState">The Next State.</param>
/// <returns>The <see cref="RequestMatchResult"/>.</returns>
RequestMatchResult GetRequestMatchResult(RequestMessage requestMessage, [CanBeNull] string nextState);

/// <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>
bool IsAdminInterface { get; }
}
}
61 changes: 14 additions & 47 deletions src/WireMock.Net/Mapping.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,55 +14,39 @@ public class Mapping : IMapping
/// <inheritdoc cref="IMapping.Guid" />
public Guid Guid { get; }

/// <summary>
/// Gets the unique title.
/// </summary>
/// <inheritdoc cref="IMapping.Title" />
public string Title { get; }

/// <summary>
/// The full filename path for this mapping (only defined for static mappings).
/// </summary>
/// <inheritdoc cref="IMapping.Path" />
public string Path { get; set; }

/// <summary>
/// Gets the priority.
/// </summary>
/// <inheritdoc cref="IMapping.Priority" />
public int Priority { get; }

/// <summary>
/// Scenario.
/// </summary>
/// <inheritdoc cref="IMapping.Scenario" />
[CanBeNull]
public string Scenario { get; }

/// <summary>
/// Execution state condition for the current mapping.
/// </summary>
/// <inheritdoc cref="IMapping.ExecutionConditionState" />
[CanBeNull]
public string 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>
/// <inheritdoc cref="IMapping.NextState" />
[CanBeNull]
public string NextState { get; }

/// <summary>
/// The Request matcher.
/// </summary>
/// <inheritdoc cref="IMapping.RequestMatcher" />
public IRequestMatcher RequestMatcher { get; }

/// <summary>
/// The Provider.
/// </summary>
/// <inheritdoc cref="IMapping.Provider" />
public IResponseProvider Provider { get; }

/// <summary>
/// Is State started ?
/// </summary>
/// <inheritdoc cref="IMapping.IsStartState" />
public bool IsStartState => Scenario == null || Scenario != null && NextState != null && ExecutionConditionState == null;

/// <inheritdoc cref="IMapping.IsAdminInterface" />
public bool IsAdminInterface => Provider is DynamicResponseProvider || Provider is DynamicAsyncResponseProvider || Provider is ProxyAsyncResponseProvider;

/// <summary>
/// Initializes a new instance of the <see cref="Mapping"/> class.
/// </summary>
Expand All @@ -88,22 +72,13 @@ public Mapping(Guid guid, [CanBeNull] string title, [CanBeNull] string path, IRe
NextState = nextState;
}

/// <summary>
/// The response to.
/// </summary>
/// <param name="requestMessage">The request message.</param>
/// <returns>The <see cref="ResponseMessage"/>.</returns>
/// <inheritdoc cref="IMapping.ResponseToAsync" />
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>
/// <inheritdoc cref="IMapping.GetRequestMatchResult" />
public RequestMatchResult GetRequestMatchResult(RequestMessage requestMessage, [CanBeNull] string nextState)
{
var result = new RequestMatchResult();
Expand All @@ -126,13 +101,5 @@ public RequestMatchResult GetRequestMatchResult(RequestMessage requestMessage, [

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;
}
}

0 comments on commit 04bcca6

Please sign in to comment.