8dd1e6f00c | ||
---|---|---|
.github | ||
src | ||
.gitignore | ||
license.txt | ||
readme.md | ||
readme.source.md |
readme.md
Verify.EntityFramework
Extends Verify to allow verification of EntityFramework bits.
Contents
NuGet package
https://nuget.org/packages/Verify.EntityFramework/
Usage
Enable VerifyEntityFramewok once at assembly load time:
VerifyEntityFramework.Enable();
ChangeTracking
Added, deleted, and Modified entities can be verified by performing changes on a DbContext and then verifying that context. This approach leverages the EntityFramework ChangeTracker.
Added entity
This test:
[Fact]
public async Task Added()
{
var options = DbContextOptions();
await using var context = new SampleDbContext(options);
context.Companies.Add(new Company {Content = "before"});
await Verify(context);
}
Will result in the following verified file:
{
Added: {
Company: {
Id: 0,
Content: 'before'
}
}
}
Deleted entity
This test:
[Fact]
public async Task Deleted()
{
var options = DbContextOptions();
await using (var context = new SampleDbContext(options))
{
context.Companies.Add(new Company {Content = "before"});
context.SaveChanges();
}
await using (var context = new SampleDbContext(options))
{
var company = context.Companies.Single();
context.Companies.Remove(company);
await Verify(context);
}
}
Will result in the following verified file:
{
Deleted: {
Company: {
Id: 0
}
}
}
Modified entity
This test:
[Fact]
public async Task Modified()
{
var options = DbContextOptions();
await using (var context = new SampleDbContext(options))
{
context.Add(new Company {Content = "before"});
context.SaveChanges();
}
await using (var context = new SampleDbContext(options))
{
context.Companies.Single().Content = "after";
await Verify(context);
}
}
Will result in the following verified file:
{
Modified: {
Company: {
Id: 0,
Content: {
Original: 'before',
Current: 'after'
}
}
}
}
Queryable
This test:
[Fact]
public async Task Queryable()
{
var database = await DbContextBuilder.GetDatabase("Queryable");
var dbContext = database.Context;
var queryable = dbContext.Companies.Where(x => x.Content == "value");
await Verify(queryable);
}
Will result in the following verified file:
SELECT [c].[Id], [c].[Content]
FROM [Companies] AS [c]
WHERE [c].[Content] = N'value'
Icon
Database designed by Creative Stall from The Noun Project.