PageRenderTime 27ms CodeModel.GetById 14ms RepoModel.GetById 1ms app.codeStats 0ms

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

https://bitbucket.org/mdavid/aspnetwebstack
C# | 629 lines | 385 code | 125 blank | 119 comment | 0 complexity | 155702bef6ccf6c822aba1a024c9e976 MD5 | raw file
  1. using System.Web.Mvc.Test;
  2. using System.Web.Routing;
  3. using Microsoft.Web.UnitTestUtil;
  4. using Xunit;
  5. using Assert = Microsoft.TestCommon.AssertEx;
  6. namespace System.Web.Mvc.Html.Test
  7. {
  8. public class TextAreaExtensionsTest
  9. {
  10. private static readonly RouteValueDictionary _textAreaAttributesDictionary = new RouteValueDictionary(new { rows = "15", cols = "12" });
  11. private static readonly object _textAreaAttributesObjectDictionary = new { rows = "15", cols = "12" };
  12. private static readonly object _textAreaAttributesObjectUnderscoresDictionary = new { rows = "15", cols = "12", foo_bar = "baz" };
  13. private class TextAreaModel
  14. {
  15. public string foo { get; set; }
  16. public string bar { get; set; }
  17. }
  18. private static ViewDataDictionary<TextAreaModel> GetTextAreaViewData()
  19. {
  20. ViewDataDictionary<TextAreaModel> viewData = new ViewDataDictionary<TextAreaModel> { { "foo", "ViewDataFoo" } };
  21. viewData.Model = new TextAreaModel { foo = "ViewItemFoo", bar = "ViewItemBar" };
  22. return viewData;
  23. }
  24. private static ViewDataDictionary<TextAreaModel> GetTextAreaViewDataWithErrors()
  25. {
  26. ViewDataDictionary<TextAreaModel> viewData = new ViewDataDictionary<TextAreaModel> { { "foo", "ViewDataFoo" } };
  27. viewData.Model = new TextAreaModel { foo = "ViewItemFoo", bar = "ViewItemBar" };
  28. ModelState modelStateFoo = new ModelState();
  29. modelStateFoo.Errors.Add(new ModelError("foo error 1"));
  30. modelStateFoo.Errors.Add(new ModelError("foo error 2"));
  31. viewData.ModelState["foo"] = modelStateFoo;
  32. modelStateFoo.Value = HtmlHelperTest.GetValueProviderResult(new string[] { "AttemptedValueFoo" }, "AttemptedValueFoo");
  33. return viewData;
  34. }
  35. // TextArea
  36. [Fact]
  37. public void TextAreaParameterDictionaryMerging()
  38. {
  39. // Arrange
  40. HtmlHelper helper = MvcHelper.GetHtmlHelper();
  41. // Act
  42. MvcHtmlString html = helper.TextArea("foo", new { rows = "30" });
  43. // Assert
  44. Assert.Equal(@"<textarea cols=""20"" id=""foo"" name=""foo"" rows=""30"">
  45. </textarea>", html.ToHtmlString());
  46. }
  47. [Fact]
  48. public void TextAreaParameterDictionaryMerging_Unobtrusive()
  49. {
  50. // Arrange
  51. HtmlHelper helper = MvcHelper.GetHtmlHelper();
  52. helper.ViewContext.ClientValidationEnabled = true;
  53. helper.ViewContext.UnobtrusiveJavaScriptEnabled = true;
  54. helper.ViewContext.FormContext = new FormContext();
  55. helper.ClientValidationRuleFactory = (name, metadata) => new[] { new ModelClientValidationRule { ValidationType = "type", ErrorMessage = "error" } };
  56. // Act
  57. MvcHtmlString html = helper.TextArea("foo", new { rows = "30" });
  58. // Assert
  59. Assert.Equal(@"<textarea cols=""20"" data-val=""true"" data-val-type=""error"" id=""foo"" name=""foo"" rows=""30"">
  60. </textarea>", html.ToHtmlString());
  61. }
  62. [Fact]
  63. public void TextAreaParameterDictionaryMergingExplicitParameters()
  64. {
  65. // Arrange
  66. HtmlHelper helper = MvcHelper.GetHtmlHelper();
  67. // Act
  68. MvcHtmlString html = helper.TextArea("foo", "bar", 10, 25, new { rows = "30" });
  69. // Assert
  70. Assert.Equal(@"<textarea cols=""25"" id=""foo"" name=""foo"" rows=""10"">
  71. bar</textarea>", html.ToHtmlString());
  72. }
  73. [Fact]
  74. public void TextAreaParameterDictionaryMergingExplicitParametersWithUnderscores()
  75. {
  76. // Arrange
  77. HtmlHelper helper = MvcHelper.GetHtmlHelper();
  78. // Act
  79. MvcHtmlString html = helper.TextArea("foo", "bar", 10, 25, new { rows = "30", foo_bar = "baz" });
  80. // Assert
  81. Assert.Equal(@"<textarea cols=""25"" foo-bar=""baz"" id=""foo"" name=""foo"" rows=""10"">
  82. bar</textarea>", html.ToHtmlString());
  83. }
  84. [Fact]
  85. public void TextAreaWithEmptyNameThrows()
  86. {
  87. // Arrange
  88. HtmlHelper helper = MvcHelper.GetHtmlHelper();
  89. // Act & Assert
  90. Assert.ThrowsArgumentNullOrEmpty(
  91. delegate { helper.TextArea(String.Empty); },
  92. "name");
  93. }
  94. [Fact]
  95. public void TextAreaWithOutOfRangeColsThrows()
  96. {
  97. // Arrange
  98. HtmlHelper helper = MvcHelper.GetHtmlHelper();
  99. // Act & Assert
  100. Assert.ThrowsArgumentOutOfRange(
  101. delegate { helper.TextArea("Foo", null /* value */, 0, -1, null /* htmlAttributes */); },
  102. "columns",
  103. @"The value must be greater than or equal to zero.");
  104. }
  105. [Fact]
  106. public void TextAreaWithOutOfRangeRowsThrows()
  107. {
  108. // Arrange
  109. HtmlHelper helper = MvcHelper.GetHtmlHelper();
  110. // Act & Assert
  111. Assert.ThrowsArgumentOutOfRange(
  112. delegate { helper.TextArea("Foo", null /* value */, -1, 0, null /* htmlAttributes */); },
  113. "rows",
  114. @"The value must be greater than or equal to zero.");
  115. }
  116. [Fact]
  117. public void TextAreaWithExplicitValue()
  118. {
  119. // Arrange
  120. HtmlHelper helper = MvcHelper.GetHtmlHelper();
  121. // Act
  122. MvcHtmlString html = helper.TextArea("foo", "bar");
  123. // Assert
  124. Assert.Equal(@"<textarea cols=""20"" id=""foo"" name=""foo"" rows=""2"">
  125. bar</textarea>", html.ToHtmlString());
  126. }
  127. [Fact]
  128. public void TextAreaWithDefaultAttributes()
  129. {
  130. // Arrange
  131. HtmlHelper helper = MvcHelper.GetHtmlHelper(GetTextAreaViewData());
  132. // Act
  133. MvcHtmlString html = helper.TextArea("foo");
  134. // Assert
  135. Assert.Equal(@"<textarea cols=""20"" id=""foo"" name=""foo"" rows=""2"">
  136. ViewDataFoo</textarea>", html.ToHtmlString());
  137. }
  138. [Fact]
  139. public void TextAreaWithZeroRowsAndColumns()
  140. {
  141. // Arrange
  142. HtmlHelper helper = MvcHelper.GetHtmlHelper(GetTextAreaViewData());
  143. // Act
  144. MvcHtmlString html = helper.TextArea("foo", null, 0, 0, null);
  145. // Assert
  146. Assert.Equal(@"<textarea id=""foo"" name=""foo"">
  147. ViewDataFoo</textarea>", html.ToHtmlString());
  148. }
  149. [Fact]
  150. public void TextAreaWithDotReplacementForId()
  151. {
  152. // Arrange
  153. HtmlHelper helper = MvcHelper.GetHtmlHelper(GetTextAreaViewData());
  154. // Act
  155. MvcHtmlString html = helper.TextArea("foo.bar.baz");
  156. // Assert
  157. Assert.Equal(@"<textarea cols=""20"" id=""foo_bar_baz"" name=""foo.bar.baz"" rows=""2"">
  158. </textarea>", html.ToHtmlString());
  159. }
  160. [Fact]
  161. public void TextAreaWithObjectAttributes()
  162. {
  163. // Arrange
  164. HtmlHelper helper = MvcHelper.GetHtmlHelper(GetTextAreaViewData());
  165. // Act
  166. MvcHtmlString html = helper.TextArea("foo", _textAreaAttributesObjectDictionary);
  167. // Assert
  168. Assert.Equal(@"<textarea cols=""12"" id=""foo"" name=""foo"" rows=""15"">
  169. ViewDataFoo</textarea>", html.ToHtmlString());
  170. }
  171. [Fact]
  172. public void TextAreaWithObjectAttributesWithUnderscores()
  173. {
  174. // Arrange
  175. HtmlHelper helper = MvcHelper.GetHtmlHelper(GetTextAreaViewData());
  176. // Act
  177. MvcHtmlString html = helper.TextArea("foo", _textAreaAttributesObjectUnderscoresDictionary);
  178. // Assert
  179. Assert.Equal(@"<textarea cols=""12"" foo-bar=""baz"" id=""foo"" name=""foo"" rows=""15"">
  180. ViewDataFoo</textarea>", html.ToHtmlString());
  181. }
  182. [Fact]
  183. public void TextAreaWithDictionaryAttributes()
  184. {
  185. // Arrange
  186. HtmlHelper helper = MvcHelper.GetHtmlHelper(GetTextAreaViewData());
  187. // Act
  188. MvcHtmlString html = helper.TextArea("foo", _textAreaAttributesDictionary);
  189. // Assert
  190. Assert.Equal(@"<textarea cols=""12"" id=""foo"" name=""foo"" rows=""15"">
  191. ViewDataFoo</textarea>", html.ToHtmlString());
  192. }
  193. [Fact]
  194. public void TextAreaWithExplicitValueAndObjectAttributes()
  195. {
  196. // Arrange
  197. HtmlHelper helper = MvcHelper.GetHtmlHelper(GetTextAreaViewData());
  198. // Act
  199. MvcHtmlString html = helper.TextArea("foo", "Hello World", _textAreaAttributesObjectDictionary);
  200. // Assert
  201. Assert.Equal(@"<textarea cols=""12"" id=""foo"" name=""foo"" rows=""15"">
  202. Hello World</textarea>", html.ToHtmlString());
  203. }
  204. [Fact]
  205. public void TextAreaWithExplicitValueAndObjectAttributesWithUnderscores()
  206. {
  207. // Arrange
  208. HtmlHelper helper = MvcHelper.GetHtmlHelper(GetTextAreaViewData());
  209. // Act
  210. MvcHtmlString html = helper.TextArea("foo", "Hello World", _textAreaAttributesObjectUnderscoresDictionary);
  211. // Assert
  212. Assert.Equal(@"<textarea cols=""12"" foo-bar=""baz"" id=""foo"" name=""foo"" rows=""15"">
  213. Hello World</textarea>", html.ToHtmlString());
  214. }
  215. [Fact]
  216. public void TextAreaWithExplicitValueAndDictionaryAttributes()
  217. {
  218. // Arrange
  219. HtmlHelper helper = MvcHelper.GetHtmlHelper(GetTextAreaViewData());
  220. // Act
  221. MvcHtmlString html = helper.TextArea("foo", "<Hello World>", _textAreaAttributesDictionary);
  222. // Assert
  223. Assert.Equal(@"<textarea cols=""12"" id=""foo"" name=""foo"" rows=""15"">
  224. &lt;Hello World&gt;</textarea>", html.ToHtmlString());
  225. }
  226. [Fact]
  227. public void TextAreaWithNoValueAndObjectAttributes()
  228. {
  229. // Arrange
  230. HtmlHelper helper = MvcHelper.GetHtmlHelper(GetTextAreaViewData());
  231. // Act
  232. MvcHtmlString html = helper.TextArea("baz", _textAreaAttributesObjectDictionary);
  233. // Assert
  234. Assert.Equal(@"<textarea cols=""12"" id=""baz"" name=""baz"" rows=""15"">
  235. </textarea>", html.ToHtmlString());
  236. }
  237. [Fact]
  238. public void TextAreaWithNullValue()
  239. {
  240. // Arrange
  241. HtmlHelper helper = MvcHelper.GetHtmlHelper(GetTextAreaViewData());
  242. // Act
  243. MvcHtmlString html = helper.TextArea("foo", null, null);
  244. // Assert
  245. Assert.Equal(@"<textarea cols=""20"" id=""foo"" name=""foo"" rows=""2"">
  246. ViewDataFoo</textarea>", html.ToHtmlString());
  247. }
  248. [Fact]
  249. public void TextAreaWithViewDataErrors()
  250. {
  251. // Arrange
  252. HtmlHelper helper = MvcHelper.GetHtmlHelper(GetTextAreaViewDataWithErrors());
  253. // Act
  254. MvcHtmlString html = helper.TextArea("foo", _textAreaAttributesObjectDictionary);
  255. // Assert
  256. Assert.Equal(@"<textarea class=""input-validation-error"" cols=""12"" id=""foo"" name=""foo"" rows=""15"">
  257. AttemptedValueFoo</textarea>", html.ToHtmlString());
  258. }
  259. [Fact]
  260. public void TextAreaWithViewDataErrorsAndCustomClass()
  261. {
  262. // Arrange
  263. HtmlHelper helper = MvcHelper.GetHtmlHelper(GetTextAreaViewDataWithErrors());
  264. // Act
  265. MvcHtmlString html = helper.TextArea("foo", new { @class = "foo-class" });
  266. // Assert
  267. Assert.Equal(@"<textarea class=""input-validation-error foo-class"" cols=""20"" id=""foo"" name=""foo"" rows=""2"">
  268. AttemptedValueFoo</textarea>", html.ToHtmlString());
  269. }
  270. [Fact]
  271. public void TextAreaWithPrefix()
  272. {
  273. // Arrange
  274. HtmlHelper helper = MvcHelper.GetHtmlHelper();
  275. helper.ViewContext.ViewData.TemplateInfo.HtmlFieldPrefix = "MyPrefix";
  276. // Act
  277. MvcHtmlString html = helper.TextArea("foo", "bar");
  278. // Assert
  279. Assert.Equal(@"<textarea cols=""20"" id=""MyPrefix_foo"" name=""MyPrefix.foo"" rows=""2"">
  280. bar</textarea>", html.ToHtmlString());
  281. }
  282. [Fact]
  283. public void TextAreaWithPrefixAndEmptyName()
  284. {
  285. // Arrange
  286. HtmlHelper helper = MvcHelper.GetHtmlHelper();
  287. helper.ViewContext.ViewData.TemplateInfo.HtmlFieldPrefix = "MyPrefix";
  288. // Act
  289. MvcHtmlString html = helper.TextArea("", "bar");
  290. // Assert
  291. Assert.Equal(@"<textarea cols=""20"" id=""MyPrefix"" name=""MyPrefix"" rows=""2"">
  292. bar</textarea>", html.ToHtmlString());
  293. }
  294. // TextAreaFor
  295. [Fact]
  296. public void TextAreaForWithNullExpression()
  297. {
  298. // Arrange
  299. HtmlHelper<TextAreaModel> helper = MvcHelper.GetHtmlHelper(GetTextAreaViewData());
  300. // Act & Assert
  301. Assert.ThrowsArgumentNull(
  302. () => helper.TextAreaFor<TextAreaModel, object>(null),
  303. "expression"
  304. );
  305. }
  306. [Fact]
  307. public void TextAreaForWithOutOfRangeColsThrows()
  308. {
  309. // Arrange
  310. HtmlHelper<TextAreaModel> helper = MvcHelper.GetHtmlHelper(GetTextAreaViewData());
  311. // Act & Assert
  312. Assert.ThrowsArgumentOutOfRange(
  313. () => helper.TextAreaFor(m => m.foo, 0, -1, null /* htmlAttributes */),
  314. "columns",
  315. "The value must be greater than or equal to zero."
  316. );
  317. }
  318. [Fact]
  319. public void TextAreaForWithOutOfRangeRowsThrows()
  320. {
  321. // Arrange
  322. HtmlHelper<TextAreaModel> helper = MvcHelper.GetHtmlHelper(GetTextAreaViewData());
  323. // Act & Assert
  324. Assert.ThrowsArgumentOutOfRange(
  325. () => helper.TextAreaFor(m => m.foo, -1, 0, null /* htmlAttributes */),
  326. "rows",
  327. "The value must be greater than or equal to zero."
  328. );
  329. }
  330. [Fact]
  331. public void TextAreaForParameterDictionaryMerging()
  332. {
  333. // Arrange
  334. HtmlHelper<TextAreaModel> helper = MvcHelper.GetHtmlHelper(GetTextAreaViewData());
  335. // Act
  336. MvcHtmlString html = helper.TextAreaFor(m => m.foo, new { rows = "30" });
  337. // Assert
  338. Assert.Equal(@"<textarea cols=""20"" id=""foo"" name=""foo"" rows=""30"">
  339. ViewItemFoo</textarea>", html.ToHtmlString());
  340. }
  341. [Fact]
  342. public void TextAreaForParameterDictionaryMerging_Unobtrusive()
  343. {
  344. // Arrange
  345. HtmlHelper<TextAreaModel> helper = MvcHelper.GetHtmlHelper(GetTextAreaViewData());
  346. helper.ViewContext.ClientValidationEnabled = true;
  347. helper.ViewContext.UnobtrusiveJavaScriptEnabled = true;
  348. helper.ViewContext.FormContext = new FormContext();
  349. helper.ClientValidationRuleFactory = (name, metadata) => new[] { new ModelClientValidationRule { ValidationType = "type", ErrorMessage = "error" } };
  350. // Act
  351. MvcHtmlString html = helper.TextAreaFor(m => m.foo, new { rows = "30" });
  352. // Assert
  353. Assert.Equal(@"<textarea cols=""20"" data-val=""true"" data-val-type=""error"" id=""foo"" name=""foo"" rows=""30"">
  354. ViewItemFoo</textarea>", html.ToHtmlString());
  355. }
  356. [Fact]
  357. public void TextAreaForWithDefaultAttributes()
  358. {
  359. // Arrange
  360. HtmlHelper<TextAreaModel> helper = MvcHelper.GetHtmlHelper(GetTextAreaViewData());
  361. // Act
  362. MvcHtmlString html = helper.TextAreaFor(m => m.foo);
  363. // Assert
  364. Assert.Equal(@"<textarea cols=""20"" id=""foo"" name=""foo"" rows=""2"">
  365. ViewItemFoo</textarea>", html.ToHtmlString());
  366. }
  367. [Fact]
  368. public void TextAreaForWithZeroRowsAndColumns()
  369. {
  370. // Arrange
  371. HtmlHelper<TextAreaModel> helper = MvcHelper.GetHtmlHelper(GetTextAreaViewData());
  372. // Act
  373. MvcHtmlString html = helper.TextAreaFor(m => m.foo, 0, 0, null);
  374. // Assert
  375. Assert.Equal(@"<textarea id=""foo"" name=""foo"">
  376. ViewItemFoo</textarea>", html.ToHtmlString());
  377. }
  378. [Fact]
  379. public void TextAreaForWithObjectAttributes()
  380. {
  381. // Arrange
  382. HtmlHelper<TextAreaModel> helper = MvcHelper.GetHtmlHelper(GetTextAreaViewData());
  383. // Act
  384. MvcHtmlString html = helper.TextAreaFor(m => m.foo, _textAreaAttributesObjectDictionary);
  385. // Assert
  386. Assert.Equal(@"<textarea cols=""12"" id=""foo"" name=""foo"" rows=""15"">
  387. ViewItemFoo</textarea>", html.ToHtmlString());
  388. }
  389. [Fact]
  390. public void TextAreaForWithObjectAttributesWithUnderscores()
  391. {
  392. // Arrange
  393. HtmlHelper<TextAreaModel> helper = MvcHelper.GetHtmlHelper(GetTextAreaViewData());
  394. // Act
  395. MvcHtmlString html = helper.TextAreaFor(m => m.foo, _textAreaAttributesObjectUnderscoresDictionary);
  396. // Assert
  397. Assert.Equal(@"<textarea cols=""12"" foo-bar=""baz"" id=""foo"" name=""foo"" rows=""15"">
  398. ViewItemFoo</textarea>", html.ToHtmlString());
  399. }
  400. [Fact]
  401. public void TextAreaForWithDictionaryAttributes()
  402. {
  403. // Arrange
  404. HtmlHelper<TextAreaModel> helper = MvcHelper.GetHtmlHelper(GetTextAreaViewData());
  405. // Act
  406. MvcHtmlString html = helper.TextAreaFor(m => m.foo, _textAreaAttributesDictionary);
  407. // Assert
  408. Assert.Equal(@"<textarea cols=""12"" id=""foo"" name=""foo"" rows=""15"">
  409. ViewItemFoo</textarea>", html.ToHtmlString());
  410. }
  411. [Fact]
  412. public void TextAreaForWithViewDataErrors()
  413. {
  414. // Arrange
  415. HtmlHelper<TextAreaModel> helper = MvcHelper.GetHtmlHelper(GetTextAreaViewDataWithErrors());
  416. // Act
  417. MvcHtmlString html = helper.TextAreaFor(m => m.foo, _textAreaAttributesObjectDictionary);
  418. // Assert
  419. Assert.Equal(@"<textarea class=""input-validation-error"" cols=""12"" id=""foo"" name=""foo"" rows=""15"">
  420. AttemptedValueFoo</textarea>", html.ToHtmlString());
  421. }
  422. [Fact]
  423. public void TextAreaForWithViewDataErrorsAndCustomClass()
  424. {
  425. // Arrange
  426. HtmlHelper<TextAreaModel> helper = MvcHelper.GetHtmlHelper(GetTextAreaViewDataWithErrors());
  427. // Act
  428. MvcHtmlString html = helper.TextAreaFor(m => m.foo, new { @class = "foo-class" });
  429. // Assert
  430. Assert.Equal(@"<textarea class=""input-validation-error foo-class"" cols=""20"" id=""foo"" name=""foo"" rows=""2"">
  431. AttemptedValueFoo</textarea>", html.ToHtmlString());
  432. }
  433. [Fact]
  434. public void TextAreaForWithPrefix()
  435. {
  436. // Arrange
  437. HtmlHelper<TextAreaModel> helper = MvcHelper.GetHtmlHelper(GetTextAreaViewData());
  438. helper.ViewContext.ViewData.TemplateInfo.HtmlFieldPrefix = "MyPrefix";
  439. // Act
  440. MvcHtmlString html = helper.TextAreaFor(m => m.foo);
  441. // Assert
  442. Assert.Equal(@"<textarea cols=""20"" id=""MyPrefix_foo"" name=""MyPrefix.foo"" rows=""2"">
  443. ViewItemFoo</textarea>", html.ToHtmlString());
  444. }
  445. [Fact]
  446. public void TextAreaForWithPrefixAndEmptyName()
  447. {
  448. // Arrange
  449. HtmlHelper<TextAreaModel> helper = MvcHelper.GetHtmlHelper(GetTextAreaViewData());
  450. helper.ViewContext.ViewData.TemplateInfo.HtmlFieldPrefix = "MyPrefix";
  451. // Act
  452. MvcHtmlString html = helper.TextAreaFor(m => m);
  453. // Assert
  454. Assert.Equal(@"<textarea cols=""20"" id=""MyPrefix"" name=""MyPrefix"" rows=""2"">
  455. System.Web.Mvc.Html.Test.TextAreaExtensionsTest+TextAreaModel</textarea>", html.ToHtmlString());
  456. }
  457. [Fact]
  458. public void TextAreaForParameterDictionaryMergingWithObjectValues()
  459. {
  460. // Arrange
  461. HtmlHelper<TextAreaModel> helper = MvcHelper.GetHtmlHelper(GetTextAreaViewData());
  462. // Act
  463. MvcHtmlString html = helper.TextAreaFor(m => m.foo, 10, 25, new { rows = "30" });
  464. // Assert
  465. Assert.Equal(@"<textarea cols=""25"" id=""foo"" name=""foo"" rows=""10"">
  466. ViewItemFoo</textarea>", html.ToHtmlString());
  467. }
  468. [Fact]
  469. public void TextAreaForParameterDictionaryMergingWithObjectValuesWithUnderscores()
  470. {
  471. // Arrange
  472. HtmlHelper<TextAreaModel> helper = MvcHelper.GetHtmlHelper(GetTextAreaViewData());
  473. // Act
  474. MvcHtmlString html = helper.TextAreaFor(m => m.foo, 10, 25, new { rows = "30", foo_bar = "baz" });
  475. // Assert
  476. Assert.Equal(@"<textarea cols=""25"" foo-bar=""baz"" id=""foo"" name=""foo"" rows=""10"">
  477. ViewItemFoo</textarea>", html.ToHtmlString());
  478. }
  479. [Fact]
  480. public void TextAreaForParameterDictionaryMergingWithDictionaryValues()
  481. {
  482. // Arrange
  483. HtmlHelper<TextAreaModel> helper = MvcHelper.GetHtmlHelper(GetTextAreaViewData());
  484. // Act
  485. MvcHtmlString html = helper.TextAreaFor(m => m.foo, 10, 25, new RouteValueDictionary(new { rows = "30" }));
  486. // Assert
  487. Assert.Equal(@"<textarea cols=""25"" id=""foo"" name=""foo"" rows=""10"">
  488. ViewItemFoo</textarea>", html.ToHtmlString());
  489. }
  490. [Fact]
  491. public void TextAreaHelperDoesNotEncodeInnerHtmlPrefix()
  492. {
  493. // Arrange
  494. HtmlHelper helper = MvcHelper.GetHtmlHelper();
  495. ModelMetadata metadata = ModelMetadata.FromStringExpression("foo", helper.ViewData);
  496. metadata.Model = "<model>";
  497. // Act
  498. MvcHtmlString html = TextAreaExtensions.TextAreaHelper(helper, metadata, "testEncoding", rowsAndColumns: null,
  499. htmlAttributes: null, innerHtmlPrefix: "<prefix>");
  500. // Assert
  501. Assert.Equal(@"<textarea id=""testEncoding"" name=""testEncoding""><prefix>&lt;model&gt;</textarea>", html.ToHtmlString());
  502. }
  503. }
  504. }