尝试在测试中使用以下内容时,我不断收到此消息。
无法将表达式类型'lambda expression'转换为返回类型bool
问题出现在线上..
// x.Send(IsObjectMessageOf(m => weLikeIt));
[Test]
public void should_send_add_comment_message__when_user_adds_comment()
{
Event currentEvent = SampleEventBuilder.PopulatedByNextId()
.NewState()
.BuildDomain();
_repository.Setup(x => x.FindByEventId(It.IsAny<int>()))
.Returns(currentEvent);
var eventComment = AddComment.Create(currentEvent.Key, currentEvent.Id, "comment", Time.Now, "client", Guid.NewGuid());
_handler.Consume(eventComment);
Func<EventComment, bool> weLikeIt = ec => ec.EventId == currentEvent.Id;
_sender.Verify(x =>
{
x.Send(IsObjectMessageOf<EventComment>(m => weLikeIt)); // Bombs Here!
});
}
private static ObjMessage IsObjectMessageOf<T>(Func<T, bool> matcher)
{
return It.Is<ObjMessage>(m => m.Body is T && matcher((T)m.Body));
}
答案 0 :(得分:0)
这里你不需要lambda:
x.Send(IsObjectMessageOf<EventComment>(m => weLikeIt));
你只需要传递一个Func:
x.Send(IsObjectMessageOf<EventComment>(weLikeIt);