Last active
January 5, 2018 10:22
-
-
Save JaykeOps/905b1f8179c2664c0e3ff03aa6d02b5f to your computer and use it in GitHub Desktop.
AutoFixture CheatSheet
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var fixture = new Fixture(); | |
//Primitives | |
var anonymousStr = fixture.Create<string>("This str makes it easier to read failed tests."); | |
var anonymousInt = fixture.Create<int>(); | |
//Collections | |
var anonymousCollection = fixture.CreateMany<int>(); | |
var limitedAnonymousCollection = fixture.CreateMany<string>(3); | |
//Add to collections | |
var collection = new Collection<string>(); | |
var fixture.AddManyTo(collection, 10); | |
var fixture.AddManyTo(collection, () => "Hello World!"); //Will add Hello World! to the collection (3x is default) | |
//Non-primitive type creation | |
var car = fixture.Create<Car>(); //Create entires object graphs | |
var cars = fixture.CreateMany<Car>(100); //Create 100 cars with anonymous test data (.AddManyTo() also works) | |
//Customizing fixture data | |
fixture.Inject("1234"); //Same instance returned everytime fixture.Create<string>() is called. | |
fixture.Inject(new Car("M3", "BMW", 2015)); //Same instance returned everytime fixture.Create<Car>() is called. | |
fixture.Register(() => "Lada"); //New instance returned everytime fixture.Create<string>() is called. |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment