我有以下情况

if (_ldapAuthentication.IsAuthenticated (Domain, login.username, login.PassWord))
{
    _ldapAuthentication.LogOn (indexViewModel.UserName, false);
    _authenticationService.LimpaTentativas (login.username);
    return RedirectToAction ("Index", "Main");
}

是的,它重定向到另一页..什么是最好的测试?

最佳答案

在单元测试中,您只需对 Controller 返回的ActionResult进行断言。

//Arrange
var controller = new ControllerUnderTest(
                        mockLdap,
                        mockAuthentication
                     );

// Mock/stub your ldap behaviour here, setting up
// the correct return value for 'IsAuthenticated'.

//Act
RedirectResult redirectResult =
     (RedirectResult) controller.ActionYouAreTesting();

//Assert
Assert.That( redirectResult.Url, Is.EqualTo("/Main/Index"));

关于asp.net-mvc - 测试RedirectToAction的最佳方法是什么?,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/7601972/

10-11 04:01