Giter Club home page Giter Club logo

factoryalien's Introduction

FactoryAlien - A fake data generator for .Net.

Join the chat at https://gitter.im/pedrohfernandes/FactoryAlien

Travis: Travis

Nuget: NuGet

Project Description

Generate fake data to improve yout unit tests. FactoryAlien is a package inspired by factory_girl gem to help you to creating fake data to your tests.

Overview

Factoryalien is designed to make test-driven development more productive and unit tests more refactoring-safe.

Getting Started

Install FactoryAlien with NuGet Package Manager:

Install-Package FactoryAlien

To start creating fake data to your tests, you just need to create a factory object with generic type to will be generated.

IFactory<User> userFactory = FactoryAlien.Define<User>();

1. Create a single object.

To create a single fake object, use CreateOne() method.

User user = userFactory.CreateOne();

So you can specify your custom values! Do following:

User user = userFactory.CreateOne(user => {
    user.FirstName = "Gabriel";
});

This code will create a new User instance with "Gabriel" value in FirstName property, and random values in others properties.

2. Create an object list.

To create a fake object list, use CreateList(size) method.

var userList = userFactory.CreateList(3);

This code will create a list with 3 fake objects.

You can specify your custom values when creating lists too! Do following:

var userList = userFactory.CreateList(3, user => {
    user.FirstName = "Gabriel";
});

This code will create a list with 3 fake User instances with "Gabriel" value in FirstName property, and random values in others properties.

3. Building complex lists.

You can use fluent interface to create a more complex list with random and customized values, see:

var factory = FactoryAlien.Define<Product>();
var fakeProducts = factory.CreateList(5, product => product.Category = "GAMES");
fakeProducts.Add(4)
             .Add(3, product => product.Value = 25.00)
             .Add(2, product => {
				 product.Status = "In Stock";
				 product.Category = "Computer";
			  });

This code above will create a list with 14 products:
5 products with category equals to "Games";
4 products with all properties filled with random values;
3 products with value equals to 25.00;
2 products with Status equals to "In Stock" and Category equals to "Computer";

factoryalien's People

Contributors

fnandes avatar gitter-badger avatar ltmenezes avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  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.