Coder Social home page Coder Social logo

kaynanguarany / fact Goto Github PK

View Code? Open in Web Editor NEW

This project forked from vmussak/fact

0.0 2.0 0.0 146 KB

Is a great tool to improve your stubs tests. Inspired in FFaker, a great Ruby test feature, Fact bring the same experiênce to C# developers

C# 100.00%

fact's Introduction

Fact

Is a great tool to improve your stubs tests. Inspired in FFaker, a great Ruby test feature, Fact bring the same experiênce to C# developers

Install

To install fact, run the following command in the Package Manager Console

PM> Install-Package fact

Fakers

discover all Fakers in Fact.Faker namespace

  var customer = new Customer
  {
      Id = "build-test-01",
      Address = Faker.BR.AddressBR.Address,
      Email = Faker.Internet.Email("customer"),
      Name = Faker.Name.FullName,
      Site = Faker.Internet.HttpUri
  };

Custom using Fakers

using Fact.Factory;
using Fact.Tests.Domain.Model;

namespace Fact.Tests.Factory
{
    internal class CustomerFactory
    {
        public static void Build()
        {
            var customer = new Customer
            {
                Id = "build-test-01",
                Address = Faker.BR.AddressBR.Address,
                Email = Faker.Internet.Email("customer"),
                Name = Faker.Name.FullName,
                Site = Faker.Internet.HttpUri
            };

            var customer_without_email = new Customer
            {
                Id = "build-test-02",
                Address = Faker.BR.AddressBR.Address,
                Name = Faker.Name.FullName,
                Site = Faker.Internet.HttpUri
            };

            Builder.Current.Set(customer);
            Builder.Current.Set("without email", customer_without_email);
        }
    }
}

##Setup

namespace Fact.Tests
{
    [SetUpFixture]
    internal class FactInitializer
    {
        [SetUp]
        public void Before()
        {
            CustomerFactory.Build();
        }

        [TearDown]
        public void Down()
        {
            Builder.Current.Clear();
        }
    }
}

Using

using Fact.Factory;

namespace Fact.Tests.Unity.Domain.Model
{
    [TestFixture]
    public class BuilderTests
    {
        [Test]
        public void BuildDeCustumer()
        {
            var customer = Builder.Current.Build<Customer>();
            var customerWithoutEmail = Builder.Current.Build<Customer>("without email");
            
            Assert.AreEqual("build-test-01", customer.Id);
            Assert.AreEqual("build-test-02", customerWithoutEmail.Id);
        }
    }
}

fact's People

Contributors

yanjustino avatar edubalf avatar

Watchers

James Cloos avatar Kaynã B. Guarany 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.