public void GetClientValidationRules_WithActionControllerArea_CallsUrlHelperWithExpectedValues() { // Arrange var attribute = new RemoteAttribute("Action", "Controller", "Test") { HttpMethod = "POST", }; var url = "/Test/Controller/Action"; var urlHelper = new MockUrlHelper(url, routeName: null); var context = GetValidationContext(urlHelper); // Act & Assert var rule = Assert.Single(attribute.GetClientValidationRules(context)); Assert.Equal("remote", rule.ValidationType); Assert.Equal("'Length' is invalid.", rule.ErrorMessage); Assert.Equal(3, rule.ValidationParameters.Count); Assert.Equal("*.Length", rule.ValidationParameters["additionalfields"]); Assert.Equal("POST", rule.ValidationParameters["type"]); Assert.Equal(url, rule.ValidationParameters["url"]); var routeDictionary = Assert.IsType <RouteValueDictionary>(urlHelper.RouteValues); Assert.Equal(3, routeDictionary.Count); Assert.Equal("Action", routeDictionary["action"] as string); Assert.Equal("Controller", routeDictionary["controller"] as string); Assert.Equal("Test", routeDictionary["area"] as string); }
public void GetClientValidationRules_WithActionController_NoController_Throws() { // Arrange var attribute = new RemoteAttribute("Action", "Controller"); var context = GetValidationContextWithNoController(); // Act & Assert var exception = Assert.Throws <InvalidOperationException>(() => attribute.GetClientValidationRules(context)); Assert.Equal("No URL for remote validation could be found.", exception.Message); }
public void GetClientValidationRules_WithBadRouteName_Throws() { // Arrange var attribute = new RemoteAttribute("nonexistentRoute"); var context = GetValidationContextWithArea(currentArea: null); // Act & Assert var exception = Assert.Throws <InvalidOperationException>(() => attribute.GetClientValidationRules(context)); Assert.Equal("No URL for remote validation could be found.", exception.Message); }
public void GetClientValidationRules_WithActionControllerAreaInArea_FindsControllerInDifferentArea() { // Arrange var attribute = new RemoteAttribute("Action", "Controller", "AnotherArea"); var context = GetValidationContextWithArea(currentArea: "Test"); // Act & Assert var rule = Assert.Single(attribute.GetClientValidationRules(context)); Assert.Equal("remote", rule.ValidationType); Assert.Equal("'Length' is invalid.", rule.ErrorMessage); Assert.Equal(2, rule.ValidationParameters.Count); Assert.Equal("*.Length", rule.ValidationParameters["additionalfields"]); Assert.Equal("/AnotherArea/Controller/Action", rule.ValidationParameters["url"]); }
public void GetClientValidationRules_WithActionControllerArea_FindsControllerInRootArea(string areaName) { // Arrange var attribute = new RemoteAttribute("Action", "Controller", areaName); var context = GetValidationContextWithArea(currentArea: null); // Act & Assert var rule = Assert.Single(attribute.GetClientValidationRules(context)); Assert.Equal("remote", rule.ValidationType); Assert.Equal("'Length' is invalid.", rule.ErrorMessage); Assert.Equal(2, rule.ValidationParameters.Count); Assert.Equal("*.Length", rule.ValidationParameters["additionalfields"]); Assert.Equal("/UrlEncode[[Controller]]/UrlEncode[[Action]]", rule.ValidationParameters["url"]); }
public void GetClientValidationRules_WithRoute_CallsUrlHelperWithExpectedValues() { // Arrange var routeName = "RouteName"; var attribute = new RemoteAttribute(routeName); var url = "/my/URL"; var urlHelper = new MockUrlHelper(url, routeName); var context = GetValidationContext(urlHelper); // Act & Assert var rule = Assert.Single(attribute.GetClientValidationRules(context)); Assert.Equal("remote", rule.ValidationType); Assert.Equal("'Length' is invalid.", rule.ErrorMessage); Assert.Equal(2, rule.ValidationParameters.Count); Assert.Equal("*.Length", rule.ValidationParameters["additionalfields"]); Assert.Equal(url, rule.ValidationParameters["url"]); var routeDictionary = Assert.IsType <RouteValueDictionary>(urlHelper.RouteValues); Assert.Empty(routeDictionary); }
public void GetClientValidationRules_WithActionControllerArea_CallsUrlHelperWithExpectedValues() { // Arrange var attribute = new RemoteAttribute("Action", "Controller", "Test") { HttpMethod = "POST", }; var url = "/Test/Controller/Action"; var urlHelper = new MockUrlHelper(url, routeName: null); var context = GetValidationContext(urlHelper); // Act & Assert var rule = Assert.Single(attribute.GetClientValidationRules(context)); Assert.Equal("remote", rule.ValidationType); Assert.Equal("'Length' is invalid.", rule.ErrorMessage); Assert.Equal(3, rule.ValidationParameters.Count); Assert.Equal("*.Length", rule.ValidationParameters["additionalfields"]); Assert.Equal("POST", rule.ValidationParameters["type"]); Assert.Equal(url, rule.ValidationParameters["url"]); var routeDictionary = Assert.IsType<RouteValueDictionary>(urlHelper.RouteValues); Assert.Equal(3, routeDictionary.Count); Assert.Equal("Action", routeDictionary["action"] as string); Assert.Equal("Controller", routeDictionary["controller"] as string); Assert.Equal("Test", routeDictionary["area"] as string); }
public void GetClientValidationRules_WithRoute_CallsUrlHelperWithExpectedValues() { // Arrange var routeName = "RouteName"; var attribute = new RemoteAttribute(routeName); var url = "/my/URL"; var urlHelper = new MockUrlHelper(url, routeName); var context = GetValidationContext(urlHelper); // Act & Assert var rule = Assert.Single(attribute.GetClientValidationRules(context)); Assert.Equal("remote", rule.ValidationType); Assert.Equal("'Length' is invalid.", rule.ErrorMessage); Assert.Equal(2, rule.ValidationParameters.Count); Assert.Equal("*.Length", rule.ValidationParameters["additionalfields"]); Assert.Equal(url, rule.ValidationParameters["url"]); var routeDictionary = Assert.IsType<RouteValueDictionary>(urlHelper.RouteValues); Assert.Empty(routeDictionary); }
public void GetClientValidationRules_WithActionController_NoController_Throws() { // Arrange var attribute = new RemoteAttribute("Action", "Controller"); var context = GetValidationContextWithNoController(); // Act & Assert var exception = Assert.Throws<InvalidOperationException>(() => attribute.GetClientValidationRules(context)); Assert.Equal("No URL for remote validation could be found.", exception.Message); }
public void GetClientValidationRules_WithBadRouteName_Throws() { // Arrange var attribute = new RemoteAttribute("nonexistentRoute"); var context = GetValidationContextWithArea(currentArea: null); // Act & Assert var exception = Assert.Throws<InvalidOperationException>(() => attribute.GetClientValidationRules(context)); Assert.Equal("No URL for remote validation could be found.", exception.Message); }