Skip to content
A fake provider for System.Data.Common.DbConnection and related classes.
Branch: master
Clone or download
jhgoodwin Merge pull request #8 from jhgoodwin/features/add_rudimentary_support…

Added basic impl FakeDbDataReader.GetFieldType and NextResult.
Latest commit 95da0c5 Aug 19, 2019
Type Name Latest commit message Commit time
Failed to load latest commit information.

Fake Db Provider for System.Data.Common.DbConnection

Master Branch Status

  • Build Status

Sometimes mocking just isn't enough, so you need a realistic double. This is where fakes come in.

To get started, I copied the code from here: Entity Framework Test code in github

In order to make this work, I needed to fill in a few places. A proper fake should not throw new NotImplementedException for normal use of properties and methods.

How to use:

Create a new test class, inheriting from AbstractFakeDbTest, like this:

public class MyInsertTests: AbstractFakeDbTest
    private int _commitCount = 0;
    public async void TransactionalSaveDataServer_SaveCausesOneSaveForSingleObject()
        var upsertSaves = 0;
        var scalarExecutes = 0;
        ExecuteNonQueryAsync = (command, token) => Task.FromResult(upsertSaves++);
        ExecuteScalarAsync = (command, token) =>
            return Task.FromResult<object>("My stub scalar");
        FakeConnection.TransactionChanged += OnTransactionChanged;
            var server = new MyClassUnderTest(Connection);
            var saveResult = await server.MySaveMethodAsync("My data to save");
            FakeConnection.TransactionChanged -= OnTransactionChanged;
    protected virtual void OnTransactionChanged(object sender, TransactionChangedEventArgs e)
        => _commitCount = ((e.CurrentValue ?? e.NextValue) as FakeDbTransaction)?.CommitCount ?? 0;
You can’t perform that action at this time.