我要测试下一个控制器:
public ActionResult Approve(UpdateBalanceCommand input)
{
return TryPush(input, setting => setting.SuccessResult = () => Redirect(Url.Action("Index", "Home").SetHash(Url.Action("Index", "Payment"))));
}
如何测试命令是否已通过必要设置执行?
Sincerelly, 安东。
答案 0 :(得分:4)
请像这样使用
Establish establish = () =>
{
command = Pleasure.Generator.Invent<UpdateBalanceCommand >();
mockController = MockController<SomeController>
.When();
};
Because of = () => { result = mockController.Original.Approve(command); };
It should_be_push = () => mockController.ShouldBePush(command);
It should_be_result = () => result.ShouldBeRedirect("your url");
答案 1 :(得分:3)
见下面的工作解决方案
Establish establish = () =>
{
_command = Pleasure.Generator.Invent<UpdateBalanceCommand>();
_paymentController = MockController<PaymentController>.When()
.StubUrlAction("/")
.StubUrlAction("/Payment");
};
Because of = () => _result = _paymentController.Original.Approve(_command);
It should_push_command = () => _paymentController.ShouldBePush(_command);
It should_be_redirect = () => _result.ShouldBeRedirect("/#!Payment?");