我试图在dotnetcore项目中设置Moq。我有一个从我的控制器调用的通用存储库。我想测试一下是用moq来设置呼叫。但是我收到了一个错误。
启动的通用存储库调用import numpy as np
# an array can perform element wise calculations unlike lists.
a, b = np.array([2,5,1,9]), np.array([4,9,5,10])
mean = (a + b)/2; print(mean)
>>>[ 3. 7. 3. 9.5]
为T
为:
Room
来自public T GetSingle(Expression<Func<T, bool>> predicate, params
Expression<Func<T, object>>[] includeProperties)
的来电如下:
RoomController
模拟部分看起来像:
var room = _roomRepository.GetSingle(r => r.Id == id, ro => ro.Image);
但我一直都有错误:
roomRepositoryMock.Setup(c => c.GetSingle(It.IsAny<Expression<Func<Room, bool>>>(), It.IsAny<Expression<Func<Room, object>>>()))
.Returns<Room>(null);
其他帖子建议在RoomControllerTest.cs(62,55): error CS1503: Argument 1: cannot convert from 'method group' to 'Expression<Func<Room, bool>>'
RoomControllerTest.cs(62,70): error CS1503: Argument 2: cannot convert from 'System.Linq.Expressions.Expression<System.Func<viten_i_senter_backend.Models.Room, object>>' to 'System.Linq.Expressions.Expression<System.Func<viten_i_senter_backend.Models.Room, object>>'
之后添加()
,但这没有帮助。
有什么想法吗?
答案 0 :(得分:2)
params
接受一个数组,因此更改第二个期望值以期望任何数组的表达式It.IsAny<Expression<Func<Room, object>>[]>()
roomRepositoryMock
.Setup(c => c.GetSingle(It.IsAny<Expression<Func<Room, bool>>>(), It.IsAny<Expression<Func<Room, object>>[]>()))
.Returns<Room>(null);