diff --git a/Response-Templating.md b/Response-Templating.md index 1e5ff6f..94cbb16 100644 --- a/Response-Templating.md +++ b/Response-Templating.md @@ -44,7 +44,7 @@ All of the standard helpers (template functions) provided by the C# Handlebars i 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#: +**Example**: to generate a random string between 8 and 20 characters, use this code in C#: ```csharp var server = FluentMockServer.Start(); server @@ -58,7 +58,24 @@ server ); ``` +**Example**: to generate a random string using a Regex pattern, use this code in C#: +```csharp +var server = FluentMockServer.Start(); +server + .Given(Request.Create().WithPath("/random-regex").UsingGet()) + .RespondWith(Response.Create() + .WithHeader("Content-Type", "application/json") + .WithBodyAsJson( + Text = "{{Xeger \"[1-9][0-9]{3}[A-Z]{2}\"}", + ) + .WithTransformer() + ); +``` + #### Random (all supported randomizers) +You can use the powerful Regular Expression string generator based on [Fare - Finite Automata and Regular Expressions](https://github.com/moodmosaic/Fare). +- Text Regex Pattern: `"{{Xeger Pattern=\"[1-9][0-9]{3}[A-Z]{2}"}}"` + 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\"}}"` @@ -67,7 +84,7 @@ Besides a random text string, it's also possible to generate this random data: - 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 Regex Pattern: `"{{Random Type=\"TextRegex\" Pattern=\"[1-9][0-9]{3}[A-Z]{2}"}}"` - Text Lorum Ipsum: `"{{Random Type=\"TextIpsum\" Paragraphs=2}}"` - String List: `"{{Random Type=\"StringList\" Values=[\"a\", \"b\", \"c\"]}}"` - IPv4 Address: `"{{Random Type=\"IPv4Address\"}}"`