我正在模拟我的存储库接口,我不知道如何设置一个接受表达式并返回一个对象的方法?我正在使用Moq和NUnit
接口:
public interface IReadOnlyRepository : IDisposable
{
IQueryable<T> All<T>() where T : class;
T Single<T>(Expression<Func<T, bool>> expression) where T : class;
}
Run Code Online (Sandbox Code Playgroud)
使用IQueryable进行测试已经设置,但不知道如何设置T Single:
private Moq.Mock<IReadOnlyRepository> _mockRepos;
private AdminController _controller;
[SetUp]
public void SetUp()
{
var allPages = new List<Page>();
for (var i = 0; i < 10; i++)
{
allPages.Add(new Page { Id = i, Title = "Page Title " + i, Slug = "Page-Title-" + i, Content = "Page " + i + " on page content." …Run Code Online (Sandbox Code Playgroud)