mirror of
https://github.com/wiremock/WireMock.Net.git
synced 2026-02-22 16:58:06 +01:00
Compare commits
7 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
c4ee91c614 | ||
|
|
4d0373d4ca | ||
|
|
6c27820659 | ||
|
|
9a532108b8 | ||
|
|
9491280fd2 | ||
|
|
da62a43875 | ||
|
|
197f96e303 |
11
CHANGELOG.md
11
CHANGELOG.md
@@ -1,3 +1,14 @@
|
||||
# 1.2.17 (01 August 2020)
|
||||
- [#495](https://github.com/WireMock-Net/WireMock.Net/pull/495) - Scenario : stay on current state for a number of times contributed by [StefH](https://github.com/StefH)
|
||||
- [#494](https://github.com/WireMock-Net/WireMock.Net/issues/494) - Stay in Current State for specified number of requests [feature]
|
||||
|
||||
# 1.2.16 (27 July 2020)
|
||||
- [#492](https://github.com/WireMock-Net/WireMock.Net/pull/492) - Mark FluentMockServer, FluentMockServerSettings, BlacklistedHeaders and BlacklistedCookies as obsolete [feature] contributed by [StefH](https://github.com/StefH)
|
||||
- [#489](https://github.com/WireMock-Net/WireMock.Net/issues/489) - Change "blacklist" and "whitelist" terms [feature]
|
||||
|
||||
# 1.2.15 (19 July 2020)
|
||||
- [#485](https://github.com/WireMock-Net/WireMock.Net/pull/485) - Add fluent assertions for headers [test] contributed by [akamud](https://github.com/akamud)
|
||||
|
||||
# 1.2.14 (09 July 2020)
|
||||
- [#479](https://github.com/WireMock-Net/WireMock.Net/pull/479) - An OpenApi (swagger) parser to generate MappingModel or mapping.json file [feature] contributed by [StefH](https://github.com/StefH)
|
||||
- [#482](https://github.com/WireMock-Net/WireMock.Net/pull/482) - Add PartialMatch to logging / logentries [feature] contributed by [StefH](https://github.com/StefH)
|
||||
|
||||
@@ -4,7 +4,7 @@
|
||||
</PropertyGroup>
|
||||
|
||||
<PropertyGroup>
|
||||
<VersionPrefix>1.2.14</VersionPrefix>
|
||||
<VersionPrefix>1.2.17</VersionPrefix>
|
||||
<PackageReleaseNotes>See CHANGELOG.md</PackageReleaseNotes>
|
||||
<PackageIconUrl>https://raw.githubusercontent.com/WireMock-Net/WireMock.Net/master/WireMock.Net-Logo.png</PackageIconUrl>
|
||||
<PackageProjectUrl>https://github.com/WireMock-Net/WireMock.Net</PackageProjectUrl>
|
||||
|
||||
@@ -1,3 +1,3 @@
|
||||
https://github.com/StefH/GitHubReleaseNotes
|
||||
|
||||
GitHubReleaseNotes.exe --output CHANGELOG.md --skip-empty-releases --exclude-labels question invalid doc --version 1.2.14
|
||||
GitHubReleaseNotes.exe --output CHANGELOG.md --skip-empty-releases --exclude-labels question invalid doc --version 1.2.17
|
||||
@@ -24,5 +24,10 @@
|
||||
/// Gets or sets a value indicating whether this <see cref="ScenarioStateModel"/> is finished.
|
||||
/// </summary>
|
||||
public bool Finished { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the state counter.
|
||||
/// </summary>
|
||||
public int Counter { get; set; }
|
||||
}
|
||||
}
|
||||
@@ -27,9 +27,9 @@ namespace WireMock.Server
|
||||
/// </summary>
|
||||
IEnumerable<MappingModel> MappingModels { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets the mappings.
|
||||
/// </summary>
|
||||
// <summary>
|
||||
// Gets the mappings.
|
||||
// </summary>
|
||||
//[PublicAPI]
|
||||
//IEnumerable<IMapping> Mappings { get; }
|
||||
|
||||
|
||||
@@ -8,19 +8,20 @@ namespace WireMock.FluentAssertions
|
||||
{
|
||||
public class WireMockAssertions
|
||||
{
|
||||
private readonly IWireMockServer _instance;
|
||||
private readonly IWireMockServer _subject;
|
||||
|
||||
public WireMockAssertions(IWireMockServer instance, int? callsCount)
|
||||
public WireMockAssertions(IWireMockServer subject, int? callsCount)
|
||||
{
|
||||
_instance = instance;
|
||||
_subject = subject;
|
||||
}
|
||||
|
||||
[CustomAssertion]
|
||||
public AndConstraint<WireMockAssertions> AtAbsoluteUrl(string absoluteUrl, string because = "", params object[] becauseArgs)
|
||||
public AndConstraint<WireMockAssertions> AtAbsoluteUrl(string absoluteUrl, string because = "",
|
||||
params object[] becauseArgs)
|
||||
{
|
||||
Execute.Assertion
|
||||
.BecauseOf(because, becauseArgs)
|
||||
.Given(() => _instance.LogEntries.Select(x => x.RequestMessage).ToList())
|
||||
.Given(() => _subject.LogEntries.Select(x => x.RequestMessage).ToList())
|
||||
.ForCondition(requests => requests.Any())
|
||||
.FailWith(
|
||||
"Expected {context:wiremockserver} to have been called at address matching the absolute url {0}{reason}, but no calls were made.",
|
||||
@@ -33,5 +34,43 @@ namespace WireMock.FluentAssertions
|
||||
|
||||
return new AndConstraint<WireMockAssertions>(this);
|
||||
}
|
||||
|
||||
[CustomAssertion]
|
||||
public AndConstraint<WireMockAssertions> WithHeader(string expectedKey, string value,
|
||||
string because = "", params object[] becauseArgs)
|
||||
=> WithHeader(expectedKey, new[] {value}, because, becauseArgs);
|
||||
|
||||
[CustomAssertion]
|
||||
public AndConstraint<WireMockAssertions> WithHeader(string expectedKey, string[] expectedValues,
|
||||
string because = "", params object[] becauseArgs)
|
||||
{
|
||||
var headersDictionary = _subject.LogEntries.SelectMany(x => x.RequestMessage.Headers)
|
||||
.ToDictionary(x => x.Key, x => x.Value);
|
||||
|
||||
using (new AssertionScope("headers from requests sent"))
|
||||
{
|
||||
headersDictionary.Should().ContainKey(expectedKey, because, becauseArgs);
|
||||
}
|
||||
|
||||
using (new AssertionScope($"header \"{expectedKey}\" from requests sent with value(s)"))
|
||||
{
|
||||
if (expectedValues.Length == 1)
|
||||
{
|
||||
headersDictionary[expectedKey].Should().Contain(expectedValues.First());
|
||||
}
|
||||
else
|
||||
{
|
||||
var trimmedHeaderValues = string.Join(",", headersDictionary[expectedKey].Select(x => x)).Split(',')
|
||||
.Select(x => x.Trim())
|
||||
.ToList();
|
||||
foreach (var expectedValue in expectedValues)
|
||||
{
|
||||
trimmedHeaderValues.Should().Contain(expectedValue);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return new AndConstraint<WireMockAssertions>(this);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,37 +1,36 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
|
||||
<PropertyGroup>
|
||||
<Description>An OpenApi (swagger) parser to generate MappingModel or mapping.json file.</Description>
|
||||
<!--<VersionPrefix>1.2.4-preview-01</VersionPrefix>-->
|
||||
<TargetFrameworks>net46;netstandard2.0</TargetFrameworks>
|
||||
<GenerateDocumentationFile>true</GenerateDocumentationFile>
|
||||
<PackageTags>wiremock;openapi;OAS;converter;parser;openapiparser</PackageTags>
|
||||
<ProjectGuid>{D3804228-91F4-4502-9595-39584E5AADAD}</ProjectGuid>
|
||||
<PublishRepositoryUrl>true</PublishRepositoryUrl>
|
||||
<CodeAnalysisRuleSet>../WireMock.Net/WireMock.Net.ruleset</CodeAnalysisRuleSet>
|
||||
<SignAssembly>true</SignAssembly>
|
||||
<AssemblyOriginatorKeyFile>../WireMock.Net/WireMock.Net.snk</AssemblyOriginatorKeyFile>
|
||||
<PublicSign Condition=" '$(OS)' != 'Windows_NT' ">true</PublicSign>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup>
|
||||
<Description>An OpenApi (swagger) parser to generate MappingModel or mapping.json file.</Description>
|
||||
<TargetFrameworks>net46;netstandard2.0</TargetFrameworks>
|
||||
<GenerateDocumentationFile>true</GenerateDocumentationFile>
|
||||
<PackageTags>wiremock;openapi;OAS;converter;parser;openapiparser</PackageTags>
|
||||
<ProjectGuid>{D3804228-91F4-4502-9595-39584E5AADAD}</ProjectGuid>
|
||||
<PublishRepositoryUrl>true</PublishRepositoryUrl>
|
||||
<CodeAnalysisRuleSet>../WireMock.Net/WireMock.Net.ruleset</CodeAnalysisRuleSet>
|
||||
<SignAssembly>true</SignAssembly>
|
||||
<AssemblyOriginatorKeyFile>../WireMock.Net/WireMock.Net.snk</AssemblyOriginatorKeyFile>
|
||||
<PublicSign Condition=" '$(OS)' != 'Windows_NT' ">true</PublicSign>
|
||||
</PropertyGroup>
|
||||
|
||||
<PropertyGroup Condition="'$(Configuration)' == 'Release'">
|
||||
<GeneratePackageOnBuild>true</GeneratePackageOnBuild>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition="'$(Configuration)' == 'Release'">
|
||||
<GeneratePackageOnBuild>true</GeneratePackageOnBuild>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="Newtonsoft.Json" Version="11.0.2" />
|
||||
<PackageReference Include="Microsoft.OpenApi.Readers" Version="1.2.0" />
|
||||
<PackageReference Include="RamlToOpenApiConverter" Version="0.1.1" />
|
||||
<PackageReference Include="JetBrains.Annotations" Version="2020.1.0" PrivateAssets="All" />
|
||||
<PackageReference Include="Microsoft.SourceLink.GitHub" Version="1.0.0" PrivateAssets="All" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<PackageReference Include="Newtonsoft.Json" Version="11.0.2" />
|
||||
<PackageReference Include="Microsoft.OpenApi.Readers" Version="1.2.0" />
|
||||
<PackageReference Include="RamlToOpenApiConverter" Version="0.1.1" />
|
||||
<PackageReference Include="JetBrains.Annotations" Version="2020.1.0" PrivateAssets="All" />
|
||||
<PackageReference Include="Microsoft.SourceLink.GitHub" Version="1.0.0" PrivateAssets="All" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\WireMock.Net.Abstractions\WireMock.Net.Abstractions.csproj" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\WireMock.Net.Abstractions\WireMock.Net.Abstractions.csproj" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<Folder Include="Options\" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Folder Include="Options\" />
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
||||
@@ -13,9 +13,9 @@ namespace WireMock.Net.StandAlone
|
||||
public static class StandAloneApp
|
||||
{
|
||||
/// <summary>
|
||||
/// Start WireMock.Net standalone Server based on the FluentMockServerSettings.
|
||||
/// Start WireMock.Net standalone Server based on the IWireMockServerSettings.
|
||||
/// </summary>
|
||||
/// <param name="settings">The FluentMockServerSettings</param>
|
||||
/// <param name="settings">The IWireMockServerSettings</param>
|
||||
[PublicAPI]
|
||||
public static WireMockServer Start([NotNull] IWireMockServerSettings settings)
|
||||
{
|
||||
|
||||
@@ -51,6 +51,12 @@ namespace WireMock
|
||||
[CanBeNull]
|
||||
string NextState { get; }
|
||||
|
||||
/// <summary>
|
||||
/// The number of times this match should be matched before the state will be changed to the next state.
|
||||
/// </summary>
|
||||
[CanBeNull]
|
||||
int? StateTimes { get; }
|
||||
|
||||
/// <summary>
|
||||
/// The Request matcher.
|
||||
/// </summary>
|
||||
|
||||
@@ -33,6 +33,9 @@ namespace WireMock
|
||||
/// <inheritdoc cref="IMapping.NextState" />
|
||||
public string NextState { get; }
|
||||
|
||||
/// <inheritdoc cref="IMapping.StateTimes" />
|
||||
public int? StateTimes { get; }
|
||||
|
||||
/// <inheritdoc cref="IMapping.RequestMatcher" />
|
||||
public IRequestMatcher RequestMatcher { get; }
|
||||
|
||||
@@ -64,9 +67,10 @@ namespace WireMock
|
||||
/// <param name="scenario">The scenario. [Optional]</param>
|
||||
/// <param name="executionConditionState">State in which the current mapping can occur. [Optional]</param>
|
||||
/// <param name="nextState">The next state which will occur after the current mapping execution. [Optional]</param>
|
||||
/// <param name="stateTimes">Only when the current state is executed this number, the next state which will occur. [Optional]</param>
|
||||
public Mapping(Guid guid, [CanBeNull] string title, [CanBeNull] string path,
|
||||
[NotNull] IWireMockServerSettings settings, [NotNull] IRequestMatcher requestMatcher, [NotNull] IResponseProvider provider,
|
||||
int priority, [CanBeNull] string scenario, [CanBeNull] string executionConditionState, [CanBeNull] string nextState)
|
||||
int priority, [CanBeNull] string scenario, [CanBeNull] string executionConditionState, [CanBeNull] string nextState, [CanBeNull] int? stateTimes)
|
||||
{
|
||||
Guid = guid;
|
||||
Title = title;
|
||||
@@ -78,6 +82,7 @@ namespace WireMock
|
||||
Scenario = scenario;
|
||||
ExecutionConditionState = executionConditionState;
|
||||
NextState = nextState;
|
||||
StateTimes = stateTimes;
|
||||
}
|
||||
|
||||
/// <inheritdoc cref="IMapping.ProvideResponseAsync" />
|
||||
|
||||
@@ -23,12 +23,12 @@ namespace WireMock.Owin
|
||||
{
|
||||
try
|
||||
{
|
||||
string scenario = mapping.Scenario != null && _options.Scenarios.ContainsKey(mapping.Scenario) ? _options.Scenarios[mapping.Scenario].NextState : null;
|
||||
string nextState = GetNextState(mapping);
|
||||
|
||||
mappings.Add(new MappingMatcherResult
|
||||
{
|
||||
Mapping = mapping,
|
||||
RequestMatchResult = mapping.GetRequestMatchResult(request, scenario)
|
||||
RequestMatchResult = mapping.GetRequestMatchResult(request, nextState)
|
||||
});
|
||||
}
|
||||
catch (Exception ex)
|
||||
@@ -56,5 +56,18 @@ namespace WireMock.Owin
|
||||
|
||||
return (match, partialMatch);
|
||||
}
|
||||
|
||||
private string GetNextState(IMapping mapping)
|
||||
{
|
||||
// If the mapping does not have a scenario or _options.Scenarios does not contain this scenario from the mapping,
|
||||
// just return null to indicate that there is no next state.
|
||||
if (mapping.Scenario == null || !_options.Scenarios.ContainsKey(mapping.Scenario))
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
// Else just return the next state
|
||||
return _options.Scenarios[mapping.Scenario].NextState;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -79,7 +79,7 @@ namespace WireMock.Owin
|
||||
{
|
||||
foreach (var mapping in _options.Mappings.Values.Where(m => m?.Scenario != null))
|
||||
{
|
||||
// Set start
|
||||
// Set scenario start
|
||||
if (!_options.Scenarios.ContainsKey(mapping.Scenario) && mapping.IsStartState)
|
||||
{
|
||||
_options.Scenarios.TryAdd(mapping.Scenario, new ScenarioState
|
||||
@@ -122,9 +122,7 @@ namespace WireMock.Owin
|
||||
|
||||
if (targetMapping.Scenario != null)
|
||||
{
|
||||
_options.Scenarios[targetMapping.Scenario].NextState = targetMapping.NextState;
|
||||
_options.Scenarios[targetMapping.Scenario].Started = true;
|
||||
_options.Scenarios[targetMapping.Scenario].Finished = targetMapping.NextState == null;
|
||||
UpdateScenarioState(targetMapping);
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
@@ -157,6 +155,25 @@ namespace WireMock.Owin
|
||||
await CompletedTask;
|
||||
}
|
||||
|
||||
private void UpdateScenarioState(IMapping mapping)
|
||||
{
|
||||
var scenario = _options.Scenarios[mapping.Scenario];
|
||||
|
||||
// Increase the number of times this state has been executed
|
||||
scenario.Counter++;
|
||||
|
||||
// Only if the number of times this state is executed equals the required StateTimes, proceed to next state and reset the counter to 0
|
||||
if (scenario.Counter == (mapping.StateTimes ?? 1))
|
||||
{
|
||||
scenario.NextState = mapping.NextState;
|
||||
scenario.Counter = 0;
|
||||
}
|
||||
|
||||
// Else just update Started and Finished
|
||||
scenario.Started = true;
|
||||
scenario.Finished = mapping.NextState == null;
|
||||
}
|
||||
|
||||
private void LogRequest(LogEntry entry, bool addRequest)
|
||||
{
|
||||
_options.Logger.DebugRequestResponse(LogEntryMapper.Map(entry), entry.RequestMessage.Path.StartsWith("/__admin/"));
|
||||
|
||||
@@ -24,5 +24,10 @@
|
||||
/// Gets or sets a value indicating whether this <see cref="ScenarioState"/> is finished.
|
||||
/// </summary>
|
||||
public bool Finished { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the state counter.
|
||||
/// </summary>
|
||||
public int Counter { get; set; }
|
||||
}
|
||||
}
|
||||
@@ -1,7 +1,9 @@
|
||||
using WireMock.Settings;
|
||||
using System;
|
||||
using WireMock.Settings;
|
||||
|
||||
namespace WireMock.Server
|
||||
{
|
||||
[Obsolete("Use WireMockServer. This will removed in next version (1.3.x)")]
|
||||
public class FluentMockServer : WireMockServer
|
||||
{
|
||||
public FluentMockServer(IFluentMockServerSettings settings) : base((IWireMockServerSettings) settings)
|
||||
|
||||
@@ -86,14 +86,16 @@ namespace WireMock.Server
|
||||
/// Once this mapping is executed the state will be changed to specified one.
|
||||
/// </summary>
|
||||
/// <param name="state">Any object which identifies the new state</param>
|
||||
/// <param name="times">The number of times this match should be matched before the state will be changed to the specified one. Default value is 1.</param>
|
||||
/// <returns>The <see cref="IRespondWithAProvider"/>.</returns>
|
||||
IRespondWithAProvider WillSetStateTo(string state);
|
||||
IRespondWithAProvider WillSetStateTo(string state, int? times = 1);
|
||||
|
||||
/// <summary>
|
||||
/// Once this mapping is executed the state will be changed to specified one.
|
||||
/// </summary>
|
||||
/// <param name="state">Any object which identifies the new state</param>
|
||||
/// <param name="times">The number of times this match should be matched before the state will be changed to the specified one. Default value is 1.</param>
|
||||
/// <returns>The <see cref="IRespondWithAProvider"/>.</returns>
|
||||
IRespondWithAProvider WillSetStateTo(int state);
|
||||
IRespondWithAProvider WillSetStateTo(int state, int? times = 1);
|
||||
}
|
||||
}
|
||||
@@ -18,6 +18,7 @@ namespace WireMock.Server
|
||||
private string _executionConditionState;
|
||||
private string _nextState;
|
||||
private string _scenario;
|
||||
private int _timesInSameState = 1;
|
||||
private readonly RegistrationCallback _registrationCallback;
|
||||
private readonly IRequestMatcher _requestMatcher;
|
||||
private readonly IWireMockServerSettings _settings;
|
||||
@@ -46,7 +47,7 @@ namespace WireMock.Server
|
||||
/// <param name="provider">The provider.</param>
|
||||
public void RespondWith(IResponseProvider provider)
|
||||
{
|
||||
_registrationCallback(new Mapping(Guid, _title, _path, _settings, _requestMatcher, provider, _priority, _scenario, _executionConditionState, _nextState), _saveToFile);
|
||||
_registrationCallback(new Mapping(Guid, _title, _path, _settings, _requestMatcher, provider, _priority, _scenario, _executionConditionState, _nextState, _timesInSameState), _saveToFile);
|
||||
}
|
||||
|
||||
/// <see cref="IRespondWithAProvider.WithGuid(string)"/>
|
||||
@@ -120,8 +121,8 @@ namespace WireMock.Server
|
||||
return WhenStateIs(state.ToString());
|
||||
}
|
||||
|
||||
/// <see cref="IRespondWithAProvider.WillSetStateTo(string)"/>
|
||||
public IRespondWithAProvider WillSetStateTo(string state)
|
||||
/// <see cref="IRespondWithAProvider.WillSetStateTo(string, int?)"/>
|
||||
public IRespondWithAProvider WillSetStateTo(string state, int? times = 1)
|
||||
{
|
||||
if (string.IsNullOrEmpty(_scenario))
|
||||
{
|
||||
@@ -129,14 +130,15 @@ namespace WireMock.Server
|
||||
}
|
||||
|
||||
_nextState = state;
|
||||
_timesInSameState = times ?? 1;
|
||||
|
||||
return this;
|
||||
}
|
||||
|
||||
/// <see cref="IRespondWithAProvider.WillSetStateTo(int)"/>
|
||||
public IRespondWithAProvider WillSetStateTo(int state)
|
||||
/// <see cref="IRespondWithAProvider.WillSetStateTo(int, int?)"/>
|
||||
public IRespondWithAProvider WillSetStateTo(int state, int? times = 1)
|
||||
{
|
||||
return WillSetStateTo(state.ToString());
|
||||
return WillSetStateTo(state.ToString(), times);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -290,7 +290,7 @@ namespace WireMock.Server
|
||||
return responseMessage;
|
||||
}
|
||||
|
||||
private IMapping ToMapping(RequestMessage requestMessage, ResponseMessage responseMessage, string[] blacklistedHeaders, string[] blacklistedCookies)
|
||||
private IMapping ToMapping(RequestMessage requestMessage, ResponseMessage responseMessage, string[] excludedHeaders, string[] excludedCookies)
|
||||
{
|
||||
var request = Request.Create();
|
||||
request.WithPath(requestMessage.Path);
|
||||
@@ -299,16 +299,16 @@ namespace WireMock.Server
|
||||
requestMessage.Query.Loop((key, value) => request.WithParam(key, false, value.ToArray()));
|
||||
requestMessage.Cookies.Loop((key, value) =>
|
||||
{
|
||||
if (!blacklistedCookies.Contains(key, StringComparer.OrdinalIgnoreCase))
|
||||
if (!excludedCookies.Contains(key, StringComparer.OrdinalIgnoreCase))
|
||||
{
|
||||
request.WithCookie(key, value);
|
||||
}
|
||||
});
|
||||
|
||||
var allBlackListedHeaders = new List<string>(blacklistedHeaders) { "Cookie" };
|
||||
var allExcludedHeaders = new List<string>(excludedHeaders) { "Cookie" };
|
||||
requestMessage.Headers.Loop((key, value) =>
|
||||
{
|
||||
if (!allBlackListedHeaders.Contains(key, StringComparer.OrdinalIgnoreCase))
|
||||
if (!allExcludedHeaders.Contains(key, StringComparer.OrdinalIgnoreCase))
|
||||
{
|
||||
request.WithHeader(key, value.ToArray());
|
||||
}
|
||||
@@ -331,7 +331,7 @@ namespace WireMock.Server
|
||||
|
||||
var response = Response.Create(responseMessage);
|
||||
|
||||
return new Mapping(Guid.NewGuid(), string.Empty, null, _settings, request, response, 0, null, null, null);
|
||||
return new Mapping(Guid.NewGuid(), string.Empty, null, _settings, request, response, 0, null, null, null, null);
|
||||
}
|
||||
#endregion
|
||||
|
||||
@@ -706,7 +706,8 @@ namespace WireMock.Server
|
||||
Name = s.Name,
|
||||
NextState = s.NextState,
|
||||
Started = s.Started,
|
||||
Finished = s.Finished
|
||||
Finished = s.Finished,
|
||||
Counter = s.Counter
|
||||
});
|
||||
|
||||
return ToJson(scenariosStates, true);
|
||||
|
||||
@@ -1,8 +1,11 @@
|
||||
namespace WireMock.Settings
|
||||
using System;
|
||||
|
||||
namespace WireMock.Settings
|
||||
{
|
||||
/// <summary>
|
||||
/// FluentMockServerSettings
|
||||
/// </summary>
|
||||
[Obsolete("Use WireMockServerSettings. This will removed in next version (1.3.x)")]
|
||||
public class FluentMockServerSettings : WireMockServerSettings
|
||||
{
|
||||
}
|
||||
|
||||
@@ -1,8 +1,11 @@
|
||||
namespace WireMock.Settings
|
||||
using System;
|
||||
|
||||
namespace WireMock.Settings
|
||||
{
|
||||
/// <summary>
|
||||
/// IFluentMockServerSettings
|
||||
/// </summary>
|
||||
[Obsolete("Use IWireMockServerSettings. This will removed in next version (1.3.x)")]
|
||||
public interface IFluentMockServerSettings : IWireMockServerSettings
|
||||
{
|
||||
}
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
using JetBrains.Annotations;
|
||||
using System;
|
||||
using JetBrains.Annotations;
|
||||
|
||||
namespace WireMock.Settings
|
||||
{
|
||||
@@ -36,13 +37,15 @@ namespace WireMock.Settings
|
||||
string ClientX509Certificate2ThumbprintOrSubjectName { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Defines a list from headers which will excluded from the saved mappings.
|
||||
/// Defines a list from headers which will be excluded from the saved mappings.
|
||||
/// </summary>
|
||||
[Obsolete("Will be renamed to ExcludedHeaders in next version (1.3.x)")]
|
||||
string[] BlackListedHeaders { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Defines a list of cookies which will excluded from the saved mappings.
|
||||
/// Defines a list of cookies which will be excluded from the saved mappings.
|
||||
/// </summary>
|
||||
[Obsolete("Will be renamed to ExcludedCookies in next version (1.3.x)")]
|
||||
string[] BlackListedCookies { get; set; }
|
||||
|
||||
/// <summary>
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
using JetBrains.Annotations;
|
||||
using System;
|
||||
using JetBrains.Annotations;
|
||||
|
||||
namespace WireMock.Settings
|
||||
{
|
||||
@@ -39,16 +40,14 @@ namespace WireMock.Settings
|
||||
[PublicAPI]
|
||||
public string ClientX509Certificate2ThumbprintOrSubjectName { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Defines a list from headers which will excluded from the saved mappings.
|
||||
/// </summary>
|
||||
/// <inheritdoc cref="IProxyAndRecordSettings.BlackListedHeaders"/>
|
||||
[PublicAPI]
|
||||
[Obsolete("Will be renamed to ExcludedHeaders in next version (1.3.x)")]
|
||||
public string[] BlackListedHeaders { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Defines a list of cookies which will excluded from the saved mappings.
|
||||
/// </summary>
|
||||
/// <inheritdoc cref="IProxyAndRecordSettings.BlackListedCookies"/>
|
||||
[PublicAPI]
|
||||
[Obsolete("Will be renamed to ExcludedCookies in next version (1.3.x)")]
|
||||
public string[] BlackListedCookies { get; set; }
|
||||
|
||||
/// <inheritdoc cref="IProxyAndRecordSettings.WebProxySettings"/>
|
||||
|
||||
@@ -1,12 +1,15 @@
|
||||
using FluentAssertions;
|
||||
using System;
|
||||
using System.Linq;
|
||||
using System.Net.Http;
|
||||
using System.Net.Http.Headers;
|
||||
using WireMock.RequestBuilders;
|
||||
using WireMock.ResponseBuilders;
|
||||
using WireMock.Server;
|
||||
using Xunit;
|
||||
using WireMock.FluentAssertions;
|
||||
using System.Threading.Tasks;
|
||||
using static System.Environment;
|
||||
|
||||
namespace WireMock.Net.Tests.FluentAssertions
|
||||
{
|
||||
@@ -14,15 +17,26 @@ namespace WireMock.Net.Tests.FluentAssertions
|
||||
{
|
||||
private WireMockServer _server;
|
||||
private HttpClient _httpClient;
|
||||
private const int Port = 42000;
|
||||
private int _portUsed;
|
||||
|
||||
public WireMockAssertionsTests()
|
||||
{
|
||||
_server = WireMockServer.Start(Port);
|
||||
_server = WireMockServer.Start();
|
||||
_server.Given(Request.Create().UsingAnyMethod())
|
||||
.RespondWith(Response.Create().WithStatusCode(200));
|
||||
.RespondWith(Response.Create().WithStatusCode(200));
|
||||
_portUsed = _server.Ports.First();
|
||||
|
||||
_httpClient = new HttpClient { BaseAddress = new Uri($"http://localhost:{Port}") };
|
||||
_httpClient = new HttpClient { BaseAddress = new Uri($"http://localhost:{_portUsed}") };
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task AtAbsoluteUrl_WhenACallWasMadeToAbsoluteUrl_Should_BeOK()
|
||||
{
|
||||
await _httpClient.GetAsync("anyurl");
|
||||
|
||||
_server.Should()
|
||||
.HaveReceivedACall()
|
||||
.AtAbsoluteUrl($"http://localhost:{_portUsed}/anyurl");
|
||||
}
|
||||
|
||||
[Fact]
|
||||
@@ -50,7 +64,96 @@ namespace WireMock.Net.Tests.FluentAssertions
|
||||
act.Should().Throw<Exception>()
|
||||
.And.Message.Should()
|
||||
.Be(
|
||||
$"Expected _server to have been called at address matching the absolute url \"anyurl\", but didn't find it among the calls to {{\"http://localhost:{Port}/\"}}.");
|
||||
$"Expected _server to have been called at address matching the absolute url \"anyurl\", but didn't find it among the calls to {{\"http://localhost:{_portUsed}/\"}}.");
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task WithHeader_WhenACallWasMadeWithExpectedHeader_Should_BeOK()
|
||||
{
|
||||
_httpClient.DefaultRequestHeaders.Add("Authorization", "Bearer a");
|
||||
await _httpClient.GetAsync("");
|
||||
|
||||
_server.Should()
|
||||
.HaveReceivedACall()
|
||||
.WithHeader("Authorization", "Bearer a");
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task WithHeader_WhenACallWasMadeWithExpectedHeaderAmongMultipleHeaderValues_Should_BeOK()
|
||||
{
|
||||
_httpClient.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/xml"));
|
||||
_httpClient.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));
|
||||
await _httpClient.GetAsync("");
|
||||
|
||||
_server.Should()
|
||||
.HaveReceivedACall()
|
||||
.WithHeader("Accept", new[] { "application/xml", "application/json" });
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task WithHeader_Should_ThrowWhenNoCallsMatchingTheHeaderNameWereMade()
|
||||
{
|
||||
await _httpClient.GetAsync("");
|
||||
|
||||
Action act = () => _server.Should()
|
||||
.HaveReceivedACall()
|
||||
.WithHeader("Authorization", "value");
|
||||
|
||||
var sentHeaders = _server.LogEntries.SelectMany(x => x.RequestMessage.Headers)
|
||||
.ToDictionary(x => x.Key, x => x.Value)
|
||||
.ToList();
|
||||
|
||||
var sentHeaderString = "{" + string.Join(", ", sentHeaders) + "}";
|
||||
|
||||
act.Should().Throw<Exception>()
|
||||
.And.Message.Should()
|
||||
.Be(
|
||||
$"Expected headers from requests sent {sentHeaderString} to contain key \"Authorization\".{NewLine}");
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task WithHeader_Should_ThrowWhenNoCallsMatchingTheHeaderValuesWereMade()
|
||||
{
|
||||
_httpClient.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/xml"));
|
||||
_httpClient.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));
|
||||
await _httpClient.GetAsync("");
|
||||
|
||||
Action act = () => _server.Should()
|
||||
.HaveReceivedACall()
|
||||
.WithHeader("Accept", "missing-value");
|
||||
|
||||
var sentHeaders = _server.LogEntries.SelectMany(x => x.RequestMessage.Headers)
|
||||
.ToDictionary(x => x.Key, x => x.Value)["Accept"]
|
||||
.Select(x => $"\"{x}\"")
|
||||
.ToList();
|
||||
|
||||
var sentHeaderString = "{" + string.Join(", ", sentHeaders) + "}";
|
||||
|
||||
act.Should().Throw<Exception>()
|
||||
.And.Message.Should()
|
||||
.Be(
|
||||
$"Expected header \"Accept\" from requests sent with value(s) {sentHeaderString} to contain \"missing-value\".{NewLine}");
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task WithHeader_Should_ThrowWhenNoCallsMatchingTheHeaderWithMultipleValuesWereMade()
|
||||
{
|
||||
_httpClient.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/xml"));
|
||||
_httpClient.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));
|
||||
await _httpClient.GetAsync("");
|
||||
|
||||
Action act = () => _server.Should()
|
||||
.HaveReceivedACall()
|
||||
.WithHeader("Accept", new[] { "missing-value1", "missing-value2" });
|
||||
|
||||
const string missingValue1Message =
|
||||
"Expected header \"Accept\" from requests sent with value(s) {\"application/xml\", \"application/json\"} to contain \"missing-value1\".";
|
||||
const string missingValue2Message =
|
||||
"Expected header \"Accept\" from requests sent with value(s) {\"application/xml\", \"application/json\"} to contain \"missing-value2\".";
|
||||
|
||||
act.Should().Throw<Exception>()
|
||||
.And.Message.Should()
|
||||
.Be($"{string.Join(NewLine, missingValue1Message, missingValue2Message)}{NewLine}");
|
||||
}
|
||||
|
||||
public void Dispose()
|
||||
@@ -59,4 +162,4 @@ namespace WireMock.Net.Tests.FluentAssertions
|
||||
_server?.Dispose();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -34,10 +34,10 @@ namespace WireMock.Net.Tests.RequestBuilders
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void RequestBuilder_WithParam_String_IExactMatcher()
|
||||
public void RequestBuilder_WithParam_String_IStringMatcher()
|
||||
{
|
||||
// Act
|
||||
var requestBuilder = (Request)Request.Create().WithParam("p", new ExactMatcher("v"));
|
||||
var requestBuilder = (Request)Request.Create().WithParam("p", new RegexMatcher("[012]"));
|
||||
|
||||
// Assert
|
||||
var matchers = requestBuilder.GetPrivateFieldValue<IList<IRequestMatcher>>("_requestMatchers");
|
||||
|
||||
@@ -11,7 +11,7 @@ namespace WireMock.Net.Tests.ResponseBuilders
|
||||
{
|
||||
public class ResponseWithStatusCodeTests
|
||||
{
|
||||
private readonly Mock<IFluentMockServerSettings> _settingsMock = new Mock<IFluentMockServerSettings>();
|
||||
private readonly Mock<IWireMockServerSettings> _settingsMock = new Mock<IWireMockServerSettings>();
|
||||
private const string ClientIp = "::1";
|
||||
|
||||
[Theory]
|
||||
|
||||
@@ -25,7 +25,7 @@ namespace WireMock.Net.Tests.Serialization
|
||||
// Assign
|
||||
var request = Request.Create();
|
||||
var response = Response.Create();
|
||||
var mapping = new Mapping(Guid.NewGuid(), "", null, _settings, request, response, 0, null, null, null);
|
||||
var mapping = new Mapping(Guid.NewGuid(), "", null, _settings, request, response, 0, null, null, null, null);
|
||||
|
||||
// Act
|
||||
var model = _sut.ToMappingModel(mapping);
|
||||
@@ -44,7 +44,7 @@ namespace WireMock.Net.Tests.Serialization
|
||||
// Assign
|
||||
var request = Request.Create();
|
||||
var response = Response.Create().WithBodyAsJson(new { x = "x" }).WithTransformer();
|
||||
var mapping = new Mapping(Guid.NewGuid(), "", null, _settings, request, response, 42, null, null, null);
|
||||
var mapping = new Mapping(Guid.NewGuid(), "", null, _settings, request, response, 42, null, null, null, null);
|
||||
|
||||
// Act
|
||||
var model = _sut.ToMappingModel(mapping);
|
||||
|
||||
@@ -3,6 +3,7 @@ using System.Linq;
|
||||
using System.Net;
|
||||
using System.Net.Http;
|
||||
using System.Threading.Tasks;
|
||||
using FluentAssertions;
|
||||
using NFluent;
|
||||
using WireMock.RequestBuilders;
|
||||
using WireMock.ResponseBuilders;
|
||||
@@ -61,6 +62,89 @@ namespace WireMock.Net.Tests
|
||||
Check.That(responseWithState).Equals("Test state msg");
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task Scenarios_With_Same_Path_Should_Use_Times_When_Moving_To_Next_State()
|
||||
{
|
||||
// given
|
||||
const int times = 2;
|
||||
string path = $"/foo_{Guid.NewGuid()}";
|
||||
string body1 = "Scenario S1, No State, Setting State T2";
|
||||
string body2 = "Scenario S1, State T2, End";
|
||||
var server = WireMockServer.Start();
|
||||
|
||||
server
|
||||
.Given(Request.Create().WithPath(path).UsingGet())
|
||||
.InScenario(1)
|
||||
.WillSetStateTo(2, times)
|
||||
.RespondWith(Response.Create().WithBody(body1));
|
||||
|
||||
server
|
||||
.Given(Request.Create().WithPath(path).UsingGet())
|
||||
.InScenario(1)
|
||||
.WhenStateIs(2)
|
||||
.RespondWith(Response.Create().WithBody(body2));
|
||||
|
||||
// when
|
||||
var client = new HttpClient();
|
||||
var responseScenario1 = await client.GetStringAsync("http://localhost:" + server.Ports[0] + path);
|
||||
var responseScenario2 = await client.GetStringAsync("http://localhost:" + server.Ports[0] + path);
|
||||
var responseWithState = await client.GetStringAsync("http://localhost:" + server.Ports[0] + path);
|
||||
|
||||
// then
|
||||
responseScenario1.Should().Be(body1);
|
||||
responseScenario2.Should().Be(body1);
|
||||
responseWithState.Should().Be(body2);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task Scenarios_With_Different_Paths_Should_Use_Times_When_Moving_To_Next_State()
|
||||
{
|
||||
// given
|
||||
const int times = 2;
|
||||
string path1 = $"/a_{Guid.NewGuid()}";
|
||||
string path2 = $"/b_{Guid.NewGuid()}";
|
||||
string path3 = $"/c_{Guid.NewGuid()}";
|
||||
string body1 = "Scenario S1, No State, Setting State T2";
|
||||
string body2 = "Scenario S1, State T2, Setting State T3";
|
||||
string body3 = "Scenario S1, State T3, End";
|
||||
|
||||
var server = WireMockServer.Start();
|
||||
|
||||
server
|
||||
.Given(Request.Create().WithPath(path1).UsingGet())
|
||||
.InScenario("S1")
|
||||
.WillSetStateTo("T2", times)
|
||||
.RespondWith(Response.Create().WithBody(body1));
|
||||
|
||||
server
|
||||
.Given(Request.Create().WithPath(path2).UsingGet())
|
||||
.InScenario("S1")
|
||||
.WhenStateIs("T2")
|
||||
.WillSetStateTo("T3", times)
|
||||
.RespondWith(Response.Create().WithBody(body2));
|
||||
|
||||
server
|
||||
.Given(Request.Create().WithPath(path3).UsingGet())
|
||||
.InScenario("S1")
|
||||
.WhenStateIs("T3")
|
||||
.RespondWith(Response.Create().WithBody(body3));
|
||||
|
||||
// when
|
||||
var client = new HttpClient();
|
||||
var t1a = await client.GetStringAsync("http://localhost:" + server.Ports[0] + path1);
|
||||
var t1b = await client.GetStringAsync("http://localhost:" + server.Ports[0] + path1);
|
||||
var t2a = await client.GetStringAsync("http://localhost:" + server.Ports[0] + path2);
|
||||
var t2b = await client.GetStringAsync("http://localhost:" + server.Ports[0] + path2);
|
||||
var t3 = await client.GetStringAsync("http://localhost:" + server.Ports[0] + path3);
|
||||
|
||||
// then
|
||||
t1a.Should().Be(body1);
|
||||
t1b.Should().Be(body1);
|
||||
t2a.Should().Be(body2);
|
||||
t2b.Should().Be(body2);
|
||||
t3.Should().Be(body3);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task Scenarios_Should_Respect_Int_Valued_Scenarios_and_States()
|
||||
{
|
||||
|
||||
@@ -33,9 +33,9 @@ namespace WireMock.Net.Tests
|
||||
SaveMappingToFile = false
|
||||
}
|
||||
};
|
||||
var server = WireMockServer.Start(settings);
|
||||
|
||||
// Act
|
||||
var server = WireMockServer.Start(settings);
|
||||
|
||||
// Act
|
||||
var requestMessage = new HttpRequestMessage
|
||||
{
|
||||
Method = HttpMethod.Get,
|
||||
@@ -47,8 +47,8 @@ namespace WireMock.Net.Tests
|
||||
// Assert
|
||||
Check.That(server.Mappings).HasSize(2);
|
||||
Check.That(server.LogEntries).HasSize(1);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task WireMockServer_Proxy_Should_proxy_responses()
|
||||
{
|
||||
@@ -123,7 +123,7 @@ namespace WireMock.Net.Tests
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task WireMockServer_Proxy_Should_exclude_blacklisted_content_header_in_mapping()
|
||||
public async Task WireMockServer_Proxy_Should_exclude_ExcludedHeaders_in_mapping()
|
||||
{
|
||||
// Assign
|
||||
string path = $"/prx_{Guid.NewGuid()}";
|
||||
@@ -139,7 +139,7 @@ namespace WireMock.Net.Tests
|
||||
Url = serverForProxyForwarding.Urls[0],
|
||||
SaveMapping = true,
|
||||
SaveMappingToFile = false,
|
||||
BlackListedHeaders = new[] { "blacklisted" }
|
||||
BlackListedHeaders = new[] { "excluded-header-X" }
|
||||
}
|
||||
};
|
||||
var server = WireMockServer.Start(settings);
|
||||
@@ -152,7 +152,7 @@ namespace WireMock.Net.Tests
|
||||
RequestUri = new Uri($"{server.Urls[0]}{path}"),
|
||||
Content = new StringContent("stringContent")
|
||||
};
|
||||
requestMessage.Headers.Add("blacklisted", "exact_match");
|
||||
requestMessage.Headers.Add("foobar", "exact_match");
|
||||
requestMessage.Headers.Add("ok", "ok-value");
|
||||
await new HttpClient().SendAsync(requestMessage);
|
||||
|
||||
@@ -160,12 +160,12 @@ namespace WireMock.Net.Tests
|
||||
var mapping = server.Mappings.FirstOrDefault(m => m.Guid != defaultMapping.Guid);
|
||||
Check.That(mapping).IsNotNull();
|
||||
var matchers = ((Request)mapping.RequestMatcher).GetRequestMessageMatchers<RequestMessageHeaderMatcher>().Select(m => m.Name).ToList();
|
||||
Check.That(matchers).Not.Contains("blacklisted");
|
||||
Check.That(matchers).Not.Contains("excluded-header-X");
|
||||
Check.That(matchers).Contains("ok");
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task WireMockServer_Proxy_Should_exclude_blacklisted_cookies_in_mapping()
|
||||
public async Task WireMockServer_Proxy_Should_exclude_ExcludedCookies_in_mapping()
|
||||
{
|
||||
// Assign
|
||||
string path = $"/prx_{Guid.NewGuid()}";
|
||||
@@ -515,7 +515,7 @@ namespace WireMock.Net.Tests
|
||||
content.Should().Contain("known"); // On Linux it's "Name or service not known". On Windows it's "No such host is known.".
|
||||
|
||||
server.LogEntries.Should().HaveCount(1);
|
||||
((StatusModel) server.LogEntries.First().ResponseMessage.BodyData.BodyAsJson).Status.Should().Contain("known");
|
||||
((StatusModel)server.LogEntries.First().ResponseMessage.BodyData.BodyAsJson).Status.Should().Contain("known");
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user