0

尝试在测试中使用以下内容时,我不断收到此消息。

无法将表达式类型“lambda 表达式”转换为返回类型 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));
        }
4

1 回答 1

0

您在这里不需要 lambda:

x.Send(IsObjectMessageOf<EventComment>(m => weLikeIt));

你只需要传递一个 Func:

x.Send(IsObjectMessageOf<EventComment>(weLikeIt);
于 2013-10-02T14:09:48.800 回答