3

一直在玩 AutoMocking。

使用 moq.contrib.indy 调用控制器时出现以下错误

{"值不能为空。\r\n参数名称:controllerContext"}

var mocks = new AutoMockContainer(new MockRepository(MockBehavior.Loose));
mocks.GetMock<IAccountService>().Setup(x => x.AddSweepstake(new AddSweepstakeViewModel()));
mocks.GetMock<IRepository<Account>>().Setup(x => x.SaveOrUpdate(new Account())).Returns(new Account()).Verifiable();

mocks.Create<AccountController>().AddSweepstake(new AddSweepstakeViewModel()); //fails on this line

通常会这样做

var context = new Mock<HttpContextBase>();

如何使用 AutoMocking 模拟控制器上下文?

4

0 回答 0