1
我使用的嘲弄库起订量,我无法安装这个签名模拟:广东话设置模拟与起订量为通用的IEnumerable任务
Task<IEnumerable<TEntity>> GetAllAsync<TEntity>(
Func<IQueryable<TEntity>, IOrderedQueryable<TEntity>> orderBy = null,
string includeProperties = null,
int? skip = null,
int? take = null)
where TEntity : class, IEntity;
}
的单元测试类
using System.Collections.Generic;
using System.Linq;
using System.Linq.Expressions;
using System.Threading.Tasks;
using ICEBookshop.API.Factories;
using ICEBookshop.API.Interfaces;
using ICEBookshop.API.Models;
using Moq;
using SpecsFor;
namespace ICEBookshop.API.UnitTests.Factories
{
public class GivenCreatingListOfProducts : SpecsFor<ProductFactory>
{
private Mock<IGenericRepository> _genericRepositorMock;
protected override void Given()
{
_genericRepositorMock = new Mock<IGenericRepository>();
}
public class GivenRepositoryHasDataAndListOfProductsExist : GivenCreatingListOfProducts
{
protected override void Given()
{
_genericRepositorMock.Setup(
expr => expr.GetAllAsync<Product>(It.IsAny<Func<IQueryable<Product>>>(), null, null, null))
.ReturnsAsync<Product>(new List<Product>());
}
}
}
}
这行代码是让我疯:
genericRepositorMock.Setup(
expr => expr.GetAllAsync<Product>(It.IsAny<Func<IQueryable<Product>>>(), null, null, null))
.ReturnsAsync<Product>(new List<Product>());
的问题是我做的不知道如何设置GetAllAsync
,因此它会编译并返回一个产品列表。它返回产品列表的期望行为。
任何人都可以帮我设置这个签名模拟?