PageRenderTime 150ms CodeModel.GetById 20ms RepoModel.GetById 1ms app.codeStats 0ms

/test/System.Web.Mvc.Test/Html/Test/LinkExtensionsTest.cs

https://bitbucket.org/mdavid/aspnetwebstack
C# | 562 lines | 310 code | 118 blank | 134 comment | 0 complexity | 81fe94bddf3641834e6557e9c838d5e1 MD5 | raw file
  1. using System.Web.Routing;
  2. using Microsoft.Web.UnitTestUtil;
  3. using Xunit;
  4. using Assert = Microsoft.TestCommon.AssertEx;
  5. namespace System.Web.Mvc.Html.Test
  6. {
  7. public class LinkExtensionsTest
  8. {
  9. private const string AppPathModifier = MvcHelper.AppPathModifier;
  10. [Fact]
  11. public void ActionLink()
  12. {
  13. // Arrange
  14. HtmlHelper htmlHelper = MvcHelper.GetHtmlHelper();
  15. // Act
  16. MvcHtmlString html = htmlHelper.ActionLink("linktext", "newaction");
  17. // Assert
  18. Assert.Equal(@"<a href=""" + AppPathModifier + @"/app/home/newaction"">linktext</a>", html.ToHtmlString());
  19. }
  20. [Fact]
  21. public void ActionLinkDictionaryOverridesImplicitValues()
  22. {
  23. // Arrange
  24. HtmlHelper htmlHelper = MvcHelper.GetHtmlHelper();
  25. // Act
  26. MvcHtmlString html = htmlHelper.ActionLink("linktext", "newaction", null, new { href = "http://foo.com" });
  27. // Assert
  28. Assert.Equal(@"<a href=""http://foo.com"">linktext</a>", html.ToHtmlString());
  29. }
  30. [Fact]
  31. public void ActionLinkExplictValuesOverrideDictionary()
  32. {
  33. // Arrange
  34. HtmlHelper htmlHelper = MvcHelper.GetHtmlHelper();
  35. // Act
  36. MvcHtmlString html = htmlHelper.ActionLink("linktext", "explicitAction", new { action = "dictionaryAction" }, null);
  37. // Assert
  38. Assert.Equal(@"<a href=""" + AppPathModifier + @"/app/home/explicitAction"">linktext</a>", html.ToHtmlString());
  39. }
  40. [Fact(Skip = "External bug DevDiv 356125 -- does not work correctly on 4.5")]
  41. public void ActionLinkParametersNeedEscaping()
  42. {
  43. // Arrange
  44. HtmlHelper htmlHelper = MvcHelper.GetHtmlHelper();
  45. // Act
  46. MvcHtmlString html = htmlHelper.ActionLink("linktext<&>\"", "new action<&>\"");
  47. // Assert
  48. Assert.Equal(@"<a href=""" + AppPathModifier + @"/app/home/new%20action%3C%26%3E%22"">linktext&lt;&amp;&gt;&quot;</a>", html.ToHtmlString());
  49. }
  50. [Fact]
  51. public void ActionLinkWithActionNameAndValueDictionary()
  52. {
  53. // Arrange
  54. HtmlHelper htmlHelper = MvcHelper.GetHtmlHelper();
  55. // Act
  56. MvcHtmlString html = htmlHelper.ActionLink("linktext", "newaction", new RouteValueDictionary(new { controller = "home2" }));
  57. // Assert
  58. Assert.Equal(@"<a href=""" + AppPathModifier + @"/app/home2/newaction"">linktext</a>", html.ToHtmlString());
  59. }
  60. [Fact]
  61. public void ActionLinkWithActionNameAndValueObject()
  62. {
  63. // Arrange
  64. HtmlHelper htmlHelper = MvcHelper.GetHtmlHelper();
  65. // Act
  66. MvcHtmlString html = htmlHelper.ActionLink("linktext", "newaction", new { controller = "home2" });
  67. // Assert
  68. Assert.Equal(@"<a href=""" + AppPathModifier + @"/app/home2/newaction"">linktext</a>", html.ToHtmlString());
  69. }
  70. [Fact]
  71. public void ActionLinkWithControllerName()
  72. {
  73. // Arrange
  74. HtmlHelper htmlHelper = MvcHelper.GetHtmlHelper();
  75. // Act
  76. MvcHtmlString html = htmlHelper.ActionLink("linktext", "newaction", "home2");
  77. // Assert
  78. Assert.Equal(@"<a href=""" + AppPathModifier + @"/app/home2/newaction"">linktext</a>", html.ToHtmlString());
  79. }
  80. [Fact]
  81. public void ActionLinkWithControllerNameAndDictionary()
  82. {
  83. // Arrange
  84. HtmlHelper htmlHelper = MvcHelper.GetHtmlHelper();
  85. // Act
  86. MvcHtmlString html = htmlHelper.ActionLink("linktext", "newaction", "home2", new RouteValueDictionary(new { id = "someid" }), new RouteValueDictionary(new { baz = "baz" }));
  87. // Assert
  88. Assert.Equal(@"<a baz=""baz"" href=""" + AppPathModifier + @"/app/home2/newaction/someid"">linktext</a>", html.ToHtmlString());
  89. }
  90. [Fact]
  91. public void ActionLinkWithControllerNameAndObjectProperties()
  92. {
  93. // Arrange
  94. HtmlHelper htmlHelper = MvcHelper.GetHtmlHelper();
  95. // Act
  96. MvcHtmlString html = htmlHelper.ActionLink("linktext", "newaction", "home2", new { id = "someid" }, new { baz = "baz" });
  97. // Assert
  98. Assert.Equal(@"<a baz=""baz"" href=""" + AppPathModifier + @"/app/home2/newaction/someid"">linktext</a>", html.ToHtmlString());
  99. }
  100. [Fact]
  101. public void ActionLinkWithControllerNameAndObjectPropertiesWithUnderscores()
  102. {
  103. // Arrange
  104. HtmlHelper htmlHelper = MvcHelper.GetHtmlHelper();
  105. // Act
  106. MvcHtmlString html = htmlHelper.ActionLink("linktext", "newaction", "home2", new { id = "someid" }, new { foo_baz = "baz" });
  107. // Assert
  108. Assert.Equal(@"<a foo-baz=""baz"" href=""" + AppPathModifier + @"/app/home2/newaction/someid"">linktext</a>", html.ToHtmlString());
  109. }
  110. [Fact]
  111. public void ActionLinkWithDictionary()
  112. {
  113. // Arrange
  114. HtmlHelper htmlHelper = MvcHelper.GetHtmlHelper();
  115. // Act
  116. MvcHtmlString html = htmlHelper.ActionLink("linktext", "newaction", new RouteValueDictionary(new { Controller = "home2", id = "someid" }), new RouteValueDictionary(new { baz = "baz" }));
  117. // Assert
  118. Assert.Equal(@"<a baz=""baz"" href=""" + AppPathModifier + @"/app/home2/newaction/someid"">linktext</a>", html.ToHtmlString());
  119. }
  120. [Fact]
  121. public void ActionLinkWithFragment()
  122. {
  123. // Arrange
  124. HtmlHelper htmlHelper = MvcHelper.GetHtmlHelper();
  125. // Act
  126. MvcHtmlString html = htmlHelper.ActionLink("linktext", "newaction", "home2", "http", "foo.bar.com", "foo", new { id = "someid" }, new { baz = "baz" });
  127. // Assert
  128. Assert.Equal(@"<a baz=""baz"" href=""http://foo.bar.com" + AppPathModifier + @"/app/home2/newaction/someid#foo"">linktext</a>", html.ToHtmlString());
  129. }
  130. [Fact]
  131. public void ActionLinkWithFragmentAndAttributesWithUnderscores()
  132. {
  133. // Arrange
  134. HtmlHelper htmlHelper = MvcHelper.GetHtmlHelper();
  135. // Act
  136. MvcHtmlString html = htmlHelper.ActionLink("linktext", "newaction", "home2", "http", "foo.bar.com", "foo", new { id = "someid" }, new { foo_baz = "baz" });
  137. // Assert
  138. Assert.Equal(@"<a foo-baz=""baz"" href=""http://foo.bar.com" + AppPathModifier + @"/app/home2/newaction/someid#foo"">linktext</a>", html.ToHtmlString());
  139. }
  140. [Fact]
  141. public void ActionLinkWithNullHostname()
  142. {
  143. // Arrange
  144. HtmlHelper htmlHelper = MvcHelper.GetHtmlHelper();
  145. // Act
  146. MvcHtmlString html = htmlHelper.ActionLink("linktext", "newaction", "home2", "https", null /* hostName */, "foo", new { id = "someid" }, new { baz = "baz" });
  147. // Assert
  148. Assert.Equal(@"<a baz=""baz"" href=""https://localhost" + AppPathModifier + @"/app/home2/newaction/someid#foo"">linktext</a>", html.ToHtmlString());
  149. }
  150. [Fact]
  151. public void ActionLinkWithNullProtocolAndFragment()
  152. {
  153. // Arrange
  154. HtmlHelper htmlHelper = MvcHelper.GetHtmlHelper();
  155. // Act
  156. MvcHtmlString html = htmlHelper.ActionLink("linktext", "newaction", "home2", null /* protocol */, "foo.bar.com", null /* fragment */, new { id = "someid" }, new { baz = "baz" });
  157. // Assert
  158. Assert.Equal(@"<a baz=""baz"" href=""http://foo.bar.com" + AppPathModifier + @"/app/home2/newaction/someid"">linktext</a>", html.ToHtmlString());
  159. }
  160. [Fact]
  161. public void ActionLinkWithNullProtocolNullHostNameAndNullFragment()
  162. {
  163. // Arrange
  164. HtmlHelper htmlHelper = MvcHelper.GetHtmlHelper();
  165. // Act
  166. MvcHtmlString html = htmlHelper.ActionLink("linktext", "newaction", "home2", null /* protocol */, null /* hostName */, null /* fragment */, new { id = "someid" }, new { baz = "baz" });
  167. // Assert
  168. Assert.Equal(@"<a baz=""baz"" href=""" + AppPathModifier + @"/app/home2/newaction/someid"">linktext</a>", html.ToHtmlString());
  169. }
  170. [Fact]
  171. public void ActionLinkWithObjectProperties()
  172. {
  173. // Arrange
  174. HtmlHelper htmlHelper = MvcHelper.GetHtmlHelper();
  175. // Act
  176. MvcHtmlString html = htmlHelper.ActionLink("linktext", "newaction", new { Controller = "home2", id = "someid" }, new { baz = "baz" });
  177. // Assert
  178. Assert.Equal(@"<a baz=""baz"" href=""" + AppPathModifier + @"/app/home2/newaction/someid"">linktext</a>", html.ToHtmlString());
  179. }
  180. [Fact]
  181. public void ActionLinkWithObjectPropertiesWithUnderscores()
  182. {
  183. // Arrange
  184. HtmlHelper htmlHelper = MvcHelper.GetHtmlHelper();
  185. // Act
  186. MvcHtmlString html = htmlHelper.ActionLink("linktext", "newaction", new { Controller = "home2", id = "someid" }, new { foo_baz = "baz" });
  187. // Assert
  188. Assert.Equal(@"<a foo-baz=""baz"" href=""" + AppPathModifier + @"/app/home2/newaction/someid"">linktext</a>", html.ToHtmlString());
  189. }
  190. [Fact]
  191. public void ActionLinkWithProtocol()
  192. {
  193. // Arrange
  194. HtmlHelper htmlHelper = MvcHelper.GetHtmlHelper();
  195. // Act
  196. MvcHtmlString html = htmlHelper.ActionLink("linktext", "newaction", "home2", "https", "foo.bar.com", null /* fragment */, new { id = "someid" }, new { baz = "baz" });
  197. // Assert
  198. Assert.Equal(@"<a baz=""baz"" href=""https://foo.bar.com" + AppPathModifier + @"/app/home2/newaction/someid"">linktext</a>", html.ToHtmlString());
  199. }
  200. [Fact]
  201. public void ActionLinkWithProtocolAndFragment()
  202. {
  203. // Arrange
  204. HtmlHelper htmlHelper = MvcHelper.GetHtmlHelper();
  205. // Act
  206. MvcHtmlString html = htmlHelper.ActionLink("linktext", "newaction", "home2", "https", "foo.bar.com", "foo", new { id = "someid" }, new { baz = "baz" });
  207. // Assert
  208. Assert.Equal(@"<a baz=""baz"" href=""https://foo.bar.com" + AppPathModifier + @"/app/home2/newaction/someid#foo"">linktext</a>", html.ToHtmlString());
  209. }
  210. [Fact]
  211. public void ActionLinkWithDefaultPort()
  212. {
  213. // Arrange
  214. HtmlHelper htmlHelper = MvcHelper.GetHtmlHelper(Uri.UriSchemeHttps, -1);
  215. // Act
  216. MvcHtmlString html = htmlHelper.ActionLink("linktext", "newaction", "home2", "https", "foo.bar.com", "foo", new { id = "someid" }, new { baz = "baz" });
  217. // Assert
  218. Assert.Equal(@"<a baz=""baz"" href=""https://foo.bar.com" + AppPathModifier + @"/app/home2/newaction/someid#foo"">linktext</a>", html.ToHtmlString());
  219. }
  220. [Fact]
  221. public void ActionLinkWithDifferentPortProtocols()
  222. {
  223. // Arrange
  224. HtmlHelper htmlHelper = MvcHelper.GetHtmlHelper(Uri.UriSchemeHttp, -1);
  225. // Act
  226. MvcHtmlString html = htmlHelper.ActionLink("linktext", "newaction", "home2", "https", "foo.bar.com", "foo", new { id = "someid" }, new { baz = "baz" });
  227. // Assert
  228. Assert.Equal(@"<a baz=""baz"" href=""https://foo.bar.com" + AppPathModifier + @"/app/home2/newaction/someid#foo"">linktext</a>", html.ToHtmlString());
  229. }
  230. [Fact]
  231. public void ActionLinkWithNonDefaultPortAndDifferentProtocol()
  232. {
  233. // Arrange
  234. HtmlHelper htmlHelper = MvcHelper.GetHtmlHelper(Uri.UriSchemeHttp, 32768);
  235. // Act
  236. MvcHtmlString html = htmlHelper.ActionLink("linktext", "newaction", "home2", "https", "foo.bar.com", "foo", new { id = "someid" }, new { baz = "baz" });
  237. // Assert
  238. Assert.Equal(@"<a baz=""baz"" href=""https://foo.bar.com" + AppPathModifier + @"/app/home2/newaction/someid#foo"">linktext</a>", html.ToHtmlString());
  239. }
  240. [Fact]
  241. public void ActionLinkWithNonDefaultPortAndSameProtocol()
  242. {
  243. // Arrange
  244. HtmlHelper htmlHelper = MvcHelper.GetHtmlHelper(Uri.UriSchemeHttp, 32768);
  245. // Act
  246. MvcHtmlString html = htmlHelper.ActionLink("linktext", "newaction", "home2", "http", "foo.bar.com", "foo", new { id = "someid" }, new { baz = "baz" });
  247. // Assert
  248. Assert.Equal(@"<a baz=""baz"" href=""http://foo.bar.com:32768" + AppPathModifier + @"/app/home2/newaction/someid#foo"">linktext</a>", html.ToHtmlString());
  249. }
  250. [Fact]
  251. public void LinkGenerationDoesNotChangeProvidedDictionary()
  252. {
  253. // Arrange
  254. HtmlHelper htmlHelper = MvcHelper.GetHtmlHelper();
  255. RouteValueDictionary valuesDictionary = new RouteValueDictionary();
  256. // Act
  257. htmlHelper.ActionLink("linkText", "actionName", valuesDictionary, new RouteValueDictionary());
  258. // Assert
  259. Assert.Empty(valuesDictionary);
  260. Assert.False(valuesDictionary.ContainsKey("action"));
  261. }
  262. [Fact]
  263. public void NullOrEmptyStringParameterThrows()
  264. {
  265. // Arrange
  266. HtmlHelper htmlHelper = MvcHelper.GetHtmlHelper();
  267. var tests = new[]
  268. {
  269. // ActionLink(string linkText, string actionName)
  270. new { Parameter = "linkText", Action = new Action(() => htmlHelper.ActionLink(String.Empty, "actionName")) },
  271. // ActionLink(string linkText, string actionName, object routeValues, object htmlAttributes)
  272. new { Parameter = "linkText", Action = new Action(() => htmlHelper.ActionLink(String.Empty, "actionName", new Object(), null /* htmlAttributes */)) },
  273. // ActionLink(string linkText, string actionName, RouteValueDictionary routeValues, IDictionary<string, object> htmlAttributes)
  274. new { Parameter = "linkText", Action = new Action(() => htmlHelper.ActionLink(String.Empty, "actionName", new RouteValueDictionary(), new RouteValueDictionary())) },
  275. // ActionLink(string linkText, string actionName, string controllerName)
  276. new { Parameter = "linkText", Action = new Action(() => htmlHelper.ActionLink(String.Empty, "actionName", "controllerName")) },
  277. // ActionLink(string linkText, string actionName, string controllerName, object routeValues, object htmlAttributes)
  278. new { Parameter = "linkText", Action = new Action(() => htmlHelper.ActionLink(String.Empty, "actionName", "controllerName", new Object(), null /* htmlAttributes */)) },
  279. // ActionLink(string linkText, string actionName, string controllerName, RouteValueDictionary routeValues, IDictionary<string, object> htmlAttributes)
  280. new { Parameter = "linkText", Action = new Action(() => htmlHelper.ActionLink(String.Empty, "actionName", "controllerName", new RouteValueDictionary(), new RouteValueDictionary())) },
  281. // ActionLink(string linkText, string actionName, string controllerName, string protocol, string hostName, string fragment, RouteValueDictionary routeValues, IDictionary<string, object> htmlAttributes)
  282. new { Parameter = "linkText", Action = new Action(() => htmlHelper.ActionLink(String.Empty, "actionName", "controllerName", null, null, null, new RouteValueDictionary(), new RouteValueDictionary())) },
  283. // RouteLink(string linkText, object routeValues, object htmlAttributes)
  284. new { Parameter = "linkText", Action = new Action(() => htmlHelper.RouteLink(String.Empty, new Object(), null /* htmlAttributes */)) },
  285. // RouteLink(string linkText, RouteValueDictionary routeValues, IDictionary<string, object> htmlAttributes)
  286. new { Parameter = "linkText", Action = new Action(() => htmlHelper.RouteLink(String.Empty, new RouteValueDictionary(), new RouteValueDictionary())) },
  287. // RouteLink(string linkText, string routeName, object routeValues)
  288. new { Parameter = "linkText", Action = new Action(() => htmlHelper.RouteLink(String.Empty, "routeName", null /* routeValues */)) },
  289. // RouteLink(string linkText, string routeName, RouteValueDictionary routeValues)
  290. new { Parameter = "linkText", Action = new Action(() => htmlHelper.RouteLink(String.Empty, "routeName", new RouteValueDictionary() /* routeValues */)) },
  291. // RouteLink(string linkText, string routeName)
  292. new { Parameter = "linkText", Action = new Action(() => htmlHelper.RouteLink(String.Empty, (string)null /* routeName */)) },
  293. // RouteLink(string linkText, object routeValues)
  294. new { Parameter = "linkText", Action = new Action(() => htmlHelper.RouteLink(String.Empty, (object)null /* routeValues */)) },
  295. // RouteLink(string linkText, RouteValueDictionary routeValues)
  296. new { Parameter = "linkText", Action = new Action(() => htmlHelper.RouteLink(String.Empty, new RouteValueDictionary() /* routeValues */)) },
  297. // RouteLink(string linkText, string routeName, object routeValues, object htmlAttributes)
  298. new { Parameter = "linkText", Action = new Action(() => htmlHelper.RouteLink(String.Empty, "routeName", new Object(), null /* htmlAttributes */)) },
  299. // RouteLink(string linkText, string routeName, RouteValueDictionary routeValues, IDictionary<string, object> htmlAttributes)
  300. new { Parameter = "linkText", Action = new Action(() => htmlHelper.RouteLink(String.Empty, "routeName", new RouteValueDictionary(), new RouteValueDictionary())) },
  301. // RouteLink(string linkText, string routeName, string protocol, string hostName, string fragment, RouteValueDictionary routeValues, IDictionary<string, object> htmlAttributes)
  302. new { Parameter = "linkText", Action = new Action(() => htmlHelper.RouteLink(String.Empty, "routeName", null, null, null, new RouteValueDictionary(), new RouteValueDictionary())) },
  303. };
  304. // Act & Assert
  305. foreach (var test in tests)
  306. {
  307. Assert.ThrowsArgumentNullOrEmpty(test.Action, test.Parameter);
  308. }
  309. }
  310. [Fact]
  311. public void RouteLinkCanUseNamedRouteWithoutSpecifyingDefaults()
  312. {
  313. // DevDiv 217072: Non-mvc specific helpers should not give default values for controller and action
  314. // Arrange
  315. HtmlHelper htmlHelper = MvcHelper.GetHtmlHelper();
  316. htmlHelper.RouteCollection.MapRoute("MyRouteName", "any/url", new { controller = "Charlie" });
  317. // Act
  318. MvcHtmlString html = htmlHelper.RouteLink("linktext", "MyRouteName", null /* routeValues */);
  319. // Assert
  320. Assert.Equal(@"<a href=""" + AppPathModifier + @"/app/any/url"">linktext</a>", html.ToHtmlString());
  321. }
  322. [Fact]
  323. public void RouteLinkWithDictionary()
  324. {
  325. // Arrange
  326. HtmlHelper htmlHelper = MvcHelper.GetHtmlHelper();
  327. // Act
  328. MvcHtmlString html = htmlHelper.RouteLink("linktext", new RouteValueDictionary(new { Action = "newaction", Controller = "home2", id = "someid" }), new RouteValueDictionary(new { baz = "baz" }));
  329. // Assert
  330. Assert.Equal(@"<a baz=""baz"" href=""" + AppPathModifier + @"/app/home2/newaction/someid"">linktext</a>", html.ToHtmlString());
  331. }
  332. [Fact]
  333. public void RouteLinkWithFragment()
  334. {
  335. // Arrange
  336. HtmlHelper htmlHelper = MvcHelper.GetHtmlHelper();
  337. // Act
  338. MvcHtmlString html = htmlHelper.RouteLink("linktext", "namedroute", "http", "foo.bar.com", "foo", new { Action = "newaction", Controller = "home2", id = "someid" }, new { baz = "baz" });
  339. // Assert
  340. Assert.Equal(@"<a baz=""baz"" href=""http://foo.bar.com" + AppPathModifier + @"/app/named/home2/newaction/someid#foo"">linktext</a>", html.ToHtmlString());
  341. }
  342. [Fact]
  343. public void RouteLinkWithFragmentAndAttributesWithUnderscores()
  344. {
  345. // Arrange
  346. HtmlHelper htmlHelper = MvcHelper.GetHtmlHelper();
  347. // Act
  348. MvcHtmlString html = htmlHelper.RouteLink("linktext", "namedroute", "http", "foo.bar.com", "foo", new { Action = "newaction", Controller = "home2", id = "someid" }, new { foo_baz = "baz" });
  349. // Assert
  350. Assert.Equal(@"<a foo-baz=""baz"" href=""http://foo.bar.com" + AppPathModifier + @"/app/named/home2/newaction/someid#foo"">linktext</a>", html.ToHtmlString());
  351. }
  352. [Fact]
  353. public void RouteLinkWithLinkTextAndRouteName()
  354. {
  355. // Arrange
  356. HtmlHelper htmlHelper = MvcHelper.GetHtmlHelper();
  357. htmlHelper.RouteCollection.MapRoute("MyRouteName", "any/url", new { controller = "Charlie" });
  358. // Act
  359. MvcHtmlString html = htmlHelper.RouteLink("linktext", "MyRouteName");
  360. // Assert
  361. Assert.Equal(@"<a href=""" + AppPathModifier + @"/app/any/url"">linktext</a>", html.ToHtmlString());
  362. }
  363. [Fact]
  364. public void RouteLinkWithObjectProperties()
  365. {
  366. // Arrange
  367. HtmlHelper htmlHelper = MvcHelper.GetHtmlHelper();
  368. // Act
  369. MvcHtmlString html = htmlHelper.RouteLink("linktext", new { Action = "newaction", Controller = "home2", id = "someid" }, new { baz = "baz" });
  370. // Assert
  371. Assert.Equal(@"<a baz=""baz"" href=""" + AppPathModifier + @"/app/home2/newaction/someid"">linktext</a>", html.ToHtmlString());
  372. }
  373. [Fact]
  374. public void RouteLinkWithObjectPropertiesWithUnderscores()
  375. {
  376. // Arrange
  377. HtmlHelper htmlHelper = MvcHelper.GetHtmlHelper();
  378. // Act
  379. MvcHtmlString html = htmlHelper.RouteLink("linktext", new { Action = "newaction", Controller = "home2", id = "someid" }, new { foo_baz = "baz" });
  380. // Assert
  381. Assert.Equal(@"<a foo-baz=""baz"" href=""" + AppPathModifier + @"/app/home2/newaction/someid"">linktext</a>", html.ToHtmlString());
  382. }
  383. [Fact]
  384. public void RouteLinkWithProtocol()
  385. {
  386. // Arrange
  387. HtmlHelper htmlHelper = MvcHelper.GetHtmlHelper();
  388. // Act
  389. MvcHtmlString html = htmlHelper.RouteLink("linktext", "namedroute", "https", "foo.bar.com", null /* fragment */, new { Action = "newaction", Controller = "home2", id = "someid" }, new { baz = "baz" });
  390. // Assert
  391. Assert.Equal(@"<a baz=""baz"" href=""https://foo.bar.com" + AppPathModifier + @"/app/named/home2/newaction/someid"">linktext</a>", html.ToHtmlString());
  392. }
  393. [Fact]
  394. public void RouteLinkWithProtocolAndFragment()
  395. {
  396. // Arrange
  397. HtmlHelper htmlHelper = MvcHelper.GetHtmlHelper();
  398. // Act
  399. MvcHtmlString html = htmlHelper.RouteLink("linktext", "namedroute", "https", "foo.bar.com", "foo", new { Action = "newaction", Controller = "home2", id = "someid" }, new { baz = "baz" });
  400. // Assert
  401. Assert.Equal(@"<a baz=""baz"" href=""https://foo.bar.com" + AppPathModifier + @"/app/named/home2/newaction/someid#foo"">linktext</a>", html.ToHtmlString());
  402. }
  403. [Fact]
  404. public void RouteLinkWithRouteNameAndDefaults()
  405. {
  406. // Arrange
  407. HtmlHelper htmlHelper = MvcHelper.GetHtmlHelper();
  408. // Act
  409. MvcHtmlString html = htmlHelper.RouteLink("linktext", "namedroute", new { Action = "newaction" });
  410. // Assert
  411. Assert.Equal(@"<a href=""" + AppPathModifier + @"/app/named/home/newaction"">linktext</a>", html.ToHtmlString());
  412. }
  413. [Fact]
  414. public void RouteLinkWithRouteNameAndDictionary()
  415. {
  416. // Arrange
  417. HtmlHelper htmlHelper = MvcHelper.GetHtmlHelper();
  418. // Act
  419. MvcHtmlString html = htmlHelper.RouteLink("linktext", "namedroute", new RouteValueDictionary(new { Action = "newaction", Controller = "home2", id = "someid" }), new RouteValueDictionary());
  420. // Assert
  421. Assert.Equal(@"<a href=""" + AppPathModifier + @"/app/named/home2/newaction/someid"">linktext</a>", html.ToHtmlString());
  422. }
  423. [Fact]
  424. public void RouteLinkWithRouteNameAndObjectProperties()
  425. {
  426. // Arrange
  427. HtmlHelper htmlHelper = MvcHelper.GetHtmlHelper();
  428. // Act
  429. MvcHtmlString html = htmlHelper.RouteLink("linktext", "namedroute", new { Action = "newaction", Controller = "home2", id = "someid" }, new { baz = "baz" });
  430. // Assert
  431. Assert.Equal(@"<a baz=""baz"" href=""" + AppPathModifier + @"/app/named/home2/newaction/someid"">linktext</a>", html.ToHtmlString());
  432. }
  433. [Fact]
  434. public void RouteLinkWithRouteNameAndObjectPropertiesWithUnderscores()
  435. {
  436. // Arrange
  437. HtmlHelper htmlHelper = MvcHelper.GetHtmlHelper();
  438. // Act
  439. MvcHtmlString html = htmlHelper.RouteLink("linktext", "namedroute", new { Action = "newaction", Controller = "home2", id = "someid" }, new { foo_baz = "baz" });
  440. // Assert
  441. Assert.Equal(@"<a foo-baz=""baz"" href=""" + AppPathModifier + @"/app/named/home2/newaction/someid"">linktext</a>", html.ToHtmlString());
  442. }
  443. }
  444. }