Skip to content

Commit 831c883

Browse files
committed
Randomizer plugin documented
1 parent 8b4bef6 commit 831c883

File tree

1 file changed

+29
-0
lines changed

1 file changed

+29
-0
lines changed

README.md

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -513,6 +513,35 @@ Here you can see that a parent has a ```List<Children>``` and the ```Children```
513513
The **```Name```** and **```LastName```** of a person will be generated by the **```RealNamesPlugin```**. The age of the person should be somewhere between 10 and 32.
514514
When you generate a city use the **```MnemonicStringPlugin```** and finally ignore the Street in the **```Address```**. Quite a lot. But it works!
515515

516+
##Randomizer<T> class
517+
People who uses the ObjectFiller.NET asked me very often, is it also possible to use the data generators from the ObjectFiller.NET in a easy way for simple types like integer or double? Now you can do it, thanks to the static class **```Randomizer<T>```**. You can use it like that:
518+
519+
```csharp
520+
public int GiveMeSomeRandomInt()
521+
{
522+
return Randomizer<int>.Create();
523+
}
524+
```
525+
526+
This will create a random integer. This will work with all types (like int, string, double, bool, etc...). Its also possible to generate a complex type, like an address. The **```Randomizer<T>```** uses always the default data generators of the ObjectFiller.NET.
527+
528+
But you can also customize the usage of the **```Randomizer<T>```** with the same plugins which you can for the ObjectFiller. For example you can do something like that:
529+
```csharp
530+
public int GiveMeSomeRandomIntBetween100And200()
531+
{
532+
return Randomizer<int>.Create(new IntRange(100, 200));
533+
}
534+
```
535+
It will return you an integer between 100 and 200.
536+
537+
Here is another example where the Randomizer generates a random string based on the lorem ipsum plugin:
538+
```csharp
539+
public string GiveMeSomeRandomLoremIpsumText()
540+
{
541+
Randomizer<string>.Create(new Lipsum(LipsumFlavor.LoremIpsum));
542+
}
543+
```
544+
516545
##Available Plugins
517546

518547
The ObjectFiller.NET is easy to extend, you can write your own plugins for it.

0 commit comments

Comments
 (0)