You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I just upgraded my Moq Nuget reference from 4.13.0 to 4.14.7 and my tests started failing. I tracked it down to this piece of code that sets up mocks for the DbSet. I could not determine what Moq is expecting. I did not play around with other versions between these two to know which one it started breaking on.
public static Mock<DbSet<T>> CreateDbSetMock<T>( IEnumerable<T> elements ) where T : class
{
var elementsAsQueryable = elements.AsQueryable();
var dbSetMock = new Mock<DbSet<T>>();
dbSetMock.As<IQueryable<T>>().Setup( m => m.Provider ).Returns( elementsAsQueryable.Provider );
dbSetMock.As<IQueryable<T>>().Setup( m => m.Expression ).Returns( elementsAsQueryable.Expression );
dbSetMock.As<IQueryable<T>>().Setup( m => m.ElementType ).Returns( elementsAsQueryable.ElementType );
dbSetMock.As<IQueryable<T>>().Setup( m => m.GetEnumerator() ).Returns( elementsAsQueryable.GetEnumerator() );
//dbSetMock.Setup( m => m.Include( It.IsAny<Expression<Func<T, IQueryable<T>>>>() ) ).Returns( dbSetMock.Object );
dbSetMock.Setup( m => m.Include( It.IsAny<String>() ) ).Returns( dbSetMock.Object );
return dbSetMock;
}
TearDown : Moq.MockException : The mock repository failed verification due to the following:
Mock<IGuildDbContext:14>:
This mock failed verification due to the following:
IGuildDbContext m => m.RankRequirements:
Mock<DbSet<RankRequirement>:3>:
This mock failed verification due to the following:
IQueryable<RankRequirement> m => m.ElementType:
This setup was not matched.
IQueryable<RankRequirement> m => m.GetEnumerator():
This setup was not matched.
DbSet<RankRequirement> m => m.Include(It.IsAny<string>()):
This setup was not matched.
IGuildDbContext m => m.RankStatusRings:
Mock<DbSet<RankStatusCompletedRing>:3>:
This mock failed verification due to the following:
IQueryable<RankStatusCompletedRing> m => m.ElementType:
This setup was not matched.
IQueryable<RankStatusCompletedRing> m => m.GetEnumerator():
This setup was not matched.
DbSet<RankStatusCompletedRing> m => m.Include(It.IsAny<string>()):
This setup was not matched.
IGuildDbContext m => m.RankStatusCrosses:
Mock<DbSet<RankStatusCompletedCross>:3>:
This mock failed verification due to the following:
IQueryable<RankStatusCompletedCross> m => m.ElementType:
This setup was not matched.
IQueryable<RankStatusCompletedCross> m => m.GetEnumerator():
This setup was not matched.
DbSet<RankStatusCompletedCross> m => m.Include(It.IsAny<string>()):
This setup was not matched.
IGuildDbContext m => m.RingApprovals:
Mock<DbSet<RingApproval>:3>:
This mock failed verification due to the following:
IQueryable<RingApproval> m => m.ElementType:
This setup was not matched.
IQueryable<RingApproval> m => m.GetEnumerator():
This setup was not matched.
DbSet<RingApproval> m => m.Include(It.IsAny<string>()):
This setup was not matched.
IGuildDbContext m => m.CrossStatusEntries:
Mock<DbSet<CrossStatusEntry>:3>:
This mock failed verification due to the following:
IQueryable<CrossStatusEntry> m => m.ElementType:
This setup was not matched.
IQueryable<CrossStatusEntry> m => m.GetEnumerator():
This setup was not matched.
DbSet<CrossStatusEntry> m => m.Include(It.IsAny<string>()):
This setup was not matched.
The text was updated successfully, but these errors were encountered:
Hard to say for sure without being able to test with an actual repro code. The most likely culprit is, once again, recursive verification. As a workaround, try replacing all .Returns(...) in your helper method with .Returns(() => ...).
I just upgraded my Moq Nuget reference from 4.13.0 to 4.14.7 and my tests started failing. I tracked it down to this piece of code that sets up mocks for the DbSet. I could not determine what Moq is expecting. I did not play around with other versions between these two to know which one it started breaking on.
TearDown : Moq.MockException : The mock repository failed verification due to the following:
The text was updated successfully, but these errors were encountered: