-
-
Notifications
You must be signed in to change notification settings - Fork 794
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Possible regression between 4.7.49 and 4.7.58? #383
Comments
Thanks for reporting. I would like to look into this to see what other use cases might be affected. Unfortunately, I cannot get your repro code to run, since some type declarations and variable definitions are missing. Could you please provide a short but complete repro code? Thanks! (Btw. this sounds slightly reminiscent of #22.) |
I have the same exact problem. [TestClass]
public class Test
{
public class Post
{
public string Url { get; set; }
}
public interface IBlogContext
{
IDbSet<Post> Posts { get; }
}
private static Mock<DbSet<T>> CreateMockSet<T>(IQueryable<T> dataForDbSet) where T : class
{
var dbsetMock = new Mock<DbSet<T>>();
dbsetMock.As<IQueryable<T>>().Setup(m => m.Provider).Returns(dataForDbSet.Provider);
dbsetMock.As<IQueryable<T>>().Setup(m => m.Expression).Returns(dataForDbSet.Expression);
dbsetMock.As<IQueryable<T>>().Setup(m => m.ElementType).Returns(dataForDbSet.ElementType);
dbsetMock.As<IQueryable<T>>().Setup(m => m.GetEnumerator()).Returns(dataForDbSet.GetEnumerator());
return dbsetMock;
}
[TestMethod]
public void TestGetFirst()
{
var posts = Enumerable.Range(0, 5).Select(x => new Post()
{
Url = string.Format("www.someurl{0}", x)
}).AsQueryable();
var dbsetMock = CreateMockSet(posts);
var mockContext = new Mock<IBlogContext>();
mockContext.Setup(c => c.Posts).Returns(dbsetMock.Object);
mockContext.Object.Posts.First().Url.Should().Be("www.someurl0");
}
} System.NotImplementedException: The member 'IQueryable.Provider' has not been implemented on type 'DbSet Regards |
Thank you @vascofernandes for the repro code. This is indeed a regression introduced by #381 (which itself fixed a major regression that has been lurking around for ages). I expect to have a fixed version of Moq available later today, or during the next few days at the latest. |
@vascofernandes, your reported issue should be fixed in Moq 4.7.63. @sharky98: If you find that the latest version doesn't resolve your problem, please report back. |
Confirmed. It is fixed. Regards |
I've created a piece of code, based on article Entity Framework Testing with a Mocking Framework (EF6 onwards). Where I'm bugging is in the Testing query scenarios section.
I was using version 4.7.49 and I had to modify the
mockSet.As<IQueryable<Blog>>().Setup(m => m.GetEnumerator()).Returns(0 => data.GetEnumerator());
tomockSet.As<IQueryable<Blog>>().Setup(m => m.GetEnumerator()).Returns(data.GetEnumerator());
to make it work. The test was running fine. When I updated Moq to 4.7.58, the test is failing with following error:I'm new to the C#, ASP.NET MVC, EF world, so I'm a bit lost on where to look for my error.
Here my test method, if that make any differences:
The text was updated successfully, but these errors were encountered: