how can I obtain the equivalent of
Substitute.For<DbSet<MyClass>, IQueryable<MyClass>, IDbAsyncEnumerable>()
with machine.fakes? I tried using
var myFake = An<DbSet<MyClass>>();
myFake.WhenToldTo(m => ((IQueryable<MyClass>)m).Provider).Return(whatever);
but I get the following NotImplementedException:
The member 'IQueryable.Provider' has not been implemented on type 'DbSet`1Proxy' which
inherits from 'DbSet`1'. Test doubles for 'DbSet`1' must provide implementations of
methods and properties that are used.
The same exception raises with myFake.WhenToldTo(m => ((IQueryable)m).Provider).Return(whatever);
This is a class that reproduces the issue with minimal code. You need to add packages for Entity Framework, Machine.Specifications, Machie.Specifications.Should, Machine.Fakes, Machine.Fakes.NSubstitute, NSubstitute (or any other Mock Framework plugin)
using System.Data.Entity;
using System.Linq;
using Machine.Fakes;
using Machine.Specifications;
namespace SpecsTests
{
public class TestClass
{}
[Subject("Test")]
internal class TestSpecifications
{
[Subject("Test")]
private class Test : WithFakes
{
private static int Count;
private static DbSet<TestClass> Subject;
private Establish context = () =>
{
var data = new [] { new TestClass() }.AsQueryable();
Subject = An<DbSet<TestClass>>();
Subject.WhenToldTo(m => ((IQueryable)m).Provider).Return( data.Provider);
};
private Because of = () => { Count = Subject.Count(); };
private It Should_return_expected_results = () =>
{
Count.ShouldEqual(1);
};
}
}
}