Extends Verify to allow verification of EntityFramework bits.
Перейти к файлу
Simon Cropp 556f1d376b refs 2020-02-19 10:19:19 +11:00
.github GitHubSync update 2020-01-27 12:36:20 +11:00
src refs 2020-02-19 10:19:19 +11:00
.gitignore . 2020-01-06 15:58:10 +11:00
license.txt . 2020-01-06 15:58:10 +11:00
readme.md refs 2020-02-19 10:19:19 +11:00
readme.source.md refs 2020-02-19 10:19:19 +11:00

readme.md

Verify.EntityFramework

Build status NuGet Status NuGet Status

Extends Verify to allow verification of EntityFramework bits.

Support is available via a Tidelift Subscription.

Contents

NuGet package

Usage

Enable VerifyEntityFramewok once at assembly load time:

VerifyEntityFramework.Enable();

snippet source | anchor

VerifyEntityFrameworkClassic.Enable();

snippet source | anchor

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.Add(new Company {Content = "before"});
    await Verify(context);
}

snippet source | anchor

Will result in the following verified file:

{
  Added: {
    Company: {
      Id: 0,
      Content: 'before'
    }
  }
}

snippet source | anchor

{
  Added: {
    Company: {
      Id: 0,
      Content: 'before'
    }
  }
}

snippet source | anchor

Deleted entity

This test:

[Fact]
public async Task Deleted()
{
    var options = DbContextOptions();

    await using var context = new SampleDbContext(options);
    context.Add(new Company {Content = "before"});
    context.SaveChanges();

    var company = context.Companies.Single();
    context.Companies.Remove(company);
    await Verify(context);
}

snippet source | anchor

Will result in the following verified file:

{
  Deleted: {
    Company: {
      Id: 0
    }
  }
}

snippet source | anchor

{
  Deleted: {
    Company: {
      Id: 0
    }
  }
}

snippet source | anchor

Modified entity

This test:

[Fact]
public async Task Modified()
{
    var options = DbContextOptions();

    await using var context = new SampleDbContext(options);
    var company = new Company {Content = "before"};
    context.Add(company);
    context.SaveChanges();

    context.Companies.Single().Content = "after";
    await Verify(context);
}

snippet source | anchor

Will result in the following verified file:

{
  Modified: {
    Company: {
      Id: 0,
      Content: {
        Original: 'before',
        Current: 'after'
      }
    }
  }
}

snippet source | anchor

{
  Modified: {
    Company: {
      Id: 0,
      Content: {
        Original: 'before',
        Current: 'after'
      }
    }
  }
}

snippet source | anchor

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

snippet source | anchor

Will result in the following verified file:

SELECT [c].[Id], [c].[Content]
FROM [Companies] AS [c]
WHERE [c].[Content] = N'value'

snippet source | anchor

SELECT 
    [Extent1].[Id] AS [Id], 
    [Extent1].[Content] AS [Content]
    FROM [dbo].[Companies] AS [Extent1]
    WHERE N'value' = [Extent1].[Content]

snippet source | anchor

Security contact information

To report a security vulnerability, use the Tidelift security contact. Tidelift will coordinate the fix and disclosure.

Icon

Database designed by Creative Stall from The Noun Project.