mirror of
https://github.com/wiremock/WireMock.Net.git
synced 2026-04-25 02:09:06 +02:00
Delay
This commit is contained in:
29
ReSharper_WireMock.DotSettings
Normal file
29
ReSharper_WireMock.DotSettings
Normal file
@@ -0,0 +1,29 @@
|
|||||||
|
<wpf:ResourceDictionary xml:space="preserve" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:s="clr-namespace:System;assembly=mscorlib" xmlns:ss="urn:shemas-jetbrains-com:settings-storage-xaml" xmlns:wpf="http://schemas.microsoft.com/winfx/2006/xaml/presentation">
|
||||||
|
<s:Boolean x:Key="/Default/PatternsAndTemplates/StructuralSearch/Pattern/=99FF42DE363B4B439A0BF7D1DA299892/@KeyIndexDefined">True</s:Boolean>
|
||||||
|
<s:Boolean x:Key="/Default/PatternsAndTemplates/StructuralSearch/Pattern/=99FF42DE363B4B439A0BF7D1DA299892/CustomPatternPlaceholder/=args/@KeyIndexDefined">True</s:Boolean>
|
||||||
|
<s:String x:Key="/Default/PatternsAndTemplates/StructuralSearch/Pattern/=99FF42DE363B4B439A0BF7D1DA299892/CustomPatternPlaceholder/=args/Properties/=Maximal/@EntryIndexedValue">-1</s:String>
|
||||||
|
<s:String x:Key="/Default/PatternsAndTemplates/StructuralSearch/Pattern/=99FF42DE363B4B439A0BF7D1DA299892/CustomPatternPlaceholder/=args/Properties/=Minimal/@EntryIndexedValue">-1</s:String>
|
||||||
|
<s:String x:Key="/Default/PatternsAndTemplates/StructuralSearch/Pattern/=99FF42DE363B4B439A0BF7D1DA299892/CustomPatternPlaceholder/=args/Type/@EntryValue">ArgumentPlaceholder</s:String>
|
||||||
|
<s:Boolean x:Key="/Default/PatternsAndTemplates/StructuralSearch/Pattern/=99FF42DE363B4B439A0BF7D1DA299892/CustomPatternPlaceholder/=ArgumentNullException/@KeyIndexDefined">True</s:Boolean>
|
||||||
|
<s:String x:Key="/Default/PatternsAndTemplates/StructuralSearch/Pattern/=99FF42DE363B4B439A0BF7D1DA299892/CustomPatternPlaceholder/=ArgumentNullException/Properties/=ExactType/@EntryIndexedValue">False</s:String>
|
||||||
|
<s:String x:Key="/Default/PatternsAndTemplates/StructuralSearch/Pattern/=99FF42DE363B4B439A0BF7D1DA299892/CustomPatternPlaceholder/=ArgumentNullException/Properties/=Type/@EntryIndexedValue"></s:String>
|
||||||
|
<s:String x:Key="/Default/PatternsAndTemplates/StructuralSearch/Pattern/=99FF42DE363B4B439A0BF7D1DA299892/CustomPatternPlaceholder/=ArgumentNullException/Type/@EntryValue">TypePlaceholder</s:String>
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
<s:Boolean x:Key="/Default/PatternsAndTemplates/StructuralSearch/Pattern/=99FF42DE363B4B439A0BF7D1DA299892/CustomPatternPlaceholder/=paramName/@KeyIndexDefined">True</s:Boolean>
|
||||||
|
<s:String x:Key="/Default/PatternsAndTemplates/StructuralSearch/Pattern/=99FF42DE363B4B439A0BF7D1DA299892/CustomPatternPlaceholder/=paramName/Properties/=ExactType/@EntryIndexedValue">False</s:String>
|
||||||
|
<s:String x:Key="/Default/PatternsAndTemplates/StructuralSearch/Pattern/=99FF42DE363B4B439A0BF7D1DA299892/CustomPatternPlaceholder/=paramName/Properties/=ExpressionType/@EntryIndexedValue"></s:String>
|
||||||
|
|
||||||
|
|
||||||
|
<s:String x:Key="/Default/PatternsAndTemplates/StructuralSearch/Pattern/=99FF42DE363B4B439A0BF7D1DA299892/CustomPatternPlaceholder/=paramName/Type/@EntryValue">ExpressionPlaceholder</s:String>
|
||||||
|
<s:Boolean x:Key="/Default/PatternsAndTemplates/StructuralSearch/Pattern/=99FF42DE363B4B439A0BF7D1DA299892/IsReplacePattern/@EntryValue">True</s:Boolean>
|
||||||
|
<s:String x:Key="/Default/PatternsAndTemplates/StructuralSearch/Pattern/=99FF42DE363B4B439A0BF7D1DA299892/LanguageName/@EntryValue">CSHARP</s:String>
|
||||||
|
<s:String x:Key="/Default/PatternsAndTemplates/StructuralSearch/Pattern/=99FF42DE363B4B439A0BF7D1DA299892/ReplacePattern/@EntryValue">Check.NotNull($paramName$, nameof($paramName$));</s:String>
|
||||||
|
<s:String x:Key="/Default/PatternsAndTemplates/StructuralSearch/Pattern/=99FF42DE363B4B439A0BF7D1DA299892/SearchPattern/@EntryValue">if ($paramName$ == null) throw new $ArgumentNullException$($args$);</s:String>
|
||||||
|
<s:String x:Key="/Default/PatternsAndTemplates/StructuralSearch/Pattern/=99FF42DE363B4B439A0BF7D1DA299892/Severity/@EntryValue">SUGGESTION</s:String></wpf:ResourceDictionary>
|
||||||
6
WireMock.Net Solution.sln.DotSettings
Normal file
6
WireMock.Net Solution.sln.DotSettings
Normal file
@@ -0,0 +1,6 @@
|
|||||||
|
<wpf:ResourceDictionary xml:space="preserve" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:s="clr-namespace:System;assembly=mscorlib" xmlns:ss="urn:shemas-jetbrains-com:settings-storage-xaml" xmlns:wpf="http://schemas.microsoft.com/winfx/2006/xaml/presentation">
|
||||||
|
<s:String x:Key="/Default/Environment/InjectedLayers/FileInjectedLayer/=FBE2016FCEACD34DB66E1CC40B87F9F2/AbsolutePath/@EntryValue">C:\Users\azureuser\Documents\Github\WireMock.Net\ReSharper_WireMock.DotSettings</s:String>
|
||||||
|
<s:String x:Key="/Default/Environment/InjectedLayers/FileInjectedLayer/=FBE2016FCEACD34DB66E1CC40B87F9F2/RelativePath/@EntryValue">..\ReSharper_WireMock.DotSettings</s:String>
|
||||||
|
<s:Boolean x:Key="/Default/Environment/InjectedLayers/FileInjectedLayer/=FBE2016FCEACD34DB66E1CC40B87F9F2/@KeyIndexDefined">True</s:Boolean>
|
||||||
|
<s:Boolean x:Key="/Default/Environment/InjectedLayers/InjectedLayerCustomization/=FileFBE2016FCEACD34DB66E1CC40B87F9F2/@KeyIndexDefined">True</s:Boolean>
|
||||||
|
<s:Double x:Key="/Default/Environment/InjectedLayers/InjectedLayerCustomization/=FileFBE2016FCEACD34DB66E1CC40B87F9F2/RelativePriority/@EntryValue">1</s:Double></wpf:ResourceDictionary>
|
||||||
@@ -35,6 +35,7 @@ namespace WireMock.Net.ConsoleApplication
|
|||||||
.WithHeader("Transformed-Postman-Token", "token is {{request.headers.Postman-Token}}")
|
.WithHeader("Transformed-Postman-Token", "token is {{request.headers.Postman-Token}}")
|
||||||
.WithBody(@"{""msg"": ""Hello world, {{request.path}}, bykey={{request.query.start}}, bykey={{request.query.stop}}, byidx0={{request.query.stop.[0]}}, byidx1={{request.query.stop.[1]}}"" }")
|
.WithBody(@"{""msg"": ""Hello world, {{request.path}}, bykey={{request.query.start}}, bykey={{request.query.stop}}, byidx0={{request.query.stop.[0]}}, byidx1={{request.query.stop.[1]}}"" }")
|
||||||
.WithTransformer()
|
.WithTransformer()
|
||||||
|
.WithDelay(1000)
|
||||||
.WithDelay(TimeSpan.FromMilliseconds(100))
|
.WithDelay(TimeSpan.FromMilliseconds(100))
|
||||||
);
|
);
|
||||||
|
|
||||||
@@ -75,7 +76,7 @@ namespace WireMock.Net.ConsoleApplication
|
|||||||
|
|
||||||
server
|
server
|
||||||
.Given(Request.Create().WithPath("/nobody").UsingGet())
|
.Given(Request.Create().WithPath("/nobody").UsingGet())
|
||||||
.RespondWith(Response.Create()
|
.RespondWith(Response.Create().WithDelay(TimeSpan.FromSeconds(1))
|
||||||
.WithStatusCode(200));
|
.WithStatusCode(200));
|
||||||
|
|
||||||
Console.WriteLine("Press any key to stop the server");
|
Console.WriteLine("Press any key to stop the server");
|
||||||
|
|||||||
@@ -54,5 +54,13 @@ namespace WireMock.Admin.Mappings
|
|||||||
/// The headers.
|
/// The headers.
|
||||||
/// </value>
|
/// </value>
|
||||||
public IDictionary<string, string> Headers { get; set; }
|
public IDictionary<string, string> Headers { get; set; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Gets or sets the delay in milliseconds.
|
||||||
|
/// </summary>
|
||||||
|
/// <value>
|
||||||
|
/// The delay in milliseconds.
|
||||||
|
/// </value>
|
||||||
|
public int? Delay { get; set; }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -1,7 +1,6 @@
|
|||||||
using System;
|
using System;
|
||||||
using JetBrains.Annotations;
|
using JetBrains.Annotations;
|
||||||
using WireMock.Matchers;
|
using WireMock.Matchers;
|
||||||
using WireMock.Matchers.Request;
|
|
||||||
|
|
||||||
namespace WireMock.RequestBuilders
|
namespace WireMock.RequestBuilders
|
||||||
{
|
{
|
||||||
@@ -13,45 +12,35 @@ namespace WireMock.RequestBuilders
|
|||||||
/// <summary>
|
/// <summary>
|
||||||
/// The with body.
|
/// The with body.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="matcher">
|
/// <param name="matcher">The matcher.</param>
|
||||||
/// The matcher.
|
|
||||||
/// </param>
|
|
||||||
/// <returns>The <see cref="IRequestBuilder"/>.</returns>
|
/// <returns>The <see cref="IRequestBuilder"/>.</returns>
|
||||||
IRequestBuilder WithBody([NotNull] IMatcher matcher);
|
IRequestBuilder WithBody([NotNull] IMatcher matcher);
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// The with body.
|
/// The with body.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="body">
|
/// <param name="body">The body.</param>
|
||||||
/// The body.
|
|
||||||
/// </param>
|
|
||||||
/// <returns>The <see cref="IRequestBuilder"/>.</returns>
|
/// <returns>The <see cref="IRequestBuilder"/>.</returns>
|
||||||
IRequestBuilder WithBody(string body);
|
IRequestBuilder WithBody(string body);
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// The with body byte[].
|
/// The with body byte[].
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="body">
|
/// <param name="body">The body as byte[].</param>
|
||||||
/// The body as byte[].
|
|
||||||
/// </param>
|
|
||||||
/// <returns>The <see cref="IRequestBuilder"/>.</returns>
|
/// <returns>The <see cref="IRequestBuilder"/>.</returns>
|
||||||
IRequestBuilder WithBody(byte[] body);
|
IRequestBuilder WithBody(byte[] body);
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// The with body string func.
|
/// The with body string func.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="body">
|
/// <param name="body">The body string function.</param>
|
||||||
/// The body string function.
|
|
||||||
/// </param>
|
|
||||||
/// <returns>The <see cref="IRequestBuilder"/>.</returns>
|
/// <returns>The <see cref="IRequestBuilder"/>.</returns>
|
||||||
IRequestBuilder WithBody(Func<string, bool> body);
|
IRequestBuilder WithBody(Func<string, bool> body);
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// The with body byte[] func.
|
/// The with body byte[] func.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="body">
|
/// <param name="body">The body byte[] function.</param>
|
||||||
/// The body byte[] function.
|
|
||||||
/// </param>
|
|
||||||
/// <returns>The <see cref="IRequestBuilder"/>.</returns>
|
/// <returns>The <see cref="IRequestBuilder"/>.</returns>
|
||||||
IRequestBuilder WithBody(Func<byte[], bool> body);
|
IRequestBuilder WithBody(Func<byte[], bool> body);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,7 +1,6 @@
|
|||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using JetBrains.Annotations;
|
using JetBrains.Annotations;
|
||||||
using WireMock.Matchers.Request;
|
|
||||||
using WireMock.Util;
|
using WireMock.Util;
|
||||||
|
|
||||||
namespace WireMock.RequestBuilders
|
namespace WireMock.RequestBuilders
|
||||||
@@ -14,12 +13,8 @@ namespace WireMock.RequestBuilders
|
|||||||
/// <summary>
|
/// <summary>
|
||||||
/// The with parameters.
|
/// The with parameters.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="key">
|
/// <param name="key">The key.</param>
|
||||||
/// The key.
|
/// <param name="values">The values.</param>
|
||||||
/// </param>
|
|
||||||
/// <param name="values">
|
|
||||||
/// The values.
|
|
||||||
/// </param>
|
|
||||||
/// <returns>The <see cref="IRequestBuilder"/>.</returns>
|
/// <returns>The <see cref="IRequestBuilder"/>.</returns>
|
||||||
IRequestBuilder WithParam([NotNull] string key, params string[] values);
|
IRequestBuilder WithParam([NotNull] string key, params string[] values);
|
||||||
|
|
||||||
|
|||||||
@@ -1,4 +1,5 @@
|
|||||||
using System;
|
using System;
|
||||||
|
using JetBrains.Annotations;
|
||||||
|
|
||||||
namespace WireMock.ResponseBuilders
|
namespace WireMock.ResponseBuilders
|
||||||
{
|
{
|
||||||
@@ -8,10 +9,17 @@ namespace WireMock.ResponseBuilders
|
|||||||
public interface IDelayResponseBuilder : IResponseProvider
|
public interface IDelayResponseBuilder : IResponseProvider
|
||||||
{
|
{
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// The after delay.
|
/// The with delay.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="delay">The delay.</param>
|
/// <param name="delay">The TimeSpan to delay.</param>
|
||||||
/// <returns>The <see cref="IResponseBuilder"/>.</returns>
|
/// <returns>The <see cref="IResponseBuilder"/>.</returns>
|
||||||
IResponseBuilder WithDelay(TimeSpan delay);
|
IResponseBuilder WithDelay(TimeSpan delay);
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// The with delay.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="milliseconds">The milliseconds to delay.</param>
|
||||||
|
/// <returns>The <see cref="IResponseBuilder"/>.</returns>
|
||||||
|
IResponseBuilder WithDelay(int milliseconds);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -1,7 +1,5 @@
|
|||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Linq;
|
|
||||||
using System.Linq.Expressions;
|
|
||||||
using System.Net;
|
using System.Net;
|
||||||
using System.Text;
|
using System.Text;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
@@ -17,7 +15,10 @@ namespace WireMock.ResponseBuilders
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
public class Response : IResponseBuilder
|
public class Response : IResponseBuilder
|
||||||
{
|
{
|
||||||
private TimeSpan _delay = TimeSpan.Zero;
|
/// <summary>
|
||||||
|
/// The delay
|
||||||
|
/// </summary>
|
||||||
|
public TimeSpan? Delay { get; private set; }
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Gets a value indicating whether [use transformer].
|
/// Gets a value indicating whether [use transformer].
|
||||||
@@ -160,7 +161,7 @@ namespace WireMock.ResponseBuilders
|
|||||||
{
|
{
|
||||||
Check.NotNull(body, nameof(body));
|
Check.NotNull(body, nameof(body));
|
||||||
|
|
||||||
ResponseMessage.Body = JsonConvert.SerializeObject(body, new JsonSerializerSettings { Formatting = Formatting.None, NullValueHandling = NullValueHandling.Ignore } );
|
ResponseMessage.Body = JsonConvert.SerializeObject(body, new JsonSerializerSettings { Formatting = Formatting.None, NullValueHandling = NullValueHandling.Ignore });
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -191,20 +192,27 @@ namespace WireMock.ResponseBuilders
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// The after delay.
|
/// The with delay.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="delay">
|
/// <param name="delay">The TimeSpan to delay.</param>
|
||||||
/// The delay.
|
/// <returns>The <see cref="IResponseBuilder"/>.</returns>
|
||||||
/// </param>
|
|
||||||
/// <returns>
|
|
||||||
/// The <see cref="IResponseProvider"/>.
|
|
||||||
/// </returns>
|
|
||||||
public IResponseBuilder WithDelay(TimeSpan delay)
|
public IResponseBuilder WithDelay(TimeSpan delay)
|
||||||
{
|
{
|
||||||
_delay = delay;
|
Check.Condition(delay, d => d > TimeSpan.Zero, nameof(delay));
|
||||||
|
Delay = delay;
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// The with delay.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="milliseconds">The milliseconds to delay.</param>
|
||||||
|
/// <returns>The <see cref="IResponseBuilder"/>.</returns>
|
||||||
|
public IResponseBuilder WithDelay(int milliseconds)
|
||||||
|
{
|
||||||
|
return WithDelay(TimeSpan.FromMilliseconds(milliseconds));
|
||||||
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// The provide response.
|
/// The provide response.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
@@ -243,7 +251,8 @@ namespace WireMock.ResponseBuilders
|
|||||||
responseMessage = ResponseMessage;
|
responseMessage = ResponseMessage;
|
||||||
}
|
}
|
||||||
|
|
||||||
await Task.Delay(_delay);
|
if (Delay != null)
|
||||||
|
await Task.Delay(Delay.Value);
|
||||||
|
|
||||||
return responseMessage;
|
return responseMessage;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -282,6 +282,10 @@ namespace WireMock.Server
|
|||||||
|
|
||||||
if (mappingModel.Response.UseTransformer)
|
if (mappingModel.Response.UseTransformer)
|
||||||
responseBuilder = responseBuilder.WithTransformer();
|
responseBuilder = responseBuilder.WithTransformer();
|
||||||
|
|
||||||
|
if (mappingModel.Response.Delay != null)
|
||||||
|
responseBuilder = responseBuilder.WithDelay(mappingModel.Response.Delay.Value);
|
||||||
|
|
||||||
return responseBuilder;
|
return responseBuilder;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -332,7 +336,8 @@ namespace WireMock.Server
|
|||||||
StatusCode = response.ResponseMessage.StatusCode,
|
StatusCode = response.ResponseMessage.StatusCode,
|
||||||
Headers = response.ResponseMessage.Headers,
|
Headers = response.ResponseMessage.Headers,
|
||||||
Body = response.ResponseMessage.Body,
|
Body = response.ResponseMessage.Body,
|
||||||
UseTransformer = response.UseTransformer
|
UseTransformer = response.UseTransformer,
|
||||||
|
Delay = response.Delay?.Milliseconds
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user