mirror of
https://github.com/wiremock/WireMock.Net.git
synced 2026-01-16 16:36:46 +01:00
Compare commits
1 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
4bfb97b192 |
@@ -62,9 +62,9 @@ namespace WireMock.Server
|
|||||||
void AddGlobalProcessingDelay(TimeSpan delay);
|
void AddGlobalProcessingDelay(TimeSpan delay);
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Allows the partial mapping.
|
/// Set the partial mapping to allowed (if true, you can also provide 'enforceHttpMethod').
|
||||||
/// </summary>
|
/// </summary>
|
||||||
void AllowPartialMapping(bool allow = true);
|
void AllowPartialMapping(bool allow = true, bool enforceHttpMethod = false);
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Deletes a LogEntry.
|
/// Deletes a LogEntry.
|
||||||
|
|||||||
@@ -4,6 +4,7 @@ using WireMock.Handlers;
|
|||||||
using WireMock.Logging;
|
using WireMock.Logging;
|
||||||
using WireMock.Matchers;
|
using WireMock.Matchers;
|
||||||
using WireMock.Util;
|
using WireMock.Util;
|
||||||
|
using WireMock.Settings;
|
||||||
#if !USE_ASPNETCORE
|
#if !USE_ASPNETCORE
|
||||||
using Owin;
|
using Owin;
|
||||||
#else
|
#else
|
||||||
@@ -22,6 +23,8 @@ namespace WireMock.Owin
|
|||||||
|
|
||||||
bool? AllowPartialMapping { get; set; }
|
bool? AllowPartialMapping { get; set; }
|
||||||
|
|
||||||
|
IPartialMappingSettings PartialMappingSettings { get; set; }
|
||||||
|
|
||||||
ConcurrentDictionary<Guid, IMapping> Mappings { get; }
|
ConcurrentDictionary<Guid, IMapping> Mappings { get; }
|
||||||
|
|
||||||
ConcurrentDictionary<string, ScenarioState> Scenarios { get; }
|
ConcurrentDictionary<string, ScenarioState> Scenarios { get; }
|
||||||
|
|||||||
@@ -42,6 +42,16 @@ namespace WireMock.Owin
|
|||||||
.OrderBy(m => m.RequestMatchResult)
|
.OrderBy(m => m.RequestMatchResult)
|
||||||
.ThenBy(m => m.Mapping.Priority)
|
.ThenBy(m => m.Mapping.Priority)
|
||||||
.ToList();
|
.ToList();
|
||||||
|
|
||||||
|
if (_options.PartialMappingSettings?.EnforceHttpMethod == true)
|
||||||
|
{
|
||||||
|
// Check if any partialMappings contain a HttpMethodMatcher, and check if this returns a 0
|
||||||
|
foreach (var partialMapping in partialMappings)
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
var partialMatch = partialMappings.FirstOrDefault(pm => pm.RequestMatchResult.AverageTotalScore > 0.0);
|
var partialMatch = partialMappings.FirstOrDefault(pm => pm.RequestMatchResult.AverageTotalScore > 0.0);
|
||||||
|
|
||||||
if (_options.AllowPartialMapping == true)
|
if (_options.AllowPartialMapping == true)
|
||||||
|
|||||||
@@ -4,6 +4,7 @@ using WireMock.Handlers;
|
|||||||
using WireMock.Logging;
|
using WireMock.Logging;
|
||||||
using WireMock.Matchers;
|
using WireMock.Matchers;
|
||||||
using WireMock.Util;
|
using WireMock.Util;
|
||||||
|
using WireMock.Settings;
|
||||||
#if !USE_ASPNETCORE
|
#if !USE_ASPNETCORE
|
||||||
using Owin;
|
using Owin;
|
||||||
#else
|
#else
|
||||||
@@ -22,6 +23,8 @@ namespace WireMock.Owin
|
|||||||
|
|
||||||
public bool? AllowPartialMapping { get; set; }
|
public bool? AllowPartialMapping { get; set; }
|
||||||
|
|
||||||
|
public IPartialMappingSettings PartialMappingSettings { get; set; }
|
||||||
|
|
||||||
public ConcurrentDictionary<Guid, IMapping> Mappings { get; } = new ConcurrentDictionary<Guid, IMapping>();
|
public ConcurrentDictionary<Guid, IMapping> Mappings { get; } = new ConcurrentDictionary<Guid, IMapping>();
|
||||||
|
|
||||||
public ConcurrentDictionary<string, ScenarioState> Scenarios { get; } = new ConcurrentDictionary<string, ScenarioState>();
|
public ConcurrentDictionary<string, ScenarioState> Scenarios { get; } = new ConcurrentDictionary<string, ScenarioState>();
|
||||||
|
|||||||
@@ -367,6 +367,7 @@ namespace WireMock.Server
|
|||||||
if (settings.AllowPartialMapping != null)
|
if (settings.AllowPartialMapping != null)
|
||||||
{
|
{
|
||||||
_options.AllowPartialMapping = settings.AllowPartialMapping.Value;
|
_options.AllowPartialMapping = settings.AllowPartialMapping.Value;
|
||||||
|
// TODO stef _options.PartialMappingSettings = settings.
|
||||||
}
|
}
|
||||||
|
|
||||||
if (settings.GlobalProcessingDelay != null)
|
if (settings.GlobalProcessingDelay != null)
|
||||||
|
|||||||
@@ -283,7 +283,7 @@ namespace WireMock.Server
|
|||||||
|
|
||||||
if (settings.AllowPartialMapping == true)
|
if (settings.AllowPartialMapping == true)
|
||||||
{
|
{
|
||||||
AllowPartialMapping();
|
AllowPartialMapping(true, settings.PartialMappingSettings);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (settings.StartAdminInterface == true)
|
if (settings.StartAdminInterface == true)
|
||||||
@@ -389,10 +389,21 @@ namespace WireMock.Server
|
|||||||
|
|
||||||
/// <inheritdoc cref="IWireMockServer.AllowPartialMapping" />
|
/// <inheritdoc cref="IWireMockServer.AllowPartialMapping" />
|
||||||
[PublicAPI]
|
[PublicAPI]
|
||||||
public void AllowPartialMapping(bool allow = true)
|
public void AllowPartialMapping(bool allow = true, bool enforceHttpMethod = false)
|
||||||
|
{
|
||||||
|
AllowPartialMapping(allow, new PartialMappingSettings
|
||||||
|
{
|
||||||
|
EnforceHttpMethod = enforceHttpMethod
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <inheritdoc cref="IWireMockServer.AllowPartialMapping" />
|
||||||
|
[PublicAPI]
|
||||||
|
public void AllowPartialMapping(bool allow = true, IPartialMappingSettings partialMappingSettings = null)
|
||||||
{
|
{
|
||||||
_settings.Logger.Info("AllowPartialMapping is set to {0}", allow);
|
_settings.Logger.Info("AllowPartialMapping is set to {0}", allow);
|
||||||
_options.AllowPartialMapping = allow;
|
_options.AllowPartialMapping = allow;
|
||||||
|
_options.PartialMappingSettings = partialMappingSettings;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <inheritdoc cref="IWireMockServer.SetBasicAuthentication" />
|
/// <inheritdoc cref="IWireMockServer.SetBasicAuthentication" />
|
||||||
|
|||||||
13
src/WireMock.Net/Settings/IPartialMappingSettings.cs
Normal file
13
src/WireMock.Net/Settings/IPartialMappingSettings.cs
Normal file
@@ -0,0 +1,13 @@
|
|||||||
|
namespace WireMock.Settings
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// IPartialMappingSettings
|
||||||
|
/// </summary>
|
||||||
|
public interface IPartialMappingSettings
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// ...
|
||||||
|
/// </summary>
|
||||||
|
bool EnforceHttpMethod { get; set; }
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -73,6 +73,12 @@ namespace WireMock.Settings
|
|||||||
[PublicAPI]
|
[PublicAPI]
|
||||||
bool? AllowPartialMapping { get; set; }
|
bool? AllowPartialMapping { get; set; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Gets or sets the partial mapping settings (optional).
|
||||||
|
/// </summary>
|
||||||
|
[PublicAPI]
|
||||||
|
IPartialMappingSettings PartialMappingSettings { get; set; }
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// The username needed for __admin access.
|
/// The username needed for __admin access.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
|||||||
15
src/WireMock.Net/Settings/PartialMappingSettings.cs
Normal file
15
src/WireMock.Net/Settings/PartialMappingSettings.cs
Normal file
@@ -0,0 +1,15 @@
|
|||||||
|
using JetBrains.Annotations;
|
||||||
|
|
||||||
|
namespace WireMock.Settings
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// PartialMappingSettings
|
||||||
|
/// </summary>
|
||||||
|
/// <seealso cref="IPartialMappingSettings" />
|
||||||
|
public class PartialMappingSettings : IPartialMappingSettings
|
||||||
|
{
|
||||||
|
/// <inheritdoc cref="IPartialMappingSettings.EnforceHttpMethod"/>
|
||||||
|
[PublicAPI]
|
||||||
|
public bool EnforceHttpMethod { get; set; }
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -53,6 +53,10 @@ namespace WireMock.Settings
|
|||||||
[PublicAPI]
|
[PublicAPI]
|
||||||
public bool? AllowPartialMapping { get; set; }
|
public bool? AllowPartialMapping { get; set; }
|
||||||
|
|
||||||
|
/// <inheritdoc cref="IWireMockServerSettings.PartialMappingSettings"/>
|
||||||
|
[PublicAPI]
|
||||||
|
public IPartialMappingSettings PartialMappingSettings { get; set; }
|
||||||
|
|
||||||
/// <inheritdoc cref="IWireMockServerSettings.AdminUsername"/>
|
/// <inheritdoc cref="IWireMockServerSettings.AdminUsername"/>
|
||||||
[PublicAPI]
|
[PublicAPI]
|
||||||
public string AdminUsername { get; set; }
|
public string AdminUsername { get; set; }
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
using NFluent;
|
using System.Collections.Generic;
|
||||||
using System.Collections.Generic;
|
using FluentAssertions;
|
||||||
|
using NFluent;
|
||||||
using WireMock.Matchers.Request;
|
using WireMock.Matchers.Request;
|
||||||
using WireMock.Models;
|
using WireMock.Models;
|
||||||
using WireMock.RequestBuilders;
|
using WireMock.RequestBuilders;
|
||||||
@@ -13,6 +14,34 @@ namespace WireMock.Net.Tests
|
|||||||
{
|
{
|
||||||
private const string ClientIp = "::1";
|
private const string ClientIp = "::1";
|
||||||
|
|
||||||
|
[Fact]
|
||||||
|
public void Should_Match_When_Verb_Does_Match()
|
||||||
|
{
|
||||||
|
// Arrange
|
||||||
|
var requestPut = Request.Create().WithPath("/bar").UsingPut();
|
||||||
|
|
||||||
|
// Act
|
||||||
|
var request = new RequestMessage(new UrlDetails("http://localhost/bar"), "PUT", ClientIp);
|
||||||
|
|
||||||
|
// Assert
|
||||||
|
var requestMatchResult = new RequestMatchResult();
|
||||||
|
requestPut.GetMatchingScore(request, requestMatchResult).Should().Be(1.0);
|
||||||
|
}
|
||||||
|
|
||||||
|
[Fact]
|
||||||
|
public void Should_NotMatch_When_Verb_Does_Not_Match()
|
||||||
|
{
|
||||||
|
// Arrange
|
||||||
|
var requestGet = Request.Create().WithPath("/bar").UsingGet();
|
||||||
|
|
||||||
|
// Act
|
||||||
|
var request = new RequestMessage(new UrlDetails("http://localhost/bar"), "PUT", ClientIp);
|
||||||
|
|
||||||
|
// Assert
|
||||||
|
var requestMatchResult = new RequestMatchResult();
|
||||||
|
requestGet.GetMatchingScore(request, requestMatchResult).Should().Be(0.0);
|
||||||
|
}
|
||||||
|
|
||||||
[Fact]
|
[Fact]
|
||||||
public void Should_exclude_requests_matching_given_http_method_but_not_url()
|
public void Should_exclude_requests_matching_given_http_method_but_not_url()
|
||||||
{
|
{
|
||||||
|
|||||||
Reference in New Issue
Block a user