无法模拟....必须启用探查器来模拟,安排或执行指定的目标

Stu*_*ing 4 unit-testing telerik justmock

我在测试中有以下内容(我的第一次JustMock测试,我可能会添加)...

        var template = Mock.Create<MessageType>();
        Mock.Arrange(() => template.Subject)
            .Returns("This template has Zero tokens.");

        Mock.Arrange(() => template.Body)
            .Returns("This template has {{number}} of {{tokens}}.");
Run Code Online (Sandbox Code Playgroud)

被Mocked这个班看起来像这样......

public class MessageType : BaseBusinessEntity
{
    public string Body { get; set; }

    public int DigestsToBeIncludedOn { get; set; }

    public Guid MessageReference { get; set; }

    public int MessageTypeId { get; set; }

    public string Name { get; set; }

    public int PredefinedRecipients { get; set; }

    public string Subject { get; set; }
}
Run Code Online (Sandbox Code Playgroud)

当我试图运行测试时,我得到...

错误消息:测试方法Genesis.Service.Implementation.Tests.DigestFixture.ShouldCorrectlyExtractTemplateTokens引发异常:Telerik.JustMock.Core.ElevatedMockingException:无法模拟'System.String get_Subject()'.必须启用探查器才能模拟,排列或执行指定的目标.Stacktrace:位于Telerik的Telerik.JustMock.Core.MocksRepository.AddArrange(IMethodMock methodMock)的Telerik.JustMock.Core.MocksRepository.CheckMethodInterceptorAvailable(IMatcher instanceMatcher,MethodBase方法)中的Telerik.JustMock.Core.ProfilerInterceptor.ThrowElevatedMockingException(MemberInfo成员). JustMock.Core.MocksRepository.Arrange [TMethodMock](表达式expr,Func 1 methodMockFactory) at Telerik.JustMock.Mock.<>c__DisplayClass81.b__6()位于Genesis.Service.Implementation.Tests.DigestFixture.ShouldCorrectlyExtractTemplateTokens的Telerik.JustMock.Core.ProfilerInterceptor.GuardInternal [T](Func 1 guardedAction) at Telerik.JustMock.Mock.Arrange[TResult](Expression1表达式) ()in c:\ Genesis\Development\Genesis.Service.Implementation.Tests\DigestFixture.cs:第46行

谁能指出我做错了什么?

Ste*_*nev 6

确保已从菜单中启用了探查器.

使用Visual Studio编写测试时,您会注意到Telerik菜单和其中的JustMock菜单项.在那里,您必须检查JustMock是否已启用("启用JustMock"应为灰色,请参见下面的示例).

在此输入图像描述