PageRenderTime 52ms CodeModel.GetById 13ms RepoModel.GetById 0ms app.codeStats 0ms

/test/System.Web.Mvc.Test/Ajax/Test/AjaxExtensionsTest.cs

https://bitbucket.org/mdavid/aspnetwebstack
C# | 1122 lines | 728 code | 203 blank | 191 comment | 0 complexity | c549ba408efb84a2a3853749a1e72a9e MD5 | raw file
  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using System.Globalization;
  4. using System.IO;
  5. using System.Threading;
  6. using System.Web.Mvc.Html;
  7. using System.Web.Routing;
  8. using Microsoft.Web.UnitTestUtil;
  9. using Moq;
  10. using Xunit;
  11. using Assert = Microsoft.TestCommon.AssertEx;
  12. namespace System.Web.Mvc.Ajax.Test
  13. {
  14. public class AjaxExtensionsTest
  15. {
  16. // Guards
  17. [Fact]
  18. public void ActionLinkWithNullOrEmptyLinkTextThrows()
  19. {
  20. // Arrange
  21. AjaxHelper ajaxHelper = GetAjaxHelper();
  22. // Act & Assert
  23. Assert.ThrowsArgumentNullOrEmpty(
  24. delegate { MvcHtmlString actionLink = ajaxHelper.ActionLink(String.Empty, String.Empty, null, null, null, null); },
  25. "linkText");
  26. }
  27. [Fact]
  28. public void RouteLinkWithNullOrEmptyLinkTextThrows()
  29. {
  30. // Arrange
  31. AjaxHelper ajaxHelper = GetAjaxHelper();
  32. // Act & Assert
  33. Assert.ThrowsArgumentNullOrEmpty(
  34. delegate { MvcHtmlString actionLink = ajaxHelper.RouteLink(String.Empty, String.Empty, null, null, null); },
  35. "linkText");
  36. }
  37. // Form context setup and cleanup
  38. [Fact]
  39. public void BeginFormSetsAndRestoresToDefault()
  40. {
  41. // Arrange
  42. AjaxHelper ajaxHelper = GetAjaxHelper();
  43. ajaxHelper.ViewContext.FormContext = null;
  44. FormContext defaultFormContext = ajaxHelper.ViewContext.FormContext;
  45. // Act & assert - push
  46. MvcForm theForm = ajaxHelper.BeginForm(new AjaxOptions());
  47. Assert.NotNull(ajaxHelper.ViewContext.FormContext);
  48. Assert.NotEqual(defaultFormContext, ajaxHelper.ViewContext.FormContext);
  49. // Act & assert - pop
  50. theForm.Dispose();
  51. Assert.Equal(defaultFormContext, ajaxHelper.ViewContext.FormContext);
  52. }
  53. [Fact]
  54. public void DisposeWritesClosingFormTag()
  55. {
  56. // Arrange
  57. AjaxHelper ajaxHelper = GetAjaxHelper();
  58. AjaxOptions ajaxOptions = new AjaxOptions { UpdateTargetId = "some-id" };
  59. StringWriter writer = new StringWriter();
  60. ajaxHelper.ViewContext.Writer = writer;
  61. // Act
  62. IDisposable form = ajaxHelper.BeginForm("Action", "Controller", ajaxOptions);
  63. form.Dispose();
  64. // Assert
  65. Assert.True(writer.ToString().EndsWith("</form>"));
  66. }
  67. // GlobalizationScript
  68. [Fact]
  69. public void GlobalizationScriptWithNullCultureInfoThrows()
  70. {
  71. // Arrange
  72. AjaxHelper ajaxHelper = GetAjaxHelper();
  73. // Act & Assert
  74. Assert.ThrowsArgumentNull(
  75. delegate { ajaxHelper.GlobalizationScript(null); },
  76. "cultureInfo");
  77. }
  78. [Fact]
  79. public void GlobalizationScriptUsesCurrentCultureAsDefault()
  80. {
  81. CultureInfo currentCulture = Thread.CurrentThread.CurrentCulture;
  82. try
  83. {
  84. // Arrange
  85. AjaxHelper ajaxHelper = GetAjaxHelper();
  86. AjaxHelper.GlobalizationScriptPath = null;
  87. Thread.CurrentThread.CurrentCulture = CultureInfo.GetCultureInfo("en-GB");
  88. // Act
  89. MvcHtmlString globalizationScript = ajaxHelper.GlobalizationScript();
  90. // Assert
  91. Assert.Equal(@"<script src=""~/Scripts/Globalization/en-GB.js"" type=""text/javascript""></script>", globalizationScript.ToHtmlString());
  92. }
  93. finally
  94. {
  95. Thread.CurrentThread.CurrentCulture = currentCulture;
  96. }
  97. }
  98. [Fact]
  99. public void GlobalizationScriptWithCultureInfo()
  100. {
  101. CultureInfo currentCulture = Thread.CurrentThread.CurrentCulture;
  102. try
  103. {
  104. // Arrange
  105. AjaxHelper ajaxHelper = GetAjaxHelper();
  106. AjaxHelper.GlobalizationScriptPath = null;
  107. Thread.CurrentThread.CurrentCulture = CultureInfo.GetCultureInfo("en-GB");
  108. // Act
  109. MvcHtmlString globalizationScript = ajaxHelper.GlobalizationScript(CultureInfo.GetCultureInfo("en-CA"));
  110. // Assert
  111. Assert.Equal(@"<script src=""~/Scripts/Globalization/en-CA.js"" type=""text/javascript""></script>", globalizationScript.ToHtmlString());
  112. }
  113. finally
  114. {
  115. Thread.CurrentThread.CurrentCulture = currentCulture;
  116. }
  117. }
  118. [Fact]
  119. public void GlobalizationScriptEncodesSource()
  120. {
  121. // Arrange
  122. Mock<CultureInfo> xssCulture = new Mock<CultureInfo>("en-US");
  123. xssCulture.Setup(culture => culture.Name).Returns("evil.example.com/<script>alert('XSS!')</script>");
  124. string globalizationPath = "~/Scripts&Globalization";
  125. string expectedScriptTag = @"<script src=""~/Scripts&amp;Globalization/evil.example.com%2f%3cscript%3ealert(%27XSS!%27)%3c%2fscript%3e.js"" type=""text/javascript""></script>";
  126. // Act
  127. MvcHtmlString globalizationScript = AjaxExtensions.GlobalizationScriptHelper(globalizationPath, xssCulture.Object);
  128. // Assert
  129. Assert.Equal(expectedScriptTag, globalizationScript.ToHtmlString());
  130. }
  131. [Fact]
  132. public void GlobalizationScriptWithNullCultureName()
  133. {
  134. // Arrange
  135. Mock<CultureInfo> xssCulture = new Mock<CultureInfo>("en-US");
  136. xssCulture.Setup(culture => culture.Name).Returns((string)null);
  137. AjaxHelper ajaxHelper = GetAjaxHelper();
  138. AjaxHelper.GlobalizationScriptPath = null;
  139. // Act
  140. MvcHtmlString globalizationScript = ajaxHelper.GlobalizationScript(xssCulture.Object);
  141. // Assert
  142. Assert.Equal(@"<script src=""~/Scripts/Globalization/.js"" type=""text/javascript""></script>", globalizationScript.ToHtmlString());
  143. }
  144. // ActionLink (traditional JavaScript)
  145. [Fact]
  146. public void ActionLinkWithNullActionName()
  147. {
  148. // Arrange
  149. AjaxHelper ajaxHelper = GetAjaxHelper(unobtrusiveJavaScript: false);
  150. // Act
  151. MvcHtmlString actionLink = ajaxHelper.ActionLink("linkText", null, new AjaxOptions());
  152. // Assert
  153. Assert.Equal(@"<a href=""" + MvcHelper.AppPathModifier + @"/app/home/oldaction"" onclick=""Sys.Mvc.AsyncHyperlink.handleClick(this, new Sys.UI.DomEvent(event), { insertionMode: Sys.Mvc.InsertionMode.replace });"">linkText</a>", actionLink.ToHtmlString());
  154. }
  155. [Fact]
  156. public void ActionLinkWithNullActionName_Unobtrusive()
  157. {
  158. // Arrange
  159. AjaxHelper ajaxHelper = GetAjaxHelper(unobtrusiveJavaScript: true);
  160. // Act
  161. MvcHtmlString actionLink = ajaxHelper.ActionLink("linkText", null, new AjaxOptions());
  162. // Assert
  163. Assert.Equal(@"<a data-ajax=""true"" href=""" + MvcHelper.AppPathModifier + @"/app/home/oldaction"">linkText</a>", actionLink.ToHtmlString());
  164. }
  165. [Fact]
  166. public void ActionLinkWithNullActionNameAndNullOptions()
  167. {
  168. // Arrange
  169. AjaxHelper ajaxHelper = GetAjaxHelper(unobtrusiveJavaScript: false);
  170. // Act
  171. MvcHtmlString actionLink = ajaxHelper.ActionLink("linkText", null, null);
  172. // Assert
  173. Assert.Equal(@"<a href=""" + MvcHelper.AppPathModifier + @"/app/home/oldaction"" onclick=""Sys.Mvc.AsyncHyperlink.handleClick(this, new Sys.UI.DomEvent(event), { insertionMode: Sys.Mvc.InsertionMode.replace });"">linkText</a>", actionLink.ToHtmlString());
  174. }
  175. [Fact]
  176. public void ActionLinkWithNullActionNameAndNullOptions_Unobtrusive()
  177. {
  178. // Arrange
  179. AjaxHelper ajaxHelper = GetAjaxHelper(unobtrusiveJavaScript: true);
  180. // Act
  181. MvcHtmlString actionLink = ajaxHelper.ActionLink("linkText", null, null);
  182. // Assert
  183. Assert.Equal(@"<a data-ajax=""true"" href=""" + MvcHelper.AppPathModifier + @"/app/home/oldaction"">linkText</a>", actionLink.ToHtmlString());
  184. }
  185. [Fact]
  186. public void ActionLink()
  187. {
  188. // Arrange
  189. AjaxHelper ajaxHelper = GetAjaxHelper(unobtrusiveJavaScript: false);
  190. // Act
  191. MvcHtmlString actionLink = ajaxHelper.ActionLink("linkText", "Action", new AjaxOptions());
  192. // Assert
  193. Assert.Equal(@"<a href=""" + MvcHelper.AppPathModifier + @"/app/home/Action"" onclick=""Sys.Mvc.AsyncHyperlink.handleClick(this, new Sys.UI.DomEvent(event), { insertionMode: Sys.Mvc.InsertionMode.replace });"">linkText</a>", actionLink.ToHtmlString());
  194. }
  195. [Fact]
  196. public void ActionLink_Unobtrusive()
  197. {
  198. // Arrange
  199. AjaxHelper ajaxHelper = GetAjaxHelper(unobtrusiveJavaScript: true);
  200. // Act
  201. MvcHtmlString actionLink = ajaxHelper.ActionLink("linkText", "Action", new AjaxOptions());
  202. // Assert
  203. Assert.Equal(@"<a data-ajax=""true"" href=""" + MvcHelper.AppPathModifier + @"/app/home/Action"">linkText</a>", actionLink.ToHtmlString());
  204. }
  205. [Fact]
  206. public void ActionLinkAnonymousValues()
  207. {
  208. // Arrange
  209. AjaxHelper helper = GetAjaxHelper(unobtrusiveJavaScript: false);
  210. object values = new { controller = "Controller" };
  211. AjaxOptions options = new AjaxOptions { UpdateTargetId = "update-div" };
  212. // Act
  213. MvcHtmlString actionLink = helper.ActionLink("Some Text", "Action", values, options);
  214. // Assert
  215. Assert.Equal(@"<a href=""" + MvcHelper.AppPathModifier + @"/app/Controller/Action"" onclick=""Sys.Mvc.AsyncHyperlink.handleClick(this, new Sys.UI.DomEvent(event), { insertionMode: Sys.Mvc.InsertionMode.replace, updateTargetId: &#39;update-div&#39; });"">Some Text</a>", actionLink.ToHtmlString());
  216. }
  217. [Fact]
  218. public void ActionLinkAnonymousValues_Unobtrusive()
  219. {
  220. // Arrange
  221. AjaxHelper helper = GetAjaxHelper(unobtrusiveJavaScript: true);
  222. object values = new { controller = "Controller" };
  223. AjaxOptions options = new AjaxOptions { UpdateTargetId = "update-div" };
  224. // Act
  225. MvcHtmlString actionLink = helper.ActionLink("Some Text", "Action", values, options);
  226. // Assert
  227. Assert.Equal(@"<a data-ajax=""true"" data-ajax-mode=""replace"" data-ajax-update=""#update-div"" href=""" + MvcHelper.AppPathModifier + @"/app/Controller/Action"">Some Text</a>", actionLink.ToHtmlString());
  228. }
  229. [Fact]
  230. public void ActionLinkAnonymousValuesAndAttributes()
  231. {
  232. // Arrange
  233. AjaxHelper helper = GetAjaxHelper(unobtrusiveJavaScript: false);
  234. object htmlAttributes = new { foo = "bar", baz = "quux", foo_bar = "baz_quux" };
  235. object values = new { controller = "Controller" };
  236. AjaxOptions options = new AjaxOptions { UpdateTargetId = "update-div" };
  237. // Act
  238. MvcHtmlString actionLink = helper.ActionLink("Some Text", "Action", values, options, htmlAttributes);
  239. // Assert
  240. Assert.Equal(@"<a baz=""quux"" foo=""bar"" foo-bar=""baz_quux"" href=""" + MvcHelper.AppPathModifier + @"/app/Controller/Action"" onclick=""Sys.Mvc.AsyncHyperlink.handleClick(this, new Sys.UI.DomEvent(event), { insertionMode: Sys.Mvc.InsertionMode.replace, updateTargetId: &#39;update-div&#39; });"">Some Text</a>", actionLink.ToHtmlString());
  241. }
  242. [Fact]
  243. public void ActionLinkAnonymousValuesAndAttributes_Unobtrusive()
  244. {
  245. // Arrange
  246. AjaxHelper helper = GetAjaxHelper(unobtrusiveJavaScript: true);
  247. object htmlAttributes = new { foo = "bar", baz = "quux", foo_bar = "baz_quux" };
  248. object values = new { controller = "Controller" };
  249. AjaxOptions options = new AjaxOptions { UpdateTargetId = "update-div" };
  250. // Act
  251. MvcHtmlString actionLink = helper.ActionLink("Some Text", "Action", values, options, htmlAttributes);
  252. // Assert
  253. Assert.Equal(@"<a baz=""quux"" data-ajax=""true"" data-ajax-mode=""replace"" data-ajax-update=""#update-div"" foo=""bar"" foo-bar=""baz_quux"" href=""" + MvcHelper.AppPathModifier + @"/app/Controller/Action"">Some Text</a>", actionLink.ToHtmlString());
  254. }
  255. [Fact]
  256. public void ActionLinkTypedValues()
  257. {
  258. // Arrange
  259. AjaxHelper helper = GetAjaxHelper(unobtrusiveJavaScript: false);
  260. RouteValueDictionary values = new RouteValueDictionary
  261. {
  262. { "controller", "Controller" }
  263. };
  264. AjaxOptions options = new AjaxOptions { UpdateTargetId = "update-div" };
  265. // Act
  266. MvcHtmlString actionLink = helper.ActionLink("Some Text", "Action", values, options);
  267. // Assert
  268. Assert.Equal(@"<a href=""" + MvcHelper.AppPathModifier + @"/app/Controller/Action"" onclick=""Sys.Mvc.AsyncHyperlink.handleClick(this, new Sys.UI.DomEvent(event), { insertionMode: Sys.Mvc.InsertionMode.replace, updateTargetId: &#39;update-div&#39; });"">Some Text</a>", actionLink.ToHtmlString());
  269. }
  270. [Fact]
  271. public void ActionLinkTypedValues_Unobtrusive()
  272. {
  273. // Arrange
  274. AjaxHelper helper = GetAjaxHelper(unobtrusiveJavaScript: true);
  275. RouteValueDictionary values = new RouteValueDictionary
  276. {
  277. { "controller", "Controller" }
  278. };
  279. AjaxOptions options = new AjaxOptions { UpdateTargetId = "update-div" };
  280. // Act
  281. MvcHtmlString actionLink = helper.ActionLink("Some Text", "Action", values, options);
  282. // Assert
  283. Assert.Equal(@"<a data-ajax=""true"" data-ajax-mode=""replace"" data-ajax-update=""#update-div"" href=""" + MvcHelper.AppPathModifier + @"/app/Controller/Action"">Some Text</a>", actionLink.ToHtmlString());
  284. }
  285. [Fact]
  286. public void ActionLinkTypedValuesAndAttributes()
  287. {
  288. // Arrange
  289. AjaxHelper helper = GetAjaxHelper(unobtrusiveJavaScript: false);
  290. RouteValueDictionary values = new RouteValueDictionary
  291. {
  292. { "controller", "Controller" }
  293. };
  294. Dictionary<string, object> htmlAttributes = new Dictionary<string, object>
  295. {
  296. { "foo", "bar" },
  297. { "baz", "quux" },
  298. { "foo_bar", "baz_quux" }
  299. };
  300. AjaxOptions options = new AjaxOptions { UpdateTargetId = "update-div" };
  301. // Act
  302. MvcHtmlString actionLink = helper.ActionLink("Some Text", "Action", values, options, htmlAttributes);
  303. // Assert
  304. Assert.Equal(@"<a baz=""quux"" foo=""bar"" foo_bar=""baz_quux"" href=""" + MvcHelper.AppPathModifier + @"/app/Controller/Action"" onclick=""Sys.Mvc.AsyncHyperlink.handleClick(this, new Sys.UI.DomEvent(event), { insertionMode: Sys.Mvc.InsertionMode.replace, updateTargetId: &#39;update-div&#39; });"">Some Text</a>", actionLink.ToHtmlString());
  305. }
  306. [Fact]
  307. public void ActionLinkTypedValuesAndAttributes_Unobtrusive()
  308. {
  309. // Arrange
  310. AjaxHelper helper = GetAjaxHelper(unobtrusiveJavaScript: true);
  311. RouteValueDictionary values = new RouteValueDictionary
  312. {
  313. { "controller", "Controller" }
  314. };
  315. Dictionary<string, object> htmlAttributes = new Dictionary<string, object>
  316. {
  317. { "foo", "bar" },
  318. { "baz", "quux" },
  319. { "foo_bar", "baz_quux" }
  320. };
  321. AjaxOptions options = new AjaxOptions { UpdateTargetId = "update-div" };
  322. // Act
  323. MvcHtmlString actionLink = helper.ActionLink("Some Text", "Action", values, options, htmlAttributes);
  324. // Assert
  325. Assert.Equal(@"<a baz=""quux"" data-ajax=""true"" data-ajax-mode=""replace"" data-ajax-update=""#update-div"" foo=""bar"" foo_bar=""baz_quux"" href=""" + MvcHelper.AppPathModifier + @"/app/Controller/Action"">Some Text</a>", actionLink.ToHtmlString());
  326. }
  327. [Fact]
  328. public void ActionLinkController()
  329. {
  330. // Arrange
  331. AjaxHelper ajaxHelper = GetAjaxHelper(unobtrusiveJavaScript: false);
  332. // Act
  333. MvcHtmlString actionLink = ajaxHelper.ActionLink("linkText", "Action", "Controller", new AjaxOptions());
  334. // Assert
  335. Assert.Equal(@"<a href=""" + MvcHelper.AppPathModifier + @"/app/Controller/Action"" onclick=""Sys.Mvc.AsyncHyperlink.handleClick(this, new Sys.UI.DomEvent(event), { insertionMode: Sys.Mvc.InsertionMode.replace });"">linkText</a>", actionLink.ToHtmlString());
  336. }
  337. [Fact]
  338. public void ActionLinkController_Unobtrusive()
  339. {
  340. // Arrange
  341. AjaxHelper ajaxHelper = GetAjaxHelper(unobtrusiveJavaScript: true);
  342. // Act
  343. MvcHtmlString actionLink = ajaxHelper.ActionLink("linkText", "Action", "Controller", new AjaxOptions());
  344. // Assert
  345. Assert.Equal(@"<a data-ajax=""true"" href=""" + MvcHelper.AppPathModifier + @"/app/Controller/Action"">linkText</a>", actionLink.ToHtmlString());
  346. }
  347. [Fact]
  348. public void ActionLinkControllerAnonymousValues()
  349. {
  350. // Arrange
  351. AjaxHelper helper = GetAjaxHelper(unobtrusiveJavaScript: false);
  352. object values = new { id = 5 };
  353. AjaxOptions options = new AjaxOptions { UpdateTargetId = "update-div" };
  354. // Act
  355. MvcHtmlString actionLink = helper.ActionLink("Some Text", "Action", "Controller", values, options);
  356. // Assert
  357. Assert.Equal(@"<a href=""" + MvcHelper.AppPathModifier + @"/app/Controller/Action/5"" onclick=""Sys.Mvc.AsyncHyperlink.handleClick(this, new Sys.UI.DomEvent(event), { insertionMode: Sys.Mvc.InsertionMode.replace, updateTargetId: &#39;update-div&#39; });"">Some Text</a>", actionLink.ToHtmlString());
  358. }
  359. [Fact]
  360. public void ActionLinkControllerAnonymousValues_Unobtrusive()
  361. {
  362. // Arrange
  363. AjaxHelper helper = GetAjaxHelper(unobtrusiveJavaScript: true);
  364. object values = new { id = 5 };
  365. AjaxOptions options = new AjaxOptions { UpdateTargetId = "update-div" };
  366. // Act
  367. MvcHtmlString actionLink = helper.ActionLink("Some Text", "Action", "Controller", values, options);
  368. // Assert
  369. Assert.Equal(@"<a data-ajax=""true"" data-ajax-mode=""replace"" data-ajax-update=""#update-div"" href=""" + MvcHelper.AppPathModifier + @"/app/Controller/Action/5"">Some Text</a>", actionLink.ToHtmlString());
  370. }
  371. [Fact]
  372. public void ActionLinkControllerAnonymousValuesAndAttributes()
  373. {
  374. // Arrange
  375. AjaxHelper helper = GetAjaxHelper(unobtrusiveJavaScript: false);
  376. object htmlAttributes = new { foo = "bar", baz = "quux", foo_bar = "baz_quux" };
  377. object values = new { id = 5 };
  378. AjaxOptions options = new AjaxOptions { UpdateTargetId = "update-div" };
  379. // Act
  380. MvcHtmlString actionLink = helper.ActionLink("Some Text", "Action", "Controller", values, options, htmlAttributes);
  381. // Assert
  382. Assert.Equal(@"<a baz=""quux"" foo=""bar"" foo-bar=""baz_quux"" href=""" + MvcHelper.AppPathModifier + @"/app/Controller/Action/5"" onclick=""Sys.Mvc.AsyncHyperlink.handleClick(this, new Sys.UI.DomEvent(event), { insertionMode: Sys.Mvc.InsertionMode.replace, updateTargetId: &#39;update-div&#39; });"">Some Text</a>", actionLink.ToHtmlString());
  383. }
  384. [Fact]
  385. public void ActionLinkControllerAnonymousValuesAndAttributes_Unobtrusive()
  386. {
  387. // Arrange
  388. AjaxHelper helper = GetAjaxHelper(unobtrusiveJavaScript: true);
  389. object htmlAttributes = new { foo = "bar", baz = "quux", foo_bar = "baz_quux" };
  390. object values = new { id = 5 };
  391. AjaxOptions options = new AjaxOptions { UpdateTargetId = "update-div" };
  392. // Act
  393. MvcHtmlString actionLink = helper.ActionLink("Some Text", "Action", "Controller", values, options, htmlAttributes);
  394. // Assert
  395. Assert.Equal(@"<a baz=""quux"" data-ajax=""true"" data-ajax-mode=""replace"" data-ajax-update=""#update-div"" foo=""bar"" foo-bar=""baz_quux"" href=""" + MvcHelper.AppPathModifier + @"/app/Controller/Action/5"">Some Text</a>", actionLink.ToHtmlString());
  396. }
  397. [Fact]
  398. public void ActionLinkControllerTypedValues()
  399. {
  400. // Arrange
  401. AjaxHelper helper = GetAjaxHelper(unobtrusiveJavaScript: false);
  402. RouteValueDictionary values = new RouteValueDictionary
  403. {
  404. { "id", 5 }
  405. };
  406. AjaxOptions options = new AjaxOptions { UpdateTargetId = "update-div" };
  407. // Act
  408. MvcHtmlString actionLink = helper.ActionLink("Some Text", "Action", "Controller", values, options);
  409. // Assert
  410. Assert.Equal(@"<a href=""" + MvcHelper.AppPathModifier + @"/app/Controller/Action/5"" onclick=""Sys.Mvc.AsyncHyperlink.handleClick(this, new Sys.UI.DomEvent(event), { insertionMode: Sys.Mvc.InsertionMode.replace, updateTargetId: &#39;update-div&#39; });"">Some Text</a>", actionLink.ToHtmlString());
  411. }
  412. [Fact]
  413. public void ActionLinkControllerTypedValues_Unobtrusive()
  414. {
  415. // Arrange
  416. AjaxHelper helper = GetAjaxHelper(unobtrusiveJavaScript: true);
  417. RouteValueDictionary values = new RouteValueDictionary
  418. {
  419. { "id", 5 }
  420. };
  421. AjaxOptions options = new AjaxOptions { UpdateTargetId = "update-div" };
  422. // Act
  423. MvcHtmlString actionLink = helper.ActionLink("Some Text", "Action", "Controller", values, options);
  424. // Assert
  425. Assert.Equal(@"<a data-ajax=""true"" data-ajax-mode=""replace"" data-ajax-update=""#update-div"" href=""" + MvcHelper.AppPathModifier + @"/app/Controller/Action/5"">Some Text</a>", actionLink.ToHtmlString());
  426. }
  427. [Fact]
  428. public void ActionLinkControllerTypedValuesAndAttributes()
  429. {
  430. // Arrange
  431. AjaxHelper helper = GetAjaxHelper(unobtrusiveJavaScript: false);
  432. RouteValueDictionary values = new RouteValueDictionary
  433. {
  434. { "id", 5 }
  435. };
  436. Dictionary<string, object> htmlAttributes = new Dictionary<string, object>
  437. {
  438. { "foo", "bar" },
  439. { "baz", "quux" },
  440. { "foo_bar", "baz_quux" }
  441. };
  442. AjaxOptions options = new AjaxOptions { UpdateTargetId = "update-div" };
  443. // Act
  444. MvcHtmlString actionLink = helper.ActionLink("Some Text", "Action", "Controller", values, options, htmlAttributes);
  445. // Assert
  446. Assert.Equal(@"<a baz=""quux"" foo=""bar"" foo_bar=""baz_quux"" href=""" + MvcHelper.AppPathModifier + @"/app/Controller/Action/5"" onclick=""Sys.Mvc.AsyncHyperlink.handleClick(this, new Sys.UI.DomEvent(event), { insertionMode: Sys.Mvc.InsertionMode.replace, updateTargetId: &#39;update-div&#39; });"">Some Text</a>", actionLink.ToHtmlString());
  447. }
  448. [Fact]
  449. public void ActionLinkControllerTypedValuesAndAttributes_Unobtrusive()
  450. {
  451. // Arrange
  452. AjaxHelper helper = GetAjaxHelper(unobtrusiveJavaScript: true);
  453. RouteValueDictionary values = new RouteValueDictionary
  454. {
  455. { "id", 5 }
  456. };
  457. Dictionary<string, object> htmlAttributes = new Dictionary<string, object>
  458. {
  459. { "foo", "bar" },
  460. { "baz", "quux" },
  461. { "foo_bar", "baz_quux" }
  462. };
  463. AjaxOptions options = new AjaxOptions { UpdateTargetId = "update-div" };
  464. // Act
  465. MvcHtmlString actionLink = helper.ActionLink("Some Text", "Action", "Controller", values, options, htmlAttributes);
  466. // Assert
  467. Assert.Equal(@"<a baz=""quux"" data-ajax=""true"" data-ajax-mode=""replace"" data-ajax-update=""#update-div"" foo=""bar"" foo_bar=""baz_quux"" href=""" + MvcHelper.AppPathModifier + @"/app/Controller/Action/5"">Some Text</a>", actionLink.ToHtmlString());
  468. }
  469. [Fact]
  470. public void ActionLinkWithOptions()
  471. {
  472. // Arrange
  473. AjaxHelper ajaxHelper = GetAjaxHelper(unobtrusiveJavaScript: false);
  474. // Act
  475. MvcHtmlString actionLink = ajaxHelper.ActionLink("linkText", "Action", "Controller", new AjaxOptions { UpdateTargetId = "some-id" });
  476. // Assert
  477. Assert.Equal(@"<a href=""" + MvcHelper.AppPathModifier + @"/app/Controller/Action"" onclick=""Sys.Mvc.AsyncHyperlink.handleClick(this, new Sys.UI.DomEvent(event), { insertionMode: Sys.Mvc.InsertionMode.replace, updateTargetId: &#39;some-id&#39; });"">linkText</a>", actionLink.ToHtmlString());
  478. }
  479. [Fact]
  480. public void ActionLinkWithOptions_Unobtrusive()
  481. {
  482. // Arrange
  483. AjaxHelper ajaxHelper = GetAjaxHelper(unobtrusiveJavaScript: true);
  484. AjaxOptions options = new AjaxOptions { UpdateTargetId = "some-id" };
  485. // Act
  486. MvcHtmlString actionLink = ajaxHelper.ActionLink("linkText", "Action", "Controller", options);
  487. // Assert
  488. Assert.Equal(@"<a data-ajax=""true"" data-ajax-mode=""replace"" data-ajax-update=""#some-id"" href=""" + MvcHelper.AppPathModifier + @"/app/Controller/Action"">linkText</a>", actionLink.ToHtmlString());
  489. }
  490. [Fact]
  491. public void ActionLinkWithNullHostName()
  492. {
  493. // Arrange
  494. AjaxHelper ajaxHelper = GetAjaxHelper(unobtrusiveJavaScript: false);
  495. // Act
  496. MvcHtmlString actionLink = ajaxHelper.ActionLink("linkText", "Action", "Controller",
  497. null, null, null, null, new AjaxOptions { UpdateTargetId = "some-id" }, null);
  498. // Assert
  499. Assert.Equal(@"<a href=""" + MvcHelper.AppPathModifier + @"/app/Controller/Action"" onclick=""Sys.Mvc.AsyncHyperlink.handleClick(this, new Sys.UI.DomEvent(event), { insertionMode: Sys.Mvc.InsertionMode.replace, updateTargetId: &#39;some-id&#39; });"">linkText</a>", actionLink.ToHtmlString());
  500. }
  501. [Fact]
  502. public void ActionLinkWithNullHostName_Unobtrusive()
  503. {
  504. // Arrange
  505. AjaxHelper ajaxHelper = GetAjaxHelper(unobtrusiveJavaScript: true);
  506. // Act
  507. MvcHtmlString actionLink = ajaxHelper.ActionLink("linkText", "Action", "Controller",
  508. null, null, null, null, new AjaxOptions { UpdateTargetId = "some-id" }, null);
  509. // Assert
  510. Assert.Equal(@"<a data-ajax=""true"" data-ajax-mode=""replace"" data-ajax-update=""#some-id"" href=""" + MvcHelper.AppPathModifier + @"/app/Controller/Action"">linkText</a>", actionLink.ToHtmlString());
  511. }
  512. [Fact]
  513. public void ActionLinkWithProtocol()
  514. {
  515. // Arrange
  516. AjaxHelper ajaxHelper = GetAjaxHelper(unobtrusiveJavaScript: false);
  517. // Act
  518. MvcHtmlString actionLink = ajaxHelper.ActionLink("linkText", "Action", "Controller", "https", null, null, null, new AjaxOptions { UpdateTargetId = "some-id" }, null);
  519. // Assert
  520. Assert.Equal(@"<a href=""https://foo.bar.baz" + MvcHelper.AppPathModifier + @"/app/Controller/Action"" onclick=""Sys.Mvc.AsyncHyperlink.handleClick(this, new Sys.UI.DomEvent(event), { insertionMode: Sys.Mvc.InsertionMode.replace, updateTargetId: &#39;some-id&#39; });"">linkText</a>", actionLink.ToHtmlString());
  521. }
  522. [Fact]
  523. public void ActionLinkWithProtocol_Unobtrusive()
  524. {
  525. // Arrange
  526. AjaxHelper ajaxHelper = GetAjaxHelper(unobtrusiveJavaScript: true);
  527. // Act
  528. MvcHtmlString actionLink = ajaxHelper.ActionLink("linkText", "Action", "Controller", "https", null, null, null, new AjaxOptions { UpdateTargetId = "some-id" }, null);
  529. // Assert
  530. Assert.Equal(@"<a data-ajax=""true"" data-ajax-mode=""replace"" data-ajax-update=""#some-id"" href=""https://foo.bar.baz" + MvcHelper.AppPathModifier + @"/app/Controller/Action"">linkText</a>", actionLink.ToHtmlString());
  531. }
  532. // RouteLink
  533. [Fact]
  534. public void RouteLinkWithNullOptions()
  535. {
  536. // Arrange
  537. AjaxHelper ajaxHelper = GetAjaxHelper(unobtrusiveJavaScript: false);
  538. // Act
  539. MvcHtmlString routeLink = ajaxHelper.RouteLink("Some Text", new RouteValueDictionary(), null);
  540. // Assert
  541. Assert.Equal(@"<a href=""" + MvcHelper.AppPathModifier + @"/app/home/oldaction"" onclick=""Sys.Mvc.AsyncHyperlink.handleClick(this, new Sys.UI.DomEvent(event), { insertionMode: Sys.Mvc.InsertionMode.replace });"">Some Text</a>", routeLink.ToHtmlString());
  542. }
  543. [Fact]
  544. public void RouteLinkWithNullOptions_Unobtrusive()
  545. {
  546. // Arrange
  547. AjaxHelper ajaxHelper = GetAjaxHelper(unobtrusiveJavaScript: true);
  548. // Act
  549. MvcHtmlString routeLink = ajaxHelper.RouteLink("Some Text", new RouteValueDictionary(), null);
  550. // Assert
  551. Assert.Equal(@"<a data-ajax=""true"" href=""" + MvcHelper.AppPathModifier + @"/app/home/oldaction"">Some Text</a>", routeLink.ToHtmlString());
  552. }
  553. [Fact]
  554. public void RouteLinkAnonymousValues()
  555. {
  556. // Arrange
  557. AjaxHelper helper = GetAjaxHelper(unobtrusiveJavaScript: false);
  558. object values = new
  559. {
  560. action = "Action",
  561. controller = "Controller"
  562. };
  563. AjaxOptions options = new AjaxOptions { UpdateTargetId = "update-div" };
  564. // Act
  565. MvcHtmlString routeLink = helper.RouteLink("Some Text", values, options);
  566. // Assert
  567. Assert.Equal(@"<a href=""" + MvcHelper.AppPathModifier + @"/app/Controller/Action"" onclick=""Sys.Mvc.AsyncHyperlink.handleClick(this, new Sys.UI.DomEvent(event), { insertionMode: Sys.Mvc.InsertionMode.replace, updateTargetId: &#39;update-div&#39; });"">Some Text</a>", routeLink.ToHtmlString());
  568. }
  569. [Fact]
  570. public void RouteLinkAnonymousValues_Unobtrusive()
  571. {
  572. // Arrange
  573. AjaxHelper helper = GetAjaxHelper(unobtrusiveJavaScript: true);
  574. object values = new
  575. {
  576. action = "Action",
  577. controller = "Controller"
  578. };
  579. AjaxOptions options = new AjaxOptions { UpdateTargetId = "update-div" };
  580. // Act
  581. MvcHtmlString routeLink = helper.RouteLink("Some Text", values, options);
  582. // Assert
  583. Assert.Equal(@"<a data-ajax=""true"" data-ajax-mode=""replace"" data-ajax-update=""#update-div"" href=""" + MvcHelper.AppPathModifier + @"/app/Controller/Action"">Some Text</a>", routeLink.ToHtmlString());
  584. }
  585. [Fact]
  586. public void RouteLinkAnonymousValuesAndAttributes()
  587. {
  588. // Arrange
  589. AjaxHelper helper = GetAjaxHelper(unobtrusiveJavaScript: false);
  590. object htmlAttributes = new
  591. {
  592. foo = "bar",
  593. baz = "quux",
  594. foo_bar = "baz_quux"
  595. };
  596. object values = new
  597. {
  598. action = "Action",
  599. controller = "Controller"
  600. };
  601. AjaxOptions options = new AjaxOptions { UpdateTargetId = "update-div" };
  602. // Act
  603. MvcHtmlString actionLink = helper.RouteLink("Some Text", values, options, htmlAttributes);
  604. // Assert
  605. Assert.Equal(@"<a baz=""quux"" foo=""bar"" foo-bar=""baz_quux"" href=""" + MvcHelper.AppPathModifier + @"/app/Controller/Action"" onclick=""Sys.Mvc.AsyncHyperlink.handleClick(this, new Sys.UI.DomEvent(event), { insertionMode: Sys.Mvc.InsertionMode.replace, updateTargetId: &#39;update-div&#39; });"">Some Text</a>", actionLink.ToHtmlString());
  606. }
  607. [Fact]
  608. public void RouteLinkAnonymousValuesAndAttributes_Unobtrusive()
  609. {
  610. // Arrange
  611. AjaxHelper helper = GetAjaxHelper(unobtrusiveJavaScript: true);
  612. object htmlAttributes = new
  613. {
  614. foo = "bar",
  615. baz = "quux",
  616. foo_bar = "baz_quux"
  617. };
  618. object values = new
  619. {
  620. action = "Action",
  621. controller = "Controller"
  622. };
  623. AjaxOptions options = new AjaxOptions { UpdateTargetId = "update-div" };
  624. // Act
  625. MvcHtmlString actionLink = helper.RouteLink("Some Text", values, options, htmlAttributes);
  626. // Assert
  627. Assert.Equal(@"<a baz=""quux"" data-ajax=""true"" data-ajax-mode=""replace"" data-ajax-update=""#update-div"" foo=""bar"" foo-bar=""baz_quux"" href=""" + MvcHelper.AppPathModifier + @"/app/Controller/Action"">Some Text</a>", actionLink.ToHtmlString());
  628. }
  629. [Fact]
  630. public void RouteLinkTypedValues()
  631. {
  632. // Arrange
  633. AjaxHelper helper = GetAjaxHelper(unobtrusiveJavaScript: false);
  634. RouteValueDictionary values = new RouteValueDictionary
  635. {
  636. { "controller", "Controller" },
  637. { "action", "Action" }
  638. };
  639. AjaxOptions options = new AjaxOptions { UpdateTargetId = "update-div" };
  640. // Act
  641. MvcHtmlString actionLink = helper.RouteLink("Some Text", values, options);
  642. // Assert
  643. Assert.Equal(@"<a href=""" + MvcHelper.AppPathModifier + @"/app/Controller/Action"" onclick=""Sys.Mvc.AsyncHyperlink.handleClick(this, new Sys.UI.DomEvent(event), { insertionMode: Sys.Mvc.InsertionMode.replace, updateTargetId: &#39;update-div&#39; });"">Some Text</a>", actionLink.ToHtmlString());
  644. }
  645. [Fact]
  646. public void RouteLinkTypedValues_Unobtrusive()
  647. {
  648. // Arrange
  649. AjaxHelper helper = GetAjaxHelper(unobtrusiveJavaScript: true);
  650. RouteValueDictionary values = new RouteValueDictionary
  651. {
  652. { "controller", "Controller" },
  653. { "action", "Action" }
  654. };
  655. AjaxOptions options = new AjaxOptions { UpdateTargetId = "update-div" };
  656. // Act
  657. MvcHtmlString actionLink = helper.RouteLink("Some Text", values, options);
  658. // Assert
  659. Assert.Equal(@"<a data-ajax=""true"" data-ajax-mode=""replace"" data-ajax-update=""#update-div"" href=""" + MvcHelper.AppPathModifier + @"/app/Controller/Action"">Some Text</a>", actionLink.ToHtmlString());
  660. }
  661. [Fact]
  662. public void RouteLinkTypedValuesAndAttributes()
  663. {
  664. // Arrange
  665. AjaxHelper helper = GetAjaxHelper(unobtrusiveJavaScript: false);
  666. RouteValueDictionary values = new RouteValueDictionary
  667. {
  668. { "controller", "Controller" },
  669. { "action", "Action" }
  670. };
  671. Dictionary<string, object> htmlAttributes = new Dictionary<string, object>
  672. {
  673. { "foo", "bar" },
  674. { "baz", "quux" },
  675. { "foo_bar", "baz_quux" }
  676. };
  677. AjaxOptions options = new AjaxOptions { UpdateTargetId = "update-div" };
  678. // Act
  679. MvcHtmlString actionLink = helper.RouteLink("Some Text", values, options, htmlAttributes);
  680. // Assert
  681. Assert.Equal(@"<a baz=""quux"" foo=""bar"" foo_bar=""baz_quux"" href=""" + MvcHelper.AppPathModifier + @"/app/Controller/Action"" onclick=""Sys.Mvc.AsyncHyperlink.handleClick(this, new Sys.UI.DomEvent(event), { insertionMode: Sys.Mvc.InsertionMode.replace, updateTargetId: &#39;update-div&#39; });"">Some Text</a>", actionLink.ToHtmlString());
  682. }
  683. [Fact]
  684. public void RouteLinkTypedValuesAndAttributes_Unobtrusive()
  685. {
  686. // Arrange
  687. AjaxHelper helper = GetAjaxHelper(unobtrusiveJavaScript: true);
  688. RouteValueDictionary values = new RouteValueDictionary
  689. {
  690. { "controller", "Controller" },
  691. { "action", "Action" }
  692. };
  693. Dictionary<string, object> htmlAttributes = new Dictionary<string, object>
  694. {
  695. { "foo", "bar" },
  696. { "baz", "quux" },
  697. { "foo_bar", "baz_quux" }
  698. };
  699. AjaxOptions options = new AjaxOptions { UpdateTargetId = "update-div" };
  700. // Act
  701. MvcHtmlString actionLink = helper.RouteLink("Some Text", values, options, htmlAttributes);
  702. // Assert
  703. Assert.Equal(@"<a baz=""quux"" data-ajax=""true"" data-ajax-mode=""replace"" data-ajax-update=""#update-div"" foo=""bar"" foo_bar=""baz_quux"" href=""" + MvcHelper.AppPathModifier + @"/app/Controller/Action"">Some Text</a>", actionLink.ToHtmlString());
  704. }
  705. [Fact]
  706. public void RouteLinkNamedRoute()
  707. {
  708. // Arrange
  709. AjaxHelper ajaxHelper = GetAjaxHelper(unobtrusiveJavaScript: false);
  710. // Act
  711. MvcHtmlString actionLink = ajaxHelper.RouteLink("linkText", "namedroute", new AjaxOptions());
  712. // Assert
  713. Assert.Equal(@"<a href=""" + MvcHelper.AppPathModifier + @"/app/named/home/oldaction"" onclick=""Sys.Mvc.AsyncHyperlink.handleClick(this, new Sys.UI.DomEvent(event), { insertionMode: Sys.Mvc.InsertionMode.replace });"">linkText</a>", actionLink.ToHtmlString());
  714. }
  715. [Fact]
  716. public void RouteLinkNamedRoute_Unobtrusive()
  717. {
  718. // Arrange
  719. AjaxHelper ajaxHelper = GetAjaxHelper(unobtrusiveJavaScript: true);
  720. // Act
  721. MvcHtmlString actionLink = ajaxHelper.RouteLink("linkText", "namedroute", new AjaxOptions());
  722. // Assert
  723. Assert.Equal(@"<a data-ajax=""true"" href=""" + MvcHelper.AppPathModifier + @"/app/named/home/oldaction"">linkText</a>", actionLink.ToHtmlString());
  724. }
  725. [Fact]
  726. public void RouteLinkNamedRouteAnonymousAttributes()
  727. {
  728. // Arrange
  729. AjaxHelper ajaxHelper = GetAjaxHelper(unobtrusiveJavaScript: false);
  730. object htmlAttributes = new
  731. {
  732. foo = "bar",
  733. baz = "quux",
  734. foo_bar = "baz_quux"
  735. };
  736. AjaxOptions options = new AjaxOptions { UpdateTargetId = "update-div" };
  737. // Act
  738. MvcHtmlString actionLink = ajaxHelper.RouteLink("Some Text", "namedroute", options, htmlAttributes);
  739. // Assert
  740. Assert.Equal(@"<a baz=""quux"" foo=""bar"" foo-bar=""baz_quux"" href=""" + MvcHelper.AppPathModifier + @"/app/named/home/oldaction"" onclick=""Sys.Mvc.AsyncHyperlink.handleClick(this, new Sys.UI.DomEvent(event), { insertionMode: Sys.Mvc.InsertionMode.replace, updateTargetId: &#39;update-div&#39; });"">Some Text</a>", actionLink.ToHtmlString());
  741. }
  742. [Fact]
  743. public void RouteLinkNamedRouteAnonymousAttributes_Unobtrusive()
  744. {
  745. // Arrange
  746. AjaxHelper ajaxHelper = GetAjaxHelper(unobtrusiveJavaScript: true);
  747. object htmlAttributes = new
  748. {
  749. foo = "bar",
  750. baz = "quux",
  751. foo_bar = "baz_quux"
  752. };
  753. AjaxOptions options = new AjaxOptions { UpdateTargetId = "update-div" };
  754. // Act
  755. MvcHtmlString actionLink = ajaxHelper.RouteLink("Some Text", "namedroute", options, htmlAttributes);
  756. // Assert
  757. Assert.Equal(@"<a baz=""quux"" data-ajax=""true"" data-ajax-mode=""replace"" data-ajax-update=""#update-div"" foo=""bar"" foo-bar=""baz_quux"" href=""" + MvcHelper.AppPathModifier + @"/app/named/home/oldaction"">Some Text</a>", actionLink.ToHtmlString());
  758. }
  759. [Fact]
  760. public void RouteLinkNamedRouteTypedAttributes()
  761. {
  762. // Arrange
  763. AjaxHelper ajaxHelper = GetAjaxHelper(unobtrusiveJavaScript: false);
  764. Dictionary<string, object> htmlAttributes = new Dictionary<string, object> { { "foo", "bar" }, { "baz", "quux" }, { "foo_bar", "baz_quux" } };
  765. AjaxOptions options = new AjaxOptions { UpdateTargetId = "update-div" };
  766. // Act
  767. MvcHtmlString actionLink = ajaxHelper.RouteLink("Some Text", "namedroute", options, htmlAttributes);
  768. // Assert
  769. Assert.Equal(@"<a baz=""quux"" foo=""bar"" foo_bar=""baz_quux"" href=""" + MvcHelper.AppPathModifier + @"/app/named/home/oldaction"" onclick=""Sys.Mvc.AsyncHyperlink.handleClick(this, new Sys.UI.DomEvent(event), { insertionMode: Sys.Mvc.InsertionMode.replace, updateTargetId: &#39;update-div&#39; });"">Some Text</a>", actionLink.ToHtmlString());
  770. }
  771. [Fact]
  772. public void RouteLinkNamedRouteTypedAttributes_Unobtrusive()
  773. {
  774. // Arrange
  775. AjaxHelper ajaxHelper = GetAjaxHelper(unobtrusiveJavaScript: true);
  776. Dictionary<string, object> htmlAttributes = new Dictionary<string, object> { { "foo", "bar" }, { "baz", "quux" }, { "foo_bar", "baz_quux" } };
  777. AjaxOptions options = new AjaxOptions { UpdateTargetId = "update-div" };
  778. // Act
  779. MvcHtmlString actionLink = ajaxHelper.RouteLink("Some Text", "namedroute", options, htmlAttributes);
  780. // Assert
  781. Assert.Equal(@"<a baz=""quux"" data-ajax=""true"" data-ajax-mode=""replace"" data-ajax-update=""#update-div"" foo=""bar"" foo_bar=""baz_quux"" href=""" + MvcHelper.AppPathModifier + @"/app/named/home/oldaction"">Some Text</a>", actionLink.ToHtmlString());
  782. }
  783. [Fact]
  784. public void RouteLinkNamedRouteWithAnonymousValues()
  785. {
  786. // Arrange
  787. AjaxHelper ajaxHelper = GetAjaxHelper(unobtrusiveJavaScript: false);
  788. object values = new
  789. {
  790. action = "Action",
  791. controller = "Controller"
  792. };
  793. // Act
  794. MvcHtmlString actionLink = ajaxHelper.RouteLink("linkText", "namedroute", values, new AjaxOptions());
  795. // Assert
  796. Assert.Equal(@"<a href=""" + MvcHelper.AppPathModifier + @"/app/named/Controller/Action"" onclick=""Sys.Mvc.AsyncHyperlink.handleClick(this, new Sys.UI.DomEvent(event), { insertionMode: Sys.Mvc.InsertionMode.replace });"">linkText</a>", actionLink.ToHtmlString());
  797. }
  798. [Fact]
  799. public void RouteLinkNamedRouteWithAnonymousValues_Unobtrusive()
  800. {
  801. // Arrange
  802. AjaxHelper ajaxHelper = GetAjaxHelper(unobtrusiveJavaScript: true);
  803. object values = new
  804. {
  805. action = "Action",
  806. controller = "Controller"
  807. };
  808. // Act
  809. MvcHtmlString actionLink = ajaxHelper.RouteLink("linkText", "namedroute", values, new AjaxOptions());
  810. // Assert
  811. Assert.Equal(@"<a data-ajax=""true"" href=""" + MvcHelper.AppPathModifier + @"/app/named/Controller/Action"">linkText</a>", actionLink.ToHtmlString());
  812. }
  813. [Fact]
  814. public void RouteLinkNamedRouteAnonymousValuesAndAttributes()
  815. {
  816. // Arrange
  817. AjaxHelper ajaxHelper = GetAjaxHelper(unobtrusiveJavaScript: false);
  818. object values = new
  819. {
  820. action = "Action",
  821. controller = "Controller"
  822. };
  823. object htmlAttributes = new
  824. {
  825. foo = "bar",
  826. baz = "quux",
  827. foo_bar = "baz_quux"
  828. };
  829. AjaxOptions options = new AjaxOptions { UpdateTargetId = "update-div" };
  830. // Act
  831. MvcHtmlString actionLink = ajaxHelper.RouteLink("Some Text", "namedroute", values, options, htmlAttributes);
  832. // Assert
  833. Assert.Equal(@"<a baz=""quux"" foo=""bar"" foo-bar=""baz_quux"" href=""" + MvcHelper.AppPathModifier + @"/app/named/Controller/Action"" onclick=""Sys.Mvc.AsyncHyperlink.handleClick(this, new Sys.UI.DomEvent(event), { insertionMode: Sys.Mvc.InsertionMode.replace, updateTargetId: &#39;update-div&#39; });"">Some Text</a>", actionLink.ToHtmlString());
  834. }
  835. [Fact]
  836. public void RouteLinkNamedRouteAnonymousValuesAndAttributes_Unobtrusive()
  837. {
  838. // Arrange
  839. AjaxHelper ajaxHelper = GetAjaxHelper(unobtrusiveJavaScript: true);
  840. object values = new
  841. {
  842. action = "Action",
  843. controller = "Controller"
  844. };
  845. object htmlAttributes = new
  846. {
  847. foo = "bar",
  848. baz = "quux",
  849. foo_bar = "baz_quux"
  850. };
  851. AjaxOptions options = new AjaxOptions { UpdateTargetId = "update-div" };
  852. // Act
  853. MvcHtmlString actionLink = ajaxHelper.RouteLink("Some Text", "namedroute", values, options, htmlAttributes);
  854. // Assert
  855. Assert.Equal(@"<a baz=""quux"" data-ajax=""true"" data-ajax-mode=""replace"" data-ajax-update=""#update-div"" foo=""bar"" foo-bar=""baz_quux"" href=""" + MvcHelper.AppPathModifier + @"/app/named/Controller/Action"">Some Text</a>", actionLink.ToHtmlString());
  856. }
  857. [Fact]
  858. public void RouteLinkNamedRouteWithTypedValues()
  859. {
  860. // Arrange
  861. AjaxHelper ajaxHelper = GetAjaxHelper(unobtrusiveJavaScript: false);
  862. RouteValueDictionary values = new RouteValueDictionary
  863. {
  864. { "controller", "Controller" },
  865. { "action", "Action" }
  866. };
  867. // Act
  868. MvcHtmlString actionLink = ajaxHelper.RouteLink("linkText", "namedroute", values, new AjaxOptions());
  869. // Assert
  870. Assert.Equal(@"<a href=""" + MvcHelper.AppPathModifier + @"/app/named/Controller/Action"" onclick=""Sys.Mvc.AsyncHyperlink.handleClick(this, new Sys.UI.DomEvent(event), { insertionMode: Sys.Mvc.InsertionMode.replace });"">linkText</a>", actionLink.ToHtmlString());
  871. }
  872. [Fact]
  873. public void RouteLinkNamedRouteWithTypedValues_Unobtrusive()
  874. {
  875. // Arrange
  876. AjaxHelper ajaxHelper = GetAjaxHelper(unobtrusiveJavaScript: true);
  877. RouteValueDictionary values = new RouteValueDictionary
  878. {
  879. { "controller", "Controller" },
  880. { "action", "Action" }
  881. };
  882. // Act
  883. MvcHtmlString actionLink = ajaxHelper.RouteLink("linkText", "namedroute", values, new AjaxOptions());
  884. // Assert
  885. Assert.Equal(@"<a data-ajax=""true"" href=""" + MvcHelper.AppPathModifier + @"/app/named/Controller/Action"">linkText</a>", actionLink.ToHtmlString());
  886. }
  887. [Fact]
  888. public void RouteLinkNamedRouteTypedValuesAndAttributes()
  889. {
  890. // Arrange
  891. AjaxHelper ajaxHelper = GetAjaxHelper(unobtrusiveJavaScript: false);
  892. RouteValueDictionary values = new RouteValueDictionary
  893. {
  894. { "controller", "Controller" },
  895. { "action", "Action" }
  896. };
  897. Dictionary<string, object> htmlAttributes = new Dictionary<string, object> { { "foo", "bar" }, { "baz", "quux" }, { "foo_bar", "baz_quux" } };
  898. AjaxOptions options = new AjaxOptions { UpdateTargetId = "update-div" };
  899. // Act
  900. MvcHtmlString actionLink = ajaxHelper.RouteLink("Some Text", "namedroute", values, options, htmlAttributes);
  901. // Assert
  902. Assert.Equal(@"<a baz=""quux"" foo=""bar"" foo_bar=""baz_quux"" href=""" + MvcHelper.AppPathModifier + @"/app/named/Controller/Action"" onclick=""Sys.Mvc.AsyncHyperlink.handleClick(this, new Sys.UI.DomEvent(event), { insertionMode: Sys.Mvc.InsertionMode.replace, updateTargetId: &#39;update-div&#39; });"">Some Text</a>", actionLink.ToHtmlString());
  903. }
  904. [Fact]
  905. public void RouteLinkNamedRouteTypedValuesAndAttributes_Unobtrusive()
  906. {
  907. // Arrange
  908. AjaxHelper ajaxHelper = GetAjaxHelper(unobtrusiveJavaScript: true);
  909. RouteValueDictionary values = new RouteValueDictionary
  910. {
  911. { "controller", "Controller" },
  912. { "action", "Action" }
  913. };
  914. Dictionary<string, object> htmlAttributes = new Dictionary<string, object> { { "foo", "bar" }, { "baz", "quux" }, { "foo_bar", "baz_quux" } };
  915. AjaxOptions options = new AjaxOptions { UpdateTargetId = "update-div" };
  916. // Act
  917. MvcHtmlString actionLink = ajaxHelper.RouteLink("Some Text", "namedroute", values, options, htmlAttributes);
  918. // Assert
  919. Assert.Equal(@"<a baz=""quux"" data-ajax=""true"" data-ajax-mode=""replace"" data-ajax