我正在使用Moq和NUnit爲Windows服務創建一些測試。我有以下幾點:Moq使用LINQ語法驗證
mockPushService = Mock.Of<IPushService>(m =>
m.SendPushNotification(It.IsAny<UserDevice>(), It.IsAny<string>(), It.IsAny<int>(), It.IsAny<string>())); // Breaks.
mockMailService = Mock.Of<IEmailService>(m =>
m.SendMessage(It.IsAny<string>(), It.IsAny<string>(), It.IsAny<string>()) &&
m.ThrowErrors == true);
mockMailService
,因爲這些方法並不作廢工作正常與LINQ語法。然而,mockPushService
不工作,因爲它是一個無效的方法。我知道我應該使用Verifiable
,但我不確定如何使用這種語法來適應它。
更清楚,我得到這個編譯時錯誤:
Cannot convert lambda expression to delegate type 'System.Func<SurgeHub.Domain.Services.IPushService,bool>' because some of the return types in the block are not implicitly convertible to the delegate return type
Cannot implicitly convert type 'void' to 'bool'
我怎樣才能使這項工作?謝謝。
你能詳細解釋一下「休息」嗎?怎麼了?應該發生什麼? –