public void RedirectResult_ThrowsIsTypeException_WhenIActionResultIsNotRedirectResult() { // Arrange var mockActionResult = new Mock <IActionResult>(MockBehavior.Strict); // Act & Assert Assert.Throws <IsTypeException>(() => MvcAssert.RedirectResult(mockActionResult.Object, "http://example.com")); }
public void RedirectResult_ThrowsEqualException_WhenUrlNotEqual() { // Arrange var redirectResult = new RedirectResult("http://example.com"); // Act & Assert Assert.Throws <EqualException>( () => MvcAssert.RedirectResult( redirectResult, "http://other.example.com" ) ); }
public void RedirectResult_ReturnRedirectResult() { // Arrange var redirectResult = new RedirectResult("http://example.com"); // Act & Assert var result = Assert.IsType <RedirectResult>( MvcAssert.RedirectResult( redirectResult, "http://example.com" ) ); Assert.Equal(redirectResult, result); }
public void RedirectToLocal_Success(string returnUrl, bool isLocalUrl, string actionName, string controllerName) { // Arrange var mockUrlHelper = new Mock <IUrlHelper>(MockBehavior.Strict); mockUrlHelper .Setup(x => x.IsLocalUrl(returnUrl)) .Returns(isLocalUrl) .Verifiable(); _mockController.Object.Url = mockUrlHelper.Object; if (_mockController.Object.Url.IsLocalUrl(returnUrl)) { _mockController .Setup(x => x.Redirect(returnUrl)) .Returns(() => new RedirectResult(returnUrl)) .Verifiable(); } else { _mockController .Setup(x => x.RedirectToAction(actionName, controllerName)) .Returns(() => new RedirectToActionResult(actionName, controllerName, null)) .Verifiable(); } // Act var actionResult = _mockController.Object.RedirectToLocal(returnUrl, actionName, controllerName); // Assert mockUrlHelper.Verify(); _mockController.Verify(); if (_mockController.Object.Url.IsLocalUrl(returnUrl)) { MvcAssert.RedirectResult(actionResult, returnUrl); } else { MvcAssert.RedirectToActionResult(actionResult, actionName, controllerName); } }