代码之家  ›  专栏  ›  技术社区  ›  ViqMontana

如何在使用实际实现时使用NSubstitute模拟属性

  •  0
  • ViqMontana  · 技术社区  · 9 年前

    我有一些NHibernate存储库,我希望我的SpecFlow测试能够涵盖它们。

    public class StaffRepository : NHibernateRepository<IStaff>, 
    {
        public IEnumerable<IStaff> GetByStaffId(string staffId)
        {
            return Repository.Where(ab => ab.StaffId == staffId);
        }
    }
    

    哪里 Repository 是一个位于基类型上的属性-这是我想要模拟的属性。我使用结构映射注入我的所有类,然后模拟StaffRepository,如下所示:

    pmsRepository = Substitute.For<StaffRepository>();
    ApplicationContext.Register<IStaffRepository, StaffRepository>(pmsRepository);
    

    我的问题是,当我嘲笑 类似这样的财产:

    pmsRepository.Query.Returns(ListOfStaffes.AsQueryable());
    

    我总是收到以下错误消息:

    NSubstitute.Exceptions.CouldNotSetReturnDueToNoLastCallException: 'Could not find a call to return from.
    

    我做错了什么?

    1 回复  |  直到 9 年前
        1
  •  1
  •   ViqMontana    9 年前

    Repository

    推荐文章