0

I have some NHibernate repositories and I would like my SpecFlow tests to cover them.

I have a repository for Staff like so:

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

Where Repository is a property that lives on the base type - this is the property I would like to mock. I am using structure map to inject all my classes, and then mocking the StaffRepository like so:

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

My problem is, when I mock the Repository property like so:

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

I always receive the following error message:

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

What am I doing wrong here?

ViqMontana
  • 5,090
  • 3
  • 19
  • 54

1 Answers1

1

I figured it out in the end. The Repository must be virtual or abstract; changing this to virtual resolved the issue.

ViqMontana
  • 5,090
  • 3
  • 19
  • 54