Skip to content

Latest commit

 

History

History
43 lines (31 loc) · 1.29 KB

README.md

File metadata and controls

43 lines (31 loc) · 1.29 KB

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>();