public void GetUrlWithValuesThatAreCompletelyDifferentFromTheCurrentRouteAsSecondRoute() { // Arrange HttpContext context = GetHttpContext("/app", null, null); IRouteCollection rt = new DefaultRouteCollection(); rt.Add(CreateRoute("{controller}/{action}/{id}")); rt.Add(CreateRoute("date/{y}/{m}/{d}")); var rd = CreateRouteData(); rd.Values.Add("controller", "home"); rd.Values.Add("action", "dostuff"); var values = CreateDispatcherValueCollection(); values.Add("y", "2007"); values.Add("m", "08"); values.Add("d", "12"); // Act var vpd = rt.GetVirtualPath(context, values); // Assert Assert.NotNull(vpd); Assert.Equal <string>("/app/date/2007/08/12", vpd.VirtualPath); }
public void GetUrlAppliesConstraintsRulesToChooseRoute() { // Arrange var rd = CreateRouteData(); rd.Values.Add("controller", "Home"); rd.Values.Add("action", "Index"); rd.Values.Add("id", null); IRouteCollection rc = new DefaultRouteCollection(); rc.Add(CreateRoute( "foo.mvc/{action}", new DispatcherValueCollection(new { controller = "Home" }), new DispatcherValueCollection(new { controller = "Home", action = "Contact", httpMethod = CreateHttpMethodConstraint("get") }))); rc.Add(CreateRoute( "{controller}.mvc/{action}", new DispatcherValueCollection(new { action = "Index" }), new DispatcherValueCollection(new { controller = "Home", action = "(Index|About)", httpMethod = CreateHttpMethodConstraint("post") }))); var values = CreateDispatcherValueCollection(); values.Add("Action", "Index"); // Act var vpd = rc.GetVirtualPath(GetHttpContext("/app1", "", ""), values); // Assert Assert.NotNull(vpd); Assert.Equal <string>("/app1/Home.mvc", vpd.VirtualPath); }
public void GetUrlWithNoChangedValuesShouldProduceSameUrl() { // Arrange var rd = CreateRouteData(); rd.Values.Add("controller", "Home"); rd.Values.Add("action", "Index"); rd.Values.Add("id", null); IRouteCollection rc = new DefaultRouteCollection(); rc.Add(CreateRoute("{controller}.mvc/{action}/{id}", new DispatcherValueCollection(new { action = "Index", id = (string)null }))); rc.Add(CreateRoute("{controller}/{action}/{id}", new DispatcherValueCollection(new { action = "Index", id = (string)null }))); var values = CreateDispatcherValueCollection(); values.Add("Action", "Index"); // Act var vpd = rc.GetVirtualPath(GetHttpContext("/app1", "", ""), values); // Assert Assert.NotNull(vpd); Assert.Equal <string>("/app1/Home.mvc", vpd.VirtualPath); }
public void GetUrlWithRouteThatHasDifferentControllerCaseShouldStillMatch() { // Arrange var rd = CreateRouteData(); rd.Values.Add("controller", "Bar"); rd.Values.Add("action", "bbb"); rd.Values.Add("id", null); IRouteCollection rc = new DefaultRouteCollection(); rc.Add(CreateRoute("PrettyFooUrl", new DispatcherValueCollection(new { controller = "Foo", action = "aaa", id = (string)null }))); rc.Add(CreateRoute("PrettyBarUrl", new DispatcherValueCollection(new { controller = "Bar", action = "bbb", id = (string)null }))); rc.Add(CreateRoute("{controller}/{action}/{id}", new DispatcherValueCollection(new { action = "Index", id = (string)null }))); var values = CreateDispatcherValueCollection(); values.Add("Action", "aaa"); values.Add("Controller", "foo"); // Act var vpd = rc.GetVirtualPath(GetHttpContext("/app1", "", ""), values); // Assert Assert.NotNull(vpd); Assert.Equal <string>("/app1/PrettyFooUrl", vpd.VirtualPath); }
public void GetUrlShouldValidateOnlyAcceptedParametersAndUserDefaultValuesForInvalidatedParameters() { // Arrange var rd = CreateRouteData(); rd.Values.Add("Controller", "UrlRouting"); rd.Values.Add("Name", "MissmatchedValidateParams"); rd.Values.Add("action", "MissmatchedValidateParameters2"); rd.Values.Add("ValidateParam1", "special1"); rd.Values.Add("ValidateParam2", "special2"); IRouteCollection rc = new DefaultRouteCollection(); rc.Add(CreateRoute( "UrlConstraints/Validation.mvc/Input5/{action}/{ValidateParam1}/{ValidateParam2}", new DispatcherValueCollection(new { Controller = "UrlRouting", Name = "MissmatchedValidateParams", ValidateParam2 = "valid" }), new DispatcherValueCollection(new { ValidateParam1 = "valid.*", ValidateParam2 = "valid.*" }))); rc.Add(CreateRoute( "UrlConstraints/Validation.mvc/Input5/{action}/{ValidateParam1}/{ValidateParam2}", new DispatcherValueCollection(new { Controller = "UrlRouting", Name = "MissmatchedValidateParams" }), new DispatcherValueCollection(new { ValidateParam1 = "special.*", ValidateParam2 = "special.*" }))); var values = CreateDispatcherValueCollection(); values.Add("Name", "MissmatchedValidateParams"); values.Add("ValidateParam1", "valid1"); // Act var vpd = rc.GetVirtualPath(GetHttpContext("/app1", "", ""), values); // Assert Assert.NotNull(vpd); Assert.Equal <string>("/app1/UrlConstraints/Validation.mvc/Input5/MissmatchedValidateParameters2/valid1", vpd.VirtualPath); }
public void GetUrlWithRouteThatHasExtensionWithSubsequentDefaultValueIncludesExtensionButNotDefaultValue() { // Arrange var rd = CreateRouteData(); rd.Values.Add("controller", "Bank"); rd.Values.Add("action", "MakeDeposit"); rd.Values.Add("accountId", "7770"); IRouteCollection rc = new DefaultRouteCollection(); rc.Add(CreateRoute( "{controller}.mvc/Deposit/{accountId}", new RouteValueDictionary(new { Action = "DepositView" }))); // Note: This route was in the original bug, but it turns out that this behavior is incorrect. With the // recent fix to Route (in this changelist) this route would have been selected since we have values for // all three required parameters. //rc.Add(new Route { // Url = "{controller}.mvc/{action}/{accountId}", // RouteHandler = new DummyRouteHandler() //}); // This route should be chosen because the requested action is List. Since the default value of the action // is List then the Action should not be in the URL. However, the file extension should be included since // it is considered "safe." rc.Add(CreateRoute( "{controller}.mvc/{action}", new RouteValueDictionary(new { Action = "List" }))); var values = CreateRouteValueDictionary(); values.Add("Action", "List"); // Act var vpd = rc.GetVirtualPath(GetHttpContext("/app1", "", ""), values); // Assert Assert.NotNull(vpd); Assert.Equal <string>("/app1/Bank.mvc", vpd.VirtualPath); }
public void GetUrlWithValuesThatAreCompletelyDifferentFromTheCurrentRouteAsSecondRoute() { // Arrange HttpContext context = GetHttpContext("/app", null, null); IRouteCollection rt = new DefaultRouteCollection(); rt.Add(CreateRoute("{controller}/{action}/{id}")); rt.Add(CreateRoute("date/{y}/{m}/{d}")); var rd = CreateRouteData(); rd.Values.Add("controller", "home"); rd.Values.Add("action", "dostuff"); var values = CreateRouteValueDictionary(); values.Add("y", "2007"); values.Add("m", "08"); values.Add("d", "12"); // Act var vpd = rt.GetVirtualPath(context, values); // Assert Assert.NotNull(vpd); Assert.Equal<string>("/app/date/2007/08/12", vpd.VirtualPath); }
public void GetUrlAppliesConstraintsRulesToChooseRoute() { // Arrange var rd = CreateRouteData(); rd.Values.Add("controller", "Home"); rd.Values.Add("action", "Index"); rd.Values.Add("id", null); IRouteCollection rc = new DefaultRouteCollection(); rc.Add(CreateRoute( "foo.mvc/{action}", new RouteValueDictionary(new { controller = "Home" }), new RouteValueDictionary(new { controller = "Home", action = "Contact", httpMethod = CreateHttpMethodConstraint("get") }))); rc.Add(CreateRoute( "{controller}.mvc/{action}", new RouteValueDictionary(new { action = "Index" }), new RouteValueDictionary(new { controller = "Home", action = "(Index|About)", httpMethod = CreateHttpMethodConstraint("post") }))); var values = CreateRouteValueDictionary(); values.Add("Action", "Index"); // Act var vpd = rc.GetVirtualPath(GetHttpContext("/app1", "", ""), values); // Assert Assert.NotNull(vpd); Assert.Equal<string>("/app1/Home.mvc", vpd.VirtualPath); }
public void GetUrlWithNoChangedValuesShouldProduceSameUrl() { // Arrange var rd = CreateRouteData(); rd.Values.Add("controller", "Home"); rd.Values.Add("action", "Index"); rd.Values.Add("id", null); IRouteCollection rc = new DefaultRouteCollection(); rc.Add(CreateRoute("{controller}.mvc/{action}/{id}", new RouteValueDictionary(new { action = "Index", id = (string)null }))); rc.Add(CreateRoute("{controller}/{action}/{id}", new RouteValueDictionary(new { action = "Index", id = (string)null }))); var values = CreateRouteValueDictionary(); values.Add("Action", "Index"); // Act var vpd = rc.GetVirtualPath(GetHttpContext("/app1", "", ""), values); // Assert Assert.NotNull(vpd); Assert.Equal<string>("/app1/Home.mvc", vpd.VirtualPath); }
public void GetUrlWithRouteThatHasDifferentControllerCaseShouldStillMatch() { // Arrange var rd = CreateRouteData(); rd.Values.Add("controller", "Bar"); rd.Values.Add("action", "bbb"); rd.Values.Add("id", null); IRouteCollection rc = new DefaultRouteCollection(); rc.Add(CreateRoute("PrettyFooUrl", new RouteValueDictionary(new { controller = "Foo", action = "aaa", id = (string)null }))); rc.Add(CreateRoute("PrettyBarUrl", new RouteValueDictionary(new { controller = "Bar", action = "bbb", id = (string)null }))); rc.Add(CreateRoute("{controller}/{action}/{id}", new RouteValueDictionary(new { action = "Index", id = (string)null }))); var values = CreateRouteValueDictionary(); values.Add("Action", "aaa"); values.Add("Controller", "foo"); // Act var vpd = rc.GetVirtualPath(GetHttpContext("/app1", "", ""), values); // Assert Assert.NotNull(vpd); Assert.Equal<string>("/app1/PrettyFooUrl", vpd.VirtualPath); }
public void GetUrlWithRouteThatHasExtensionWithSubsequentDefaultValueIncludesExtensionButNotDefaultValue() { // Arrange var rd = CreateRouteData(); rd.Values.Add("controller", "Bank"); rd.Values.Add("action", "MakeDeposit"); rd.Values.Add("accountId", "7770"); IRouteCollection rc = new DefaultRouteCollection(); rc.Add(CreateRoute( "{controller}.mvc/Deposit/{accountId}", new RouteValueDictionary(new { Action = "DepositView" }))); // Note: This route was in the original bug, but it turns out that this behavior is incorrect. With the // recent fix to Route (in this changelist) this route would have been selected since we have values for // all three required parameters. //rc.Add(new Route { // Url = "{controller}.mvc/{action}/{accountId}", // RouteHandler = new DummyRouteHandler() //}); // This route should be chosen because the requested action is List. Since the default value of the action // is List then the Action should not be in the URL. However, the file extension should be included since // it is considered "safe." rc.Add(CreateRoute( "{controller}.mvc/{action}", new RouteValueDictionary(new { Action = "List" }))); var values = CreateRouteValueDictionary(); values.Add("Action", "List"); // Act var vpd = rc.GetVirtualPath(GetHttpContext("/app1", "", ""), values); // Assert Assert.NotNull(vpd); Assert.Equal<string>("/app1/Bank.mvc", vpd.VirtualPath); }
public void GetUrlShouldValidateOnlyAcceptedParametersAndUserDefaultValuesForInvalidatedParameters() { // Arrange var rd = CreateRouteData(); rd.Values.Add("Controller", "UrlRouting"); rd.Values.Add("Name", "MissmatchedValidateParams"); rd.Values.Add("action", "MissmatchedValidateParameters2"); rd.Values.Add("ValidateParam1", "special1"); rd.Values.Add("ValidateParam2", "special2"); IRouteCollection rc = new DefaultRouteCollection(); rc.Add(CreateRoute( "UrlConstraints/Validation.mvc/Input5/{action}/{ValidateParam1}/{ValidateParam2}", new RouteValueDictionary(new { Controller = "UrlRouting", Name = "MissmatchedValidateParams", ValidateParam2 = "valid" }), new RouteValueDictionary(new { ValidateParam1 = "valid.*", ValidateParam2 = "valid.*" }))); rc.Add(CreateRoute( "UrlConstraints/Validation.mvc/Input5/{action}/{ValidateParam1}/{ValidateParam2}", new RouteValueDictionary(new { Controller = "UrlRouting", Name = "MissmatchedValidateParams" }), new RouteValueDictionary(new { ValidateParam1 = "special.*", ValidateParam2 = "special.*" }))); var values = CreateRouteValueDictionary(); values.Add("Name", "MissmatchedValidateParams"); values.Add("ValidateParam1", "valid1"); // Act var vpd = rc.GetVirtualPath(GetHttpContext("/app1", "", ""), values); // Assert Assert.NotNull(vpd); Assert.Equal<string>("/app1/UrlConstraints/Validation.mvc/Input5/MissmatchedValidateParameters2/valid1", vpd.VirtualPath); }