diff --git a/Response-Templating.md b/Response-Templating.md index b314795..d3c2079 100644 --- a/Response-Templating.md +++ b/Response-Templating.md @@ -40,6 +40,40 @@ The model of the request is supplied to the header and body templates. The follo All of the standard helpers (template functions) provided by the C# Handlebars implementation plus all of the string helpers are available e.g. `{{capitalize request.query.search}}` +### Generate Random Data Support +It's possible to return random data using the `Random` Handlebars function. + +#### Random Text +Example: to generate a random string between 8 and 20 characters, use this code in C#: +```csharp +var server = FluentMockServer.Start(); +server + .Given(Request.Create().WithPath("/random").UsingGet()) + .RespondWith(Response.Create() + .WithHeader("Content-Type", "application/json") + .WithBodyAsJson( + Text = "{{Random Type=\"Text\" Min=8 Max=20}}", + ) + .WithTransformer() + ); +``` + +#### Random (all supported randomizers) +Besides a random text string, it's also possible to generate this random data: +- Integer: `"{{Random Type=\"Integer\" Min=100 Max=999}}"` +- Guid: `"{{Random Type=\"Guid\"}}"` +- City: `"{{Random Type=\"City\"}}"` +- Country: `"{{Random Type=\"Country\"}}"` +- First Name: `"{{Random Type=\"FirstName\" Male=false Female=true}}"` +- Email Address: `"{{Random Type=\"EmailAddress\"}}"` +- Text Words: `"{{Random Type=\"TextWords\" Min=10 Max=20}}"` +- Text Pattern: `"{{Random Type=\"TextPattern\" Pattern=\"\\xLLnn_**ss\\x\"}}"` +- Text Lorum Ipsum: `"{{Random Type=\"TextIpsum\" Paragraphs=2}}"` +- String List: `"{{Random Type=\"StringList\" Values=\"a\", \"b\", \"c\"}}"` (**TODO** : does this work ?) +- IP Address: `"{{Random Type=\"IPv4Address\"}}"` +- MAC Address: `"{{Random Type=\"MACAddress\"}}"` +- For more details on the supported random data types, see [RandomDataGenerator.Net](https://github.com/StefH/RandomDataGenerator); + ### JsonPath support JsonPath support is also present (internal logic is based on Newtonsoft.Json).