diff --git a/ReSharper_WireMock.DotSettings b/ReSharper_WireMock.DotSettings
new file mode 100644
index 00000000..dcd08149
--- /dev/null
+++ b/ReSharper_WireMock.DotSettings
@@ -0,0 +1,29 @@
+
+ True
+ True
+ -1
+ -1
+ ArgumentPlaceholder
+ True
+ False
+
+ TypePlaceholder
+
+
+
+
+
+
+
+
+ True
+ False
+
+
+
+ ExpressionPlaceholder
+ True
+ CSHARP
+ Check.NotNull($paramName$, nameof($paramName$));
+ if ($paramName$ == null) throw new $ArgumentNullException$($args$);
+ SUGGESTION
\ No newline at end of file
diff --git a/WireMock.Net Solution.sln.DotSettings b/WireMock.Net Solution.sln.DotSettings
new file mode 100644
index 00000000..0464aade
--- /dev/null
+++ b/WireMock.Net Solution.sln.DotSettings
@@ -0,0 +1,6 @@
+
+ C:\Users\azureuser\Documents\Github\WireMock.Net\ReSharper_WireMock.DotSettings
+ ..\ReSharper_WireMock.DotSettings
+ True
+ True
+ 1
\ No newline at end of file
diff --git a/examples/WireMock.Net.ConsoleApplication/Program.cs b/examples/WireMock.Net.ConsoleApplication/Program.cs
index e3cbc7fe..c3faea31 100644
--- a/examples/WireMock.Net.ConsoleApplication/Program.cs
+++ b/examples/WireMock.Net.ConsoleApplication/Program.cs
@@ -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");
diff --git a/src/WireMock.Net/Admin/Mappings/ResponseModel.cs b/src/WireMock.Net/Admin/Mappings/ResponseModel.cs
index f433c1c0..333db82b 100644
--- a/src/WireMock.Net/Admin/Mappings/ResponseModel.cs
+++ b/src/WireMock.Net/Admin/Mappings/ResponseModel.cs
@@ -54,5 +54,13 @@ namespace WireMock.Admin.Mappings
/// The headers.
///
public IDictionary Headers { get; set; }
+
+ ///
+ /// Gets or sets the delay in milliseconds.
+ ///
+ ///
+ /// The delay in milliseconds.
+ ///
+ public int? Delay { get; set; }
}
}
\ No newline at end of file
diff --git a/src/WireMock.Net/RequestBuilders/IBodyRequestBuilder.cs b/src/WireMock.Net/RequestBuilders/IBodyRequestBuilder.cs
index 6757698e..5aa52039 100644
--- a/src/WireMock.Net/RequestBuilders/IBodyRequestBuilder.cs
+++ b/src/WireMock.Net/RequestBuilders/IBodyRequestBuilder.cs
@@ -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
///
/// The with body.
///
- ///
- /// The matcher.
- ///
+ /// The matcher.
/// The .
IRequestBuilder WithBody([NotNull] IMatcher matcher);
///
/// The with body.
///
- ///
- /// The body.
- ///
+ /// The body.
/// The .
IRequestBuilder WithBody(string body);
///
/// The with body byte[].
///
- ///
- /// The body as byte[].
- ///
+ /// The body as byte[].
/// The .
IRequestBuilder WithBody(byte[] body);
///
/// The with body string func.
///
- ///
- /// The body string function.
- ///
+ /// The body string function.
/// The .
IRequestBuilder WithBody(Func body);
///
/// The with body byte[] func.
///
- ///
- /// The body byte[] function.
- ///
+ /// The body byte[] function.
/// The .
IRequestBuilder WithBody(Func body);
}
diff --git a/src/WireMock.Net/RequestBuilders/IParamsRequestBuilder.cs b/src/WireMock.Net/RequestBuilders/IParamsRequestBuilder.cs
index 97fedf1d..fb7ba015 100644
--- a/src/WireMock.Net/RequestBuilders/IParamsRequestBuilder.cs
+++ b/src/WireMock.Net/RequestBuilders/IParamsRequestBuilder.cs
@@ -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
///
/// The with parameters.
///
- ///
- /// The key.
- ///
- ///
- /// The values.
- ///
+ /// The key.
+ /// The values.
/// The .
IRequestBuilder WithParam([NotNull] string key, params string[] values);
diff --git a/src/WireMock.Net/ResponseBuilders/IDelayResponseBuilder.cs b/src/WireMock.Net/ResponseBuilders/IDelayResponseBuilder.cs
index 03804a15..eb94efc9 100644
--- a/src/WireMock.Net/ResponseBuilders/IDelayResponseBuilder.cs
+++ b/src/WireMock.Net/ResponseBuilders/IDelayResponseBuilder.cs
@@ -1,4 +1,5 @@
using System;
+using JetBrains.Annotations;
namespace WireMock.ResponseBuilders
{
@@ -8,10 +9,17 @@ namespace WireMock.ResponseBuilders
public interface IDelayResponseBuilder : IResponseProvider
{
///
- /// The after delay.
+ /// The with delay.
///
- /// The delay.
+ /// The TimeSpan to delay.
/// The .
IResponseBuilder WithDelay(TimeSpan delay);
+
+ ///
+ /// The with delay.
+ ///
+ /// The milliseconds to delay.
+ /// The .
+ IResponseBuilder WithDelay(int milliseconds);
}
}
\ No newline at end of file
diff --git a/src/WireMock.Net/ResponseBuilders/Response.cs b/src/WireMock.Net/ResponseBuilders/Response.cs
index 4ad980e1..4209d0aa 100644
--- a/src/WireMock.Net/ResponseBuilders/Response.cs
+++ b/src/WireMock.Net/ResponseBuilders/Response.cs
@@ -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
///
public class Response : IResponseBuilder
{
- private TimeSpan _delay = TimeSpan.Zero;
+ ///
+ /// The delay
+ ///
+ public TimeSpan? Delay { get; private set; }
///
/// 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
}
///
- /// The after delay.
+ /// The with delay.
///
- ///
- /// The delay.
- ///
- ///
- /// The .
- ///
+ /// The TimeSpan to delay.
+ /// The .
public IResponseBuilder WithDelay(TimeSpan delay)
{
- _delay = delay;
+ Check.Condition(delay, d => d > TimeSpan.Zero, nameof(delay));
+ Delay = delay;
return this;
}
+ ///
+ /// The with delay.
+ ///
+ /// The milliseconds to delay.
+ /// The .
+ public IResponseBuilder WithDelay(int milliseconds)
+ {
+ return WithDelay(TimeSpan.FromMilliseconds(milliseconds));
+ }
+
///
/// The provide response.
///
@@ -243,7 +251,8 @@ namespace WireMock.ResponseBuilders
responseMessage = ResponseMessage;
}
- await Task.Delay(_delay);
+ if (Delay != null)
+ await Task.Delay(Delay.Value);
return responseMessage;
}
diff --git a/src/WireMock.Net/Server/FluentMockServer.Admin.cs b/src/WireMock.Net/Server/FluentMockServer.Admin.cs
index d3b2d3b5..dcd03164 100644
--- a/src/WireMock.Net/Server/FluentMockServer.Admin.cs
+++ b/src/WireMock.Net/Server/FluentMockServer.Admin.cs
@@ -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
}
};
}