相关疑难解决方法(0)

使用FakeItEasy和FluentValidation伪造来自commonlibnet的Captcha

我正在使用commonlibrary中的Captcha类(http://commonlibrarynet.codeplex.com/).我的代码工作和一切,但现在我正在尝试编写单元测试.

我的验证规则是:

 RuleFor(x => x.CaptchaUserInput)
            .NotEmpty()
            .Must((x, captchaUserInput) => Captcha.IsCorrect(captchaUserInput, x.CaptchaGeneratedText))
            .WithMessage("Invalid captcha code");
Run Code Online (Sandbox Code Playgroud)

在我的设置代码中,我尝试执行以下操作:

A.CallTo(() => Captcha.IsCorrect()).Returns(true);
Run Code Online (Sandbox Code Playgroud)

但是我收到以下错误消息:

SetUp : FakeItEasy.Configuration.FakeConfigurationException : 

The current proxy generator can not intercept the specified method for the following reason:
- Static methods can not be intercepted.


at FakeItEasy.Configuration.DefaultInterceptionAsserter.AssertThatMethodCanBeInterceptedOnInstance(Metho    dInfo method, Object callTarget)
at FakeItEasy.Configuration.FakeConfigurationManager.CallTo(Expression`1 callSpecification)
at ProdMaster.Hosts.Web.Tests.Unit.Controllers.AccountControllerTests.SetUp() in     AccountControllerTests.cs: line 44 
Run Code Online (Sandbox Code Playgroud)

所以问题实际上是如何使用FakeItEasy伪造静态方法.

TIA,

大卫

captcha unit-testing common-library fluentvalidation fakeiteasy

2
推荐指数
1
解决办法
1566
查看次数