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

Cannot mock .... The profiler must be enabled to mock, arrange or execute the specified target

我在测试中有以下内容(我可能会添加我的第一个 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}}.");

被嘲笑的 class 看起来像这样...

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; }
}

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

Error Message: Test method Genesis.Service.Implementation.Tests.DigestFixture.ShouldCorrectlyExtractTemplateTokens threw exception: Telerik.JustMock.Core.ElevatedMockingException: Cannot mock 'System.String get_Subject()'. The profiler must be enabled to mock, arrange or execute the specified target. Stacktrace: at Telerik.JustMock.Core.ProfilerInterceptor.ThrowElevatedMockingException(MemberInfo member) at Telerik.JustMock.Core.MocksRepository.CheckMethodInterceptorAvailable(IMatcher instanceMatcher, MethodBase method) at Telerik.JustMock.Core.MocksRepository.AddArrange(IMethodMock methodMock) at Telerik.JustMock.Core.MocksRepository.Arrange[TMethodMock](Expression expr, Func1 methodMockFactory) at Telerik.JustMock.Mock.<>c__DisplayClass81.b__6() at Telerik.JustMock.Core.ProfilerInterceptor.GuardInternal[T](Func1 guardedAction) at Telerik.JustMock.Mock.Arrange[TResult](Expression1 expression) at Genesis.Service.Implementation.Tests.DigestFixture.ShouldCorrectlyExtractTemplateTokens() in c:\Genesis\Development\Genesis.Service.Implementation.Tests\DigestFixture.cs:line 46

谁能指出我做错了什么?

确保您已从菜单中启用分析器。

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