public void ChallengeResult_ReturnChallengeResult() { // Arrange var authenticationProperties = new AuthenticationProperties(new AttributeDictionary { { "TestKey", "TestValue" } }); var challengeResult = new ChallengeResult { Properties = authenticationProperties, AuthenticationSchemes = new List <string> { "TestProvider" } }; // Act & Assert var result = Assert.IsType <ChallengeResult>( MvcAssert.ChallengeResult( challengeResult, authenticationProperties, "TestProvider" ) ); Assert.Equal(challengeResult, result); }
public void ViewResult_ThrowsIsTypeException_WhenIActionResultIsNotViewResult() { // Arrange var mockActionResult = new Mock <IActionResult>(MockBehavior.Strict); // Act & Assert Assert.Throws <IsTypeException>(() => MvcAssert.ViewResult(mockActionResult.Object)); }
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 DisplaysLoginScreenWhenCredentialsArentValid() { var credentials = new Credentials(); var controller = new HomeController(null, null); controller.ModelState.AddModelError(string.Empty, string.Empty); MvcAssert.DefaultViewWithModel(credentials, controller.Login(credentials)); }
public void JsonResult_ThrowsAssertActualExpectedException_WhenValueNotEqual() { // Arrange var jsonResult = new JsonResult(new { Value = "TestValue" }); // Act & Assert Assert.Throws <AssertActualExpectedException>(() => MvcAssert.JsonResult(jsonResult, new { OtherValue = "TestValue" })); }
public void JsonResult_ThrowsIsTypeException_WhenIActionResultIsNotJsonResult() { // Arrange var mockActionResult = new Mock <IActionResult>(MockBehavior.Strict); // Act & Assert Assert.Throws <IsTypeException>(() => MvcAssert.JsonResult(mockActionResult.Object, new { Value = "TestValue" })); }
public void ChallengeResult_ThrowsIsTypeException_WhenIActionResultIsNotChallengeResult() { // Arrange var mockActionResult = new Mock <IActionResult>(MockBehavior.Strict); // Act & Assert Assert.Throws <IsTypeException>(() => MvcAssert.ChallengeResult(mockActionResult.Object, new AuthenticationProperties(), "TestProvider")); }
public void ViewResult_ReturnViewResult() { // Arrange var viewResult = new ViewResult(); // Act & Assert var result = Assert.IsType <ViewResult>(MvcAssert.ViewResult(viewResult)); Assert.Equal(viewResult, result); }
public void ReturnsWithValidationErrors() { var user = new User(); var controller = new HomeController(null, null); controller.ModelState.AddModelError(string.Empty, string.Empty); var result = controller.Register(user); MvcAssert.DefaultViewWithModel(user, result); }
public void JsonResult_ReturnJsonResult() { // Arrange var jsonResult = new JsonResult(new { Value = "TestValue" }); // Act & Assert var result = Assert.IsType <JsonResult>(MvcAssert.JsonResult(jsonResult, new { Value = "TestValue" })); Assert.Equal(jsonResult, result); }
public void ViewResult_ThrowsEqualException_WhenViewNameNotEqual() { // Arrange var viewResult = new ViewResult { ViewName = "Index" }; // Act & Assert Assert.Throws <EqualException>(() => MvcAssert.ViewResult(viewResult, "NotIndex")); }
public void ReturnsDefaultViewWithSummary() { var repository = Dynamic <IUserRepository>(); var expected = new PagedList <User>(); var controller = new ManageController(repository); repository.Stub(r => r.GetUserList(Arg <Pager> .Is.Anything)).Return(expected); ReplayAll(); MvcAssert.DefaultViewWithModel(expected, controller.Index(0)); }
public void DisplaysLoginScreenUsersCantBeFound() { var repository = Dynamic <IUserRepository>(); var credentials = new Credentials(); var controller = new HomeController(null, repository); repository.Stub(r => r.FindByCredentials(Arg <Credentials> .Is.Anything)).Return(null); ReplayAll(); MvcAssert.DefaultViewWithModel(credentials, controller.Login(credentials)); }
public void RendersViewWithUserModel() { var repository = Dynamic <IUserRepository>(); var user = new User(); var controller = new ManageController(repository); repository.Expect(r => r.Find <User>(85)).Return(user); ReplayAll(); MvcAssert.DefaultViewWithModel(user, controller.View(85)); repository.VerifyAllExpectations(); }
public void RedirectToActionResult_ThrowsEqualException_WhenActionNameNotEqual() { // Arrange var redirectToActionResult = new RedirectToActionResult("Index", null, null); // Act & Assert Assert.Throws <EqualException>( () => MvcAssert.RedirectToActionResult( redirectToActionResult, "NotIndex" ) ); }
public void Index_WhenHostingEnvironmentIsDevelopment_ReturnViewResult() { // Arrange var controller = new HomeController(new NullLogger <HomeController>(), new HostingEnvironment { EnvironmentName = "Development" }); // Act var actionResult = controller.Index(); // Assert MvcAssert.ViewResult(actionResult); }
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 ViewResult_ThrowsAssertActualExpectedException_WhenModelNotEqual() { // Arrange var viewResult = new ViewResult { ViewData = new ViewDataDictionary(new EmptyModelMetadataProvider(), new ModelStateDictionary()) { Model = new { Value = "TestValue" } } }; // Act & Assert Assert.Throws <AssertActualExpectedException>(() => MvcAssert.ViewResult(viewResult, null, new { OtherValue = "TestValue" })); }
public void RedirectsAuthenticatedUserToManager() { var repository = Dynamic <IUserRepository>(); var authenticator = Dynamic <IAuthenticationManager>(); var credentials = new Credentials { Email = "*****@*****.**", Password = "******" }; var controller = new HomeController(authenticator, repository); repository.Stub(r => r.FindByCredentials(credentials)).Return(new User()); authenticator.Stub(e => e.SetAuthenticationToken(Arg <int> .Is.Anything)); ReplayAll(); MvcAssert.RedirectTo("/Manage/Index", controller.Login(credentials)); }
public void DisplaysSuccessView() { var user = new User { Credentials = new Credentials { Email = "*****@*****.**" } }; var repository = Dynamic <IUserRepository>(); var controller = new HomeController(null, repository); repository.Stub(r => r.Save(user)); ReplayAll(); MvcAssert.ViewName("RegistrationSuccessful", controller.Register(user)); }
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 ModelState_IsValid_WhenErrorsEmpty() { // Arrange var viewResult = new ViewResult { ViewData = new ViewDataDictionary(new EmptyModelMetadataProvider(), new ModelStateDictionary()) }; // Act & Assert var result = Assert.IsType <ModelStateDictionary>( MvcAssert.ModelState( viewResult, new List <KeyValuePair <string, string> >() ) ); Assert.Equal(viewResult.ViewData.ModelState, result); }
public void RedirectToActionResult_ThrowsEqualException_WhenRouteValuesNotEqual() { // Arrange var redirectToActionResult = new RedirectToActionResult("Index", "Home", new { ReturnUrl = "ReturnUrl" }); // Act & Assert Assert.Throws <EqualException>( () => MvcAssert.RedirectToActionResult( redirectToActionResult, "Index", "Home", new List <KeyValuePair <string, object> > { new KeyValuePair <string, object>("ReturnUrl", "NotReturnUrl") } ) ); }
public void ChallengeResult_ThrowsEqualException_WhenAuthenticationPropertiesNotEqual() { // Arrange var challengeResult = new ChallengeResult(new AuthenticationProperties(new AttributeDictionary { { "TestKey", "TestValue" } })); // Act & Assert Assert.Throws <EqualException>( () => MvcAssert.ChallengeResult( challengeResult, new AuthenticationProperties(new AttributeDictionary { { "TestKey", "OtherTestValue" } }), "TestProvider" ) ); }
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); } }
public void Index_WhenHostingEnvironmentIsNotDevelopment_RedirectToActionResult(string returnUrl) { // Arrange var controller = new HomeController(new NullLogger <HomeController>(), new HostingEnvironment()); // Act var actionResult = controller.Index(returnUrl); // Assert MvcAssert.RedirectToActionResult( actionResult, "Index", "SignIn", new List <KeyValuePair <string, object> > { new KeyValuePair <string, object>("ReturnUrl", returnUrl) } ); }
public void RedirectToActionResult_ReturnRedirectToActionResult() { // Arrange var redirectToActionResult = new RedirectToActionResult("Index", "Home", new { ReturnUrl = "ReturnUrl" }); // Act & Assert var result = Assert.IsType <RedirectToActionResult>( MvcAssert.RedirectToActionResult( redirectToActionResult, "Index", "Home", new List <KeyValuePair <string, object> > { new KeyValuePair <string, object>("ReturnUrl", "ReturnUrl") } ) ); Assert.Equal(redirectToActionResult, result); }
public void ModelState_WithKeyValue_ReturnModelState() { // Arrange var viewResult = new ViewResult { ViewData = new ViewDataDictionary(new EmptyModelMetadataProvider(), new ModelStateDictionary()) }; viewResult.ViewData.ModelState.AddModelError("ErrorKey", "ErrorMessage"); // Act & Assert var result = Assert.IsType <ModelStateDictionary>( MvcAssert.ModelState( viewResult, "ErrorKey", "ErrorMessage" ) ); Assert.Equal(viewResult.ViewData.ModelState, result); }
public void ViewData_WithKeyValue_ReturnViewData() { // Arrange var viewResult = new ViewResult { ViewData = new ViewDataDictionary(new EmptyModelMetadataProvider(), new ModelStateDictionary()) { new KeyValuePair <string, object>("TestKey", "TestValue") } }; // Act & Assert var result = Assert.IsType <ViewDataDictionary>( MvcAssert.ViewData( viewResult, "TestKey", "TestValue" ) ); Assert.Equal(viewResult.ViewData, result); }
public void ViewData_ThrowsEqualException_WhenViewDataNotEqual() { // Arrange var viewResult = new ViewResult { ViewData = new ViewDataDictionary(new EmptyModelMetadataProvider(), new ModelStateDictionary()) { new KeyValuePair <string, object>("TestKey", "TestValue") } }; // Act & Assert Assert.Throws <EqualException>( () => MvcAssert.ViewData( viewResult, new List <KeyValuePair <string, object> > { new KeyValuePair <string, object>("TestKey", "OtherTestValue") } ) ); }