Skip to content

alec-anikin/SharpJuice.AutoFixture

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

13 Commits
 
 
 
 
 
 
 
 

Repository files navigation

SharpJuice.AutoFixture

NuGet

AutoFixture extension for partially specifying constructor parameters.

Samples

Class under test

public class Order
{
  //Modest constructor
  public Order(int id, string[] lineItems, decimal discount, string createdBy) {...}
  
  //Greedy constructor
  public Order(int id, string[] lineItems, decimal discount, Guid customerId, DateTimeOffset createdAt) {...}
}

Creating single instance with best fit constructor (modest constructor with all matched arguments)

fixture.Create<Order>(new { id = 100500, createdAt = DateTimeOffset.Now  });

Anonymous type property must match (case-insensitive) with one of constructor parameters.

Best fit constructor configuration

fixture.CustomizeConstructor<Order>(new { id = 100500, createdBy = "someuser" });

Greedy constructor configuration

fixture.CustomizeGreedyConstructor<Order>(new { discount = 10.0m, customerId = Guid.NewGuid() });

Freezing constructor parameter for a type. All instances of the type will get the same parameter instance.

fixture.FreezeParameter<Order, decimal>();

About

AutoFixture constructor injections

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages