Manipulating objects with DbSet<T> and IQueryable<T> with NSubstitute returns error
问题 I'd like to use NSubstitute to unit test Entity Framework 6.x by mocking DbSet. Fortunately, Scott Xu provides a good unit testing library, EntityFramework.Testing.Moq using Moq. So, I modified his code to be suitable for NSubstitute and it's been looking good so far, until I wanted to test DbSet<T>.Add() , DbSet<T>.Remove() methods. Here's my code bits: public static class NSubstituteDbSetExtensions { public static DbSet<TEntity> SetupData<TEntity>(this DbSet<TEntity> dbset, ICollection