4

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

被嘲笑的班级看起来像这样......

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

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

错误消息:测试方法 Genesis.Service.Implementation.Tests.DigestFixture.ShouldCorrectlyExtractTemplateTokens 抛出异常:Telerik.JustMock.Core.ElevatedMockingException:无法模拟“System.String get_Subject()”。必须启用探查器来模拟、安排或执行指定的目标。Stacktrace:在 Telerik.JustMock.Core.MocksRepository.AddArrange(IMethodMock methodMock) 在 Telerik.JustMock.Core.MocksRepository.CheckMethodInterceptorAvailable(IMatcher instanceMatcher, MethodBase method) 在 Telerik.JustMock.Core.ProfilerInterceptor.ThrowElevatedMockingException(MemberInfo member)。 JustMock.Core.MocksRepository.Arrange[TMethodMock](Expression expr, Func 1 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 表达式)在 Genesis.Service.Implementation.Tests.DigestFixture.ShouldCorrectlyExtractTemplateTokens() 在 c:\Genesis\Development\Genesis.Service.Implementation.Tests\DigestFixture.cs:line 46

谁能指出我做错了什么?

4

1 回答 1

6

确保您已从菜单中启用探查器。

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

在此处输入图像描述

于 2015-05-07T08:44:28.490 回答