我正在尝试为接口INotificationService创建一个模拟对象并进行设置,以便方法PushNotification(接受8个参数)将始终返回true或false。
以下似乎无法按预期工作。
我是否也需要使用Callback方法来执行此操作?
var notificationServiceMock = new Mock<INotificationService>();
notificationServiceMock
.Setup(n => n.PushNotification(
It.IsAny<long>(),
It.IsAny<Guid>(),
It.IsAny<string>(),
It.IsAny<string>(),
It.IsAny<DateTime>(),
It.IsAny<string>(),
It.IsAny<decimal>(),
It.IsAny<string>()))
.Returns<bool>(b => { return true; });
答案 0 :(得分:1)
var notificationServiceMock = new Mock<INotificationService>();
notificationServiceMock.Setup(n => n.PushNotification(
It.IsAny<long>(),
It.IsAny<Guid>(),
It.IsAny<string>(),
It.IsAny<string>(),
It.IsAny<DateTime>(),
It.IsAny<string>(),
It.IsAny<decimal>(),
It.IsAny<string>()))
.Returns(true);
INotificationService ntfObj = notificationServiceMock.Object;