GarbageCan.Application.UnitTests/Shared/MockDbContextExtensions.cs
/// <summary>
/// Will Configure the db context db set with a mocked Db Set
/// </summary>
/// <typeparam name="T"></typeparam>
/// <param name="setFunc"></param>
/// <param name="item">Item to be put into the mock DB set</param>
/// <param name="context"></param>
/// <returns>The Mocked Db Set</returns>
Will Configure the db context db set with a mocked Db Set
Will Configure the db context db set with a mocked Db Set
public static DbSet<T> ConfigureMockDbSet<T>(this IApplicationDbContext context,
            Func<IApplicationDbContext, DbSet<T>> setFunc,
            T item) where T : class
        {
            var mockDbSet = new[] { item }.AsQueryable().BuildMockDbSet();
            setFunc(context).Returns(x => mockDbSet);
            return mockDbSet;
        }
public static DbSet < T > ConfigureMockDbSet < T > ( this IApplicationDbContext context , Func < IApplicationDbContext , DbSet < T > > setFunc , T item ) where T : class { var mockDbSet = new [ ] { item } . AsQueryable ( ) . BuildMockDbSet ( ) ; setFunc ( context ) . Returns ( x => mockDbSet ) ; return mockDbSet ; }
Will Configure the db context db set with a mocked Db Set
Will Configure the db context db set with a mocked Db Set
The Mocked Db Set
The Mocked Db Set
IApplicationDbContext
this
setFunc
Func<IApplicationDbContext, DbSet<T>>
None
item
T
Item to be put into the mock DB set
Item to be put into the mock DB set
context
None
typeparam
None