NMockaroo is a little library that provides an easy way for you to generate mock data based on your C# objects using the Mockaroo API.
Run the following command in the Package Manager Console:
PM> Install-Package NMockaroo
Suppose you have a Person object like this:
publicclassPerson{publicstringFirstName{get;set;}publicstringLastName{get;set;}publicstringEmail{get;set;}publicstringRole{get;set;}}Use the library of attributes in NMockaroo to define your Person Schema in Mockaroo:
publicclassPerson{[MockarooInfo(Type=DataTypes.FirstName)]publicstringFirstName{get;set;}[MockarooInfo(Type=DataTypes.LastName)]publicstringLastName{get;set;}[MockarooInfo(Type=DataTypes.EmailAddress,PercentBlank=40)]publicstringEmail{get;set;}[MockarooCustomList(PercentBlank=0,Type=DataTypes.CustomList,Values=new[]{"Super User","Administrator","Manager","Employee"},SelectionStyle="sequential")]publicstringRole{get;set;}}Then use MockarooClient to generate your mock data:
varclient=newMockarooClient(YOUR_API_KEY);varpeople=client.GetData<Person>(10).ToArray();Easy peasy.
From version 1.0.0, NMockaroo has web proxy support. When instantiating your MockarooClient object, you can declare your WebProxy details as follows:
varclient=newMockarooClient(YOUR_API_KEY){Proxy=newWebProxy{Address=newUri("http://web-proxy-url"),// ...}};NMockaroo is a single assembly designed to be easy to deploy anywhere. If you prefer to compile it yourself, you will need:
- Visual Studio 2015 (Community Edition is more than enough)
- Windows 7 or newer
NMockaroo is hosted on GitHub. If you find a bug, please visit the issue tracker and report the issue.
Feel free to submit a pull request containing any improvements, bug fixes or new features.
P.S. A huge thanks to Mockaroo, without which this library would not exist.
Copyright © 2016 Andrew McCaughan and other contributors.
Distributed under the MIT License.