I\'m trying to write a suite of database integration tests for my domain which uses Entity Framework. I would prefer to autofixture objects in some scenarios. My ideal synt
Would something like this work?
var fixture = new Fixture();
fixture.Customize(c => c
.FromFactory(ctx => ctx.Set.Create()));
using (var context = new MyDbContext())
{
fixture.Inject(context);
var item = fixture.CreateAnonymous();
context.Set().Add(item);
context.SaveChanges();
}
Disclaimer: I haven't tried to compile this...
FWIW, if you were using xUnit.net with AutoFixture, you could reduce the test to something like:
[Theory, MyAutoData]
public void TheTest([Frozen]MyDbContext context, MyEntity item)
{
context.Set().Add(item);
context.SaveChanges();
}