SqlServer.Rules.EntityFramework

Build status NuGet Status

Extends Verify to allow snapshot testing with EntityFramework.

See Milestones for release notes.

NuGet package

Enable

Call EfRecording.EnableRecording() on DbContextOptionsBuilder.

var builder = new DbContextOptionsBuilder<SampleDbContext>();
builder.UseSqlServer(connection);
builder.EnableRecording();
var data = new SampleDbContext(builder.Options);

snippet source | anchor

EnableRecording should only be called in the test context.

Usage

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

snippet source | anchor

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'
  }
}

snippet source | anchor

Icon

Database designed by Creative Stall from The Noun Project.