This commit is contained in:
Stef Heyenrath
2017-01-30 21:51:54 +01:00
parent 9a413a0940
commit 517304b999
9 changed files with 90 additions and 40 deletions

View 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>

View 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>

View File

@@ -35,6 +35,7 @@ namespace WireMock.Net.ConsoleApplication
.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]}}"" }")
.WithTransformer()
.WithDelay(1000)
.WithDelay(TimeSpan.FromMilliseconds(100))
);
@@ -75,7 +76,7 @@ namespace WireMock.Net.ConsoleApplication
server
.Given(Request.Create().WithPath("/nobody").UsingGet())
.RespondWith(Response.Create()
.RespondWith(Response.Create().WithDelay(TimeSpan.FromSeconds(1))
.WithStatusCode(200));
Console.WriteLine("Press any key to stop the server");

View File

@@ -54,5 +54,13 @@ namespace WireMock.Admin.Mappings
/// The headers.
/// </value>
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; }
}
}

View File

@@ -1,7 +1,6 @@
using System;
using JetBrains.Annotations;
using WireMock.Matchers;
using WireMock.Matchers.Request;
namespace WireMock.RequestBuilders
{
@@ -13,45 +12,35 @@ namespace WireMock.RequestBuilders
/// <summary>
/// The with body.
/// </summary>
/// <param name="matcher">
/// The matcher.
/// </param>
/// <param name="matcher">The matcher.</param>
/// <returns>The <see cref="IRequestBuilder"/>.</returns>
IRequestBuilder WithBody([NotNull] IMatcher matcher);
/// <summary>
/// The with body.
/// </summary>
/// <param name="body">
/// The body.
/// </param>
/// <param name="body">The body.</param>
/// <returns>The <see cref="IRequestBuilder"/>.</returns>
IRequestBuilder WithBody(string body);
/// <summary>
/// The with body byte[].
/// </summary>
/// <param name="body">
/// The body as byte[].
/// </param>
/// <param name="body">The body as byte[].</param>
/// <returns>The <see cref="IRequestBuilder"/>.</returns>
IRequestBuilder WithBody(byte[] body);
/// <summary>
/// The with body string func.
/// </summary>
/// <param name="body">
/// The body string function.
/// </param>
/// <param name="body">The body string function.</param>
/// <returns>The <see cref="IRequestBuilder"/>.</returns>
IRequestBuilder WithBody(Func<string, bool> body);
/// <summary>
/// The with body byte[] func.
/// </summary>
/// <param name="body">
/// The body byte[] function.
/// </param>
/// <param name="body">The body byte[] function.</param>
/// <returns>The <see cref="IRequestBuilder"/>.</returns>
IRequestBuilder WithBody(Func<byte[], bool> body);
}

View File

@@ -1,7 +1,6 @@
using System;
using System.Collections.Generic;
using JetBrains.Annotations;
using WireMock.Matchers.Request;
using WireMock.Util;
namespace WireMock.RequestBuilders
@@ -14,12 +13,8 @@ namespace WireMock.RequestBuilders
/// <summary>
/// The with parameters.
/// </summary>
/// <param name="key">
/// The key.
/// </param>
/// <param name="values">
/// The values.
/// </param>
/// <param name="key">The key.</param>
/// <param name="values">The values.</param>
/// <returns>The <see cref="IRequestBuilder"/>.</returns>
IRequestBuilder WithParam([NotNull] string key, params string[] values);

View File

@@ -1,4 +1,5 @@
using System;
using JetBrains.Annotations;
namespace WireMock.ResponseBuilders
{
@@ -8,10 +9,17 @@ namespace WireMock.ResponseBuilders
public interface IDelayResponseBuilder : IResponseProvider
{
/// <summary>
/// The after delay.
/// The with delay.
/// </summary>
/// <param name="delay">The delay.</param>
/// <param name="delay">The TimeSpan to delay.</param>
/// <returns>The <see cref="IResponseBuilder"/>.</returns>
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);
}
}

View File

@@ -1,7 +1,5 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Linq.Expressions;
using System.Net;
using System.Text;
using System.Threading.Tasks;
@@ -17,7 +15,10 @@ namespace WireMock.ResponseBuilders
/// </summary>
public class Response : IResponseBuilder
{
private TimeSpan _delay = TimeSpan.Zero;
/// <summary>
/// The delay
/// </summary>
public TimeSpan? Delay { get; private set; }
/// <summary>
/// Gets a value indicating whether [use transformer].
@@ -160,7 +161,7 @@ namespace WireMock.ResponseBuilders
{
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;
}
@@ -191,20 +192,27 @@ namespace WireMock.ResponseBuilders
}
/// <summary>
/// The after delay.
/// The with delay.
/// </summary>
/// <param name="delay">
/// The delay.
/// </param>
/// <returns>
/// The <see cref="IResponseProvider"/>.
/// </returns>
/// <param name="delay">The TimeSpan to delay.</param>
/// <returns>The <see cref="IResponseBuilder"/>.</returns>
public IResponseBuilder WithDelay(TimeSpan delay)
{
_delay = delay;
Check.Condition(delay, d => d > TimeSpan.Zero, nameof(delay));
Delay = delay;
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>
/// The provide response.
/// </summary>
@@ -243,7 +251,8 @@ namespace WireMock.ResponseBuilders
responseMessage = ResponseMessage;
}
await Task.Delay(_delay);
if (Delay != null)
await Task.Delay(Delay.Value);
return responseMessage;
}

View File

@@ -282,6 +282,10 @@ namespace WireMock.Server
if (mappingModel.Response.UseTransformer)
responseBuilder = responseBuilder.WithTransformer();
if (mappingModel.Response.Delay != null)
responseBuilder = responseBuilder.WithDelay(mappingModel.Response.Delay.Value);
return responseBuilder;
}
@@ -332,7 +336,8 @@ namespace WireMock.Server
StatusCode = response.ResponseMessage.StatusCode,
Headers = response.ResponseMessage.Headers,
Body = response.ResponseMessage.Body,
UseTransformer = response.UseTransformer
UseTransformer = response.UseTransformer,
Delay = response.Delay?.Milliseconds
}
};
}