Extends Verify to allow snapshot testing with EntityFramework.
See Milestones for release notes.
Call EfRecording.EnableRecording()
on DbContextOptionsBuilder
.
var builder = new DbContextOptionsBuilder<SampleDbContext>();
builder.UseSqlServer(connection);
builder.EnableRecording();
var data = new SampleDbContext(builder.Options);
EnableRecording
should only be called in the test context.
To start recording call EfRecording.StartRecording()
. The results will be automatically included in verified file.
var company = new Company
{
Name = "Title"
};
data.Add(company);
await data.SaveChangesAsync();
Recording.Start();
await data
.Companies
.Where(_ => _.Name == "Title")
.ToListAsync();
await Verify();
Will result in the following verified file:
{
ef: {
Type: ReaderExecutedAsync,
HasTransaction: false,
Text:
SELECT [c].[Id], [c].[Name]
FROM [Companies] AS [c]
WHERE [c].[Name] = N'Title'
}
}
Database designed by Creative Stall from The Noun Project.