Giter Site home page Giter Site logo

faker's Introduction

Faker

User defined data type faker, capable of filling any complex data structure

Usage

Declare FakerConfig and Faker:

FakerConfig config = new FakerConfig();
Faker faker = new Faker(config);

Add custom function to fake data if needed:

public class Foo
{
    public int FooInt;
}

public object CustomIntGenerator(Type[] genericTypes)
{
  return -1;
}

FakerConfig config = new FakerConfig();
config.Add<Foo, Int32>(CustomIntGenerator, obj => obj.FooInt);
Faker faker = new Faker(config);

Your custom function should return object and receive Type[]. You can fill your custom class attribute if it has public access modifier or public constructor with the same name and type parameter. Class declaration example:

public class Foo
{
    public int FooInt { get; private set; }
    public TestClosedClass(int fooInt)
    {
        FooInt = fooInt;
    }
}

Usage example:

public class Foo
{
    public int FooInt { get; private set; }
    public TestClosedClass(int fooInt)
    {
        FooInt = fooInt;
    }
}

public object CustomIntGenerator(Type[] genericTypes)
{
  Random rand = new Random();
  return rand.Next() % 10;
}

FakerConfig config = new FakerConfig();
config.Add<Foo, Int32>(CustomIntGenerator, obj => obj.FooInt);
Faker faker = new Faker(config);
Foo foo = (Foo)faker.Create(typeof(Foo));    

faker's People

Contributors

den25570 avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.