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

/src/Nancy.Tests/Unit/ViewEngines/SuperSimpleViewEngineTests.cs

https://gitlab.com/ivanm/Sue
C# | 1429 lines | 1030 code | 363 blank | 36 comment | 2 complexity | da3e7bdda1f12a27f33e4149e553af0c MD5 | raw file
Possible License(s): LGPL-2.0

Large files files are truncated, but you can click here to view the full file

  1. namespace Nancy.Tests.Unit.ViewEngines
  2. {
  3. using System;
  4. using System.Collections.Generic;
  5. using System.Dynamic;
  6. using System.Linq;
  7. using FakeItEasy;
  8. using Nancy.Tests.Fakes;
  9. using Nancy.ViewEngines.SuperSimpleViewEngine;
  10. using Xunit;
  11. public class SuperSimpleViewEngineTests
  12. {
  13. private readonly SuperSimpleViewEngine viewEngine;
  14. private readonly IViewEngineHost fakeHost;
  15. public SuperSimpleViewEngineTests()
  16. {
  17. this.fakeHost = new FakeViewEngineHost();
  18. this.viewEngine = new SuperSimpleViewEngine(Enumerable.Empty<ISuperSimpleViewEngineMatcher>());
  19. }
  20. [Fact]
  21. public void Should_expand_partial_inside_each_section()
  22. {
  23. const string input = @"<html><head></head><body>@Each;@Partial['testing'];@EndEach</body></html>";
  24. var fakeViewEngineHost = new FakeViewEngineHost();
  25. fakeViewEngineHost.GetTemplateCallback = (s, m) => "Hi";
  26. var model = new List<string>() { "foo", "bar" };
  27. var result = viewEngine.Render(input, model, fakeViewEngineHost);
  28. Assert.Equal(@"<html><head></head><body>HiHi</body></html>", result);
  29. }
  30. [Fact]
  31. public void Should_expand_multiple_partials_inside_each_section()
  32. {
  33. const string input = @"<html><head></head><body>@Each;@Partial['greeting'], @Partial['name'];@EndEach</body></html>";
  34. var fakeViewEngineHost = new FakeViewEngineHost();
  35. fakeViewEngineHost.GetTemplateCallback = (s, m) =>
  36. {
  37. return (s.Equals("greeting")) ? "Hi" : "Nancy";
  38. };
  39. var model = new List<string>() { "foo", "bar" };
  40. var result = viewEngine.Render(input, model, fakeViewEngineHost);
  41. Assert.Equal(@"<html><head></head><body>Hi, NancyHi, Nancy</body></html>", result);
  42. }
  43. [Fact]
  44. public void Should_expand_partial_inside_each_section_with_current_as_model()
  45. {
  46. const string input = @"<html><head></head><body>@Each;@Partial['testing', @Current];@EndEach</body></html>";
  47. var fakeViewEngineHost = new FakeViewEngineHost();
  48. fakeViewEngineHost.GetTemplateCallback = (s, m) => "Hi @Model ";
  49. var model = new List<string>() { "foo", "bar" };
  50. var result = viewEngine.Render(input, model, fakeViewEngineHost);
  51. Assert.Equal(@"<html><head></head><body>Hi foo Hi bar </body></html>", result);
  52. }
  53. [Fact]
  54. public void Should_expand_partial_inside_each_section_with_parameter_of_current_as_model()
  55. {
  56. const string input = @"<html><head></head><body>@Each;@Partial['testing', @Current.Name];@EndEach</body></html>";
  57. var fakeViewEngineHost = new FakeViewEngineHost();
  58. fakeViewEngineHost.GetTemplateCallback = (s, m) => "Hi @Model ";
  59. dynamic foo = new ExpandoObject();
  60. foo.Name = "foo";
  61. dynamic bar = new ExpandoObject();
  62. bar.Name = "bar";
  63. var model = new List<ExpandoObject>() { foo, bar };
  64. var result = viewEngine.Render(input, model, fakeViewEngineHost);
  65. Assert.Equal(@"<html><head></head><body>Hi foo Hi bar </body></html>", result);
  66. }
  67. [Fact]
  68. public void Should_expand_partial_inside_each_section_with_property_parameter_of_current_as_model()
  69. {
  70. const string input = @"<html><head></head><body>@Each;@Partial['testing', @Current.FirstName];@EndEach</body></html>";
  71. var fakeViewEngineHost = new FakeViewEngineHost();
  72. fakeViewEngineHost.GetTemplateCallback = (s, m) => "Hi @Model ";
  73. var clark = new PersonWithAgeField()
  74. {
  75. FirstName = "Clark",
  76. };
  77. var lois = new PersonWithAgeField()
  78. {
  79. FirstName = "Lois",
  80. };
  81. var model = new List<PersonWithAgeField>() { clark, lois };
  82. var result = viewEngine.Render(input, model, fakeViewEngineHost);
  83. Assert.Equal(@"<html><head></head><body>Hi Clark Hi Lois </body></html>", result);
  84. }
  85. [Fact]
  86. public void Should_expand_partial_inside_each_section_with_field_parameter_of_current_as_model()
  87. {
  88. const string input = @"<html><head></head><body>@Each;@Partial['testing', @Current.Age];@EndEach</body></html>";
  89. var fakeViewEngineHost = new FakeViewEngineHost();
  90. fakeViewEngineHost.GetTemplateCallback = (s, m) => "Hi @Model ";
  91. var clark = new PersonWithAgeField()
  92. {
  93. Age = 28,
  94. };
  95. var lois = new PersonWithAgeField()
  96. {
  97. Age = 37,
  98. };
  99. var model = new List<Person>() { clark, lois };
  100. var result = viewEngine.Render(input, model, fakeViewEngineHost);
  101. Assert.Equal(@"<html><head></head><body>Hi 28 Hi 37 </body></html>", result);
  102. }
  103. [Fact]
  104. public void Should_expand_multiple_partial_inside_each_section_with_parameter_of_current_as_model()
  105. {
  106. const string input = @"<html><head></head><body>@Each;@Partial['first', @Current.Name];-@Partial['second', @Current.Name];@EndEach</body></html>";
  107. var fakeViewEngineHost = new FakeViewEngineHost
  108. {
  109. GetTemplateCallback = (s, m) =>
  110. {
  111. return (s.Equals("first")) ?
  112. "Hi @Model" :
  113. "Hello @Model";
  114. }
  115. };
  116. dynamic foo = new ExpandoObject();
  117. foo.Name = "foo";
  118. dynamic bar = new ExpandoObject();
  119. bar.Name = "bar";
  120. var model = new List<ExpandoObject>() { foo, bar };
  121. var result = viewEngine.Render(input, model, fakeViewEngineHost);
  122. Assert.Equal(@"<html><head></head><body>Hi foo-Hello fooHi bar-Hello bar</body></html>", result);
  123. }
  124. [Fact]
  125. public void Should_expand_multiple_partial_inside_each_section_with_different_parameter_of_current_as_model()
  126. {
  127. const string input = @"<html><head></head><body>@Each;@Partial['first', @Current.First];-@Partial['second', @Current.Last];@EndEach</body></html>";
  128. var fakeViewEngineHost = new FakeViewEngineHost
  129. {
  130. GetTemplateCallback = (s, m) =>
  131. {
  132. return (s.Equals("first")) ?
  133. "Hi @Model" :
  134. "Hello @Model";
  135. }
  136. };
  137. dynamic foo = new ExpandoObject();
  138. foo.First = "foo";
  139. foo.Last = "bar";
  140. dynamic bar = new ExpandoObject();
  141. bar.First = "baz";
  142. bar.Last = "bin";
  143. var model = new List<ExpandoObject>() { foo, bar };
  144. var result = viewEngine.Render(input, model, fakeViewEngineHost);
  145. Assert.Equal(@"<html><head></head><body>Hi foo-Hello barHi baz-Hello bin</body></html>", result);
  146. }
  147. [Fact]
  148. public void Should_evaluate_current_conditional_inside_each()
  149. {
  150. // Given
  151. const string input = @"<html><head></head><body><ul>@Each.Users;<li>@Current.Name says:@If.IsGreekCitizen;<b>Yay Greece!</b>@EndIf;@IfNot.IsGreekCitizen;<b>Boo Greece!</b>@EndIf;</li>@EndEach;</ul></body></html>";
  152. dynamic model = new ExpandoObject();
  153. model.Users = new List<object>() { new { Name = "Bob", IsGreekCitizen = true }, new { Name = "Malin", IsGreekCitizen = false } };
  154. // When
  155. var output = viewEngine.Render(input, model, this.fakeHost);
  156. // Then
  157. Assert.Equal(@"<html><head></head><body><ul><li>Bob says:<b>Yay Greece!</b></li><li>Malin says:<b>Boo Greece!</b></li></ul></body></html>", output);
  158. }
  159. [Fact]
  160. public void Should_not_evaluate_current_conditional_from_outside_each()
  161. {
  162. // Given
  163. const string input = @"<html><head></head><body>@If.HasUsers;Yay Users!@EndIf<ul>@Each.Users;<li>@Current.Name:@If.IsGreekCitizen;<b>Yay Greece!</b>@EndIf;</li>@EndEach;</ul>@IfNot.HasUsers;Yay Users!@EndIf</body></html>";
  164. dynamic model = new ExpandoObject();
  165. model.Users = new List<object>() { new { Name = "Bob", IsGreekCitizen = true }, new { Name = "Malin", IsGreekCitizen = false } };
  166. // When
  167. var output = viewEngine.Render(input, model, this.fakeHost);
  168. // Then
  169. Assert.Equal(@"<html><head></head><body>Yay Users!<ul><li>Bob:<b>Yay Greece!</b></li><li>Malin:</li></ul></body></html>", output);
  170. }
  171. [Fact]
  172. public void Should_evaluate_viewbag_as_dynamic_dictionary_conditional()
  173. {
  174. const string input = @"@Context.ViewBag.HaveMessage;! @If.Context.ViewBag.HaveMessage;Yay message!@EndIf;";
  175. var context = new { ViewBag = (dynamic)new DynamicDictionary() };
  176. context.ViewBag.HaveMessage = true;
  177. ((FakeViewEngineHost)this.fakeHost).Context = context;
  178. var output = viewEngine.Render(input, null, this.fakeHost);
  179. Assert.Equal(@"True! Yay message!", output);
  180. }
  181. [Fact]
  182. public void Should_not_throw_when_viewbag_property_is_null()
  183. {
  184. const string input = @"<html><head></head><body>Hey@If.Context.ViewBag.HaveMessage;Yay message!@EndIf;</body></html>";
  185. var context = new { ViewBag = (dynamic)new DynamicDictionary() };
  186. ((FakeViewEngineHost)this.fakeHost).Context = context;
  187. var output = viewEngine.Render(input, null, this.fakeHost);
  188. Assert.Equal(@"<html><head></head><body>Hey</body></html>", output);
  189. }
  190. [Fact]
  191. public void Should_replace_primitive_model_with_value()
  192. {
  193. // Given
  194. const string input = @"<html><head></head><body>Hello there @Model</body></html>";
  195. const string model = "Bob";
  196. // When
  197. var output = viewEngine.Render(input, model, this.fakeHost);
  198. // Then
  199. Assert.Equal(@"<html><head></head><body>Hello there Bob</body></html>", output);
  200. }
  201. [Fact]
  202. public void Should_replace_primitive_model_with_value_when_followed_by_closing_tag()
  203. {
  204. // Given
  205. const string input = @"<html><head></head><body>Hello there @Model;</body></html>";
  206. const string model = "Bob";
  207. // When
  208. var output = viewEngine.Render(input, model, this.fakeHost);
  209. // Then
  210. Assert.Equal(@"<html><head></head><body>Hello there Bob</body></html>", output);
  211. }
  212. [Fact]
  213. public void Should_replaces_valid_property_when_followed_by_closing_tag()
  214. {
  215. const string input = @"<html><head></head><body>Hello there @Model.Name;</body></html>";
  216. dynamic model = new ExpandoObject();
  217. model.Name = "Bob";
  218. var output = viewEngine.Render(input, model, this.fakeHost);
  219. Assert.Equal(@"<html><head></head><body>Hello there Bob</body></html>", output);
  220. }
  221. [Fact]
  222. public void Should_replace_multiple_properties_with_the_same_name()
  223. {
  224. const string input = @"<html><head></head><body>Hello there @Model.Name;, nice to see you @Model.Name;</body></html>";
  225. dynamic model = new ExpandoObject();
  226. model.Name = "Bob";
  227. var output = viewEngine.Render(input, model, this.fakeHost);
  228. Assert.Equal(@"<html><head></head><body>Hello there Bob, nice to see you Bob</body></html>", output);
  229. }
  230. [Fact]
  231. public void Should_replace_invalid_properties_with_error_string()
  232. {
  233. const string input = @"<html><head></head><body>Hello there @Model.Wrong;</body></html>";
  234. dynamic model = new ExpandoObject();
  235. model.Name = "Bob";
  236. var output = viewEngine.Render(input, model, this.fakeHost);
  237. Assert.Equal(@"<html><head></head><body>Hello there [ERR!]</body></html>", output);
  238. }
  239. [Fact]
  240. public void Should_not_replace_properties_if_case_is_incorrect()
  241. {
  242. const string input = @"<html><head></head><body>Hello there @Model.name;</body></html>";
  243. dynamic model = new ExpandoObject();
  244. model.Name = "Bob";
  245. var output = viewEngine.Render(input, model, this.fakeHost);
  246. Assert.Equal(@"<html><head></head><body>Hello there [ERR!]</body></html>", output);
  247. }
  248. [Fact]
  249. public void Should_replace_multiple_properties_from_dictionary()
  250. {
  251. const string input = @"<html><head></head><body>Hello there @Model.Name; - welcome to @Model.SiteName;</body></html>";
  252. dynamic model = new ExpandoObject();
  253. model.Name = "Bob";
  254. model.SiteName = "Cool Site!";
  255. var output = viewEngine.Render(input, model, this.fakeHost);
  256. Assert.Equal(@"<html><head></head><body>Hello there Bob - welcome to Cool Site!</body></html>", output);
  257. }
  258. [Fact]
  259. public void Should_create_multiple_entries_for_each_statements()
  260. {
  261. const string input = @"<html><head></head><body><ul>@Each.Users;<li>@Current;</li>@EndEach;</ul></body></html>";
  262. dynamic model = new ExpandoObject();
  263. model.Users = new List<string>() { "Bob", "Jim", "Bill" };
  264. var output = viewEngine.Render(input, model, this.fakeHost);
  265. Assert.Equal(@"<html><head></head><body><ul><li>Bob</li><li>Jim</li><li>Bill</li></ul></body></html>", output);
  266. }
  267. [Fact]
  268. public void Should_use_multiple_current_statements_inside_each()
  269. {
  270. const string input = @"<html><head></head><body><ul>@Each.Users;<li id=""@Current;"">@Current;</li>@EndEach;</ul></body></html>";
  271. dynamic model = new ExpandoObject();
  272. model.Users = new List<string>() { "Bob", "Jim", "Bill" };
  273. var output = viewEngine.Render(input, model, this.fakeHost);
  274. Assert.Equal(@"<html><head></head><body><ul><li id=""Bob"">Bob</li><li id=""Jim"">Jim</li><li id=""Bill"">Bill</li></ul></body></html>", output);
  275. }
  276. [Fact]
  277. public void Should_try_to_use_non_enumerable_in_each_shows_error()
  278. {
  279. const string input = @"<html><head></head><body><ul>@Each.Users;<li id=""@Current;"">@Current;</li>@EndEach;</ul></body></html>";
  280. dynamic model = new ExpandoObject();
  281. model.Users = new object();
  282. var output = viewEngine.Render(input, model, this.fakeHost);
  283. Assert.Equal(@"<html><head></head><body><ul>[ERR!]</ul></body></html>", output);
  284. }
  285. [Fact]
  286. public void Should_combine_single_substitutions_and_each_substitutions()
  287. {
  288. const string input = @"<html><head></head><body><ul>@Each.Users;<li>Hello @Current;, @Model.Name; says hello!</li>@EndEach;</ul></body></html>";
  289. dynamic model = new ExpandoObject();
  290. model.Name = "Nancy";
  291. model.Users = new List<string>() { "Bob", "Jim", "Bill" };
  292. var output = viewEngine.Render(input, model, this.fakeHost);
  293. Assert.Equal(@"<html><head></head><body><ul><li>Hello Bob, Nancy says hello!</li><li>Hello Jim, Nancy says hello!</li><li>Hello Bill, Nancy says hello!</li></ul></body></html>", output);
  294. }
  295. [Fact]
  296. public void Should_allow_model_statement_to_be_followed_by_a_newline()
  297. {
  298. const string input = "<html><head></head><body>Hello there @Model.Name;\n</body></html>";
  299. dynamic model = new ExpandoObject();
  300. model.Name = "Bob";
  301. var output = viewEngine.Render(input, model, this.fakeHost);
  302. Assert.Equal("<html><head></head><body>Hello there Bob\n</body></html>", output);
  303. }
  304. [Fact]
  305. public void Should_allow_each_statements_to_work_over_multiple_lines()
  306. {
  307. const string input = "<html>\n\t<head>\n\t</head>\n\t<body>\n\t\t<ul>@Each.Users;\n\t\t\t<li>@Current;</li>@EndEach;\n\t\t</ul>\n\t</body>\n</html>";
  308. dynamic model = new ExpandoObject();
  309. model.Users = new List<string>() { "Bob", "Jim", "Bill" };
  310. var output = viewEngine.Render(input, model, this.fakeHost);
  311. Assert.Equal("<html>\n\t<head>\n\t</head>\n\t<body>\n\t\t<ul>\n\t\t\t<li>Bob</li>\n\t\t\t<li>Jim</li>\n\t\t\t<li>Bill</li>\n\t\t</ul>\n\t</body>\n</html>", output);
  312. }
  313. [Fact]
  314. public void Single_substitutions_work_with_standard_anonymous_type_objects()
  315. {
  316. const string input = @"<html><head></head><body>Hello there @Model.Name; - welcome to @Model.SiteName;</body></html>";
  317. var model = new { Name = "Bob", SiteName = "Cool Site!" };
  318. var output = viewEngine.Render(input, model, this.fakeHost);
  319. Assert.Equal(@"<html><head></head><body>Hello there Bob - welcome to Cool Site!</body></html>", output);
  320. }
  321. [Fact]
  322. public void Should_allow_each_substitutions_to_work_with_standard_anonymous_type_objects()
  323. {
  324. const string input = @"<html><head></head><body><ul>@Each.Users;<li id=""@Current;"">@Current;</li>@EndEach;</ul></body></html>";
  325. var model = new { Users = new List<string>() { "Bob", "Jim", "Bill" } };
  326. var output = viewEngine.Render(input, model, this.fakeHost);
  327. Assert.Equal(@"<html><head></head><body><ul><li id=""Bob"">Bob</li><li id=""Jim"">Jim</li><li id=""Bill"">Bill</li></ul></body></html>", output);
  328. }
  329. [Fact]
  330. public void Should_allow_substitutions_to_work_with_standard_objects()
  331. {
  332. const string input = @"<html><head></head><body><ul>@Each.Users;<li>Hello @Current;, @Model.Name; says hello!</li>@EndEach;</ul></body></html>";
  333. var model = new FakeModel("Nancy", new List<string>() { "Bob", "Jim", "Bill" });
  334. var output = viewEngine.Render(input, model, this.fakeHost);
  335. Assert.Equal(@"<html><head></head><body><ul><li>Hello Bob, Nancy says hello!</li><li>Hello Jim, Nancy says hello!</li><li>Hello Bill, Nancy says hello!</li></ul></body></html>", output);
  336. }
  337. [Fact]
  338. public void Should_render_block_when_if_statement_returns_true()
  339. {
  340. const string input = @"<html><head></head><body>@If.HasUsers;<ul>@Each.Users;<li>Hello @Current;, @Model.Name; says hello!</li>@EndEach;</ul>@EndIf;</body></html>";
  341. var model = new FakeModel("Nancy", new List<string>() { "Bob", "Jim", "Bill" });
  342. var output = viewEngine.Render(input, model, this.fakeHost);
  343. Assert.Equal(@"<html><head></head><body><ul><li>Hello Bob, Nancy says hello!</li><li>Hello Jim, Nancy says hello!</li><li>Hello Bill, Nancy says hello!</li></ul></body></html>", output);
  344. }
  345. [Fact]
  346. public void Should_not_render_block_when_if_statement_returns_false()
  347. {
  348. const string input = @"<html><head></head><body>@If.HasUsers;<ul>@Each.Users;<li>Hello @Current;, @Model.Name; says hello!</li>@EndEach;</ul>@EndIf;</body></html>";
  349. var model = new FakeModel("Nancy", new List<string>());
  350. var output = viewEngine.Render(input, model, this.fakeHost);
  351. Assert.Equal(@"<html><head></head><body></body></html>", output);
  352. }
  353. [Fact]
  354. public void Should_not_render_block_when_ifnot_statements_returns_true()
  355. {
  356. const string input = @"<html><head></head><body>@IfNot.HasUsers;<p>No users found!</p>@EndIf;<ul>@Each.Users;<li>Hello @Current;, @Model.Name; says hello!</li>@EndEach;</ul></body></html>";
  357. var model = new FakeModel("Nancy", new List<string>() { "Bob", "Jim", "Bill" });
  358. var output = viewEngine.Render(input, model, this.fakeHost);
  359. Assert.Equal(@"<html><head></head><body><ul><li>Hello Bob, Nancy says hello!</li><li>Hello Jim, Nancy says hello!</li><li>Hello Bill, Nancy says hello!</li></ul></body></html>", output);
  360. }
  361. [Fact]
  362. public void Should_render_block_when_ifnot_statement_returns_false()
  363. {
  364. const string input = @"<html><head></head><body>@IfNot.HasUsers;<p>No users found!</p>@EndIf;<ul>@Each.Users;<li>Hello @Current;, @Model.Name; says hello!</li>@EndEach;</ul></body></html>";
  365. var model = new FakeModel("Nancy", new List<string>());
  366. var output = viewEngine.Render(input, model, this.fakeHost);
  367. Assert.Equal(@"<html><head></head><body><p>No users found!</p><ul></ul></body></html>", output);
  368. }
  369. [Fact]
  370. public void Should_not_conflict_when_if_and_ifNot_statements_combined_but_not_nested()
  371. {
  372. const string input = @"<html><head></head><body>@IfNot.HasUsers;<p>No users found!</p>@EndIf;@If.HasUsers;<ul>@Each.Users;<li>Hello @Current;, @Model.Name; says hello!</li>@EndEach;</ul>@EndIf;</body></html>";
  373. var model = new FakeModel("Nancy", new List<string>());
  374. var output = viewEngine.Render(input, model, this.fakeHost);
  375. Assert.Equal(@"<html><head></head><body><p>No users found!</p></body></html>", output);
  376. }
  377. [Fact]
  378. public void Should_match_multiple_if_statements_correctly()
  379. {
  380. const string input = "@If.One;<p>One</p>@EndIf; @If.Two;<p>Two</p>@EndIf;";
  381. var model = new { One = true, Two = true };
  382. var output = viewEngine.Render(input, model, this.fakeHost);
  383. Assert.Equal(@"<p>One</p> <p>Two</p>", output);
  384. }
  385. [Fact]
  386. public void Should_match_correctly_when_multiple_each_statements()
  387. {
  388. const string input = "@Each.Users;<li>@Current;</li>@EndEach; @Each.Admins;<li>@Current;</li>@EndEach;";
  389. var model = new { Users = new List<string> { "1", "2" }, Admins = new List<string> { "3", "4" } };
  390. var output = viewEngine.Render(input, model, this.fakeHost);
  391. Assert.Equal(@"<li>1</li><li>2</li> <li>3</li><li>4</li>", output);
  392. }
  393. [Fact]
  394. public void Should_return_true_for_ifhascollection_when_if_model_has_a_collection_with_items_but_no_bool()
  395. {
  396. const string input = @"<html><head></head><body>@If.HasUsers;<ul>@Each.Users;<li>Hello @Current;, @Model.Name; says hello!</li>@EndEach;</ul>@EndIf;</body></html>";
  397. var model = new { Users = new List<string>() { "Bob", "Jim", "Bill" }, Name = "Nancy" };
  398. var output = viewEngine.Render(input, model, this.fakeHost);
  399. Assert.Equal(@"<html><head></head><body><ul><li>Hello Bob, Nancy says hello!</li><li>Hello Jim, Nancy says hello!</li><li>Hello Bill, Nancy says hello!</li></ul></body></html>", output);
  400. }
  401. [Fact]
  402. public void Should_return_false_for_ifnot_hascollection_when_model_has_a_collection_with_items_but_no_bool()
  403. {
  404. const string input = @"<html><head></head><body>@IfNot.HasUsers;<p>No Users!</p>@EndIf;</body></html>";
  405. var model = new { Users = new List<string>() { "Bob", "Jim", "Bill" } };
  406. var output = viewEngine.Render(input, model, this.fakeHost);
  407. Assert.Equal(@"<html><head></head><body></body></html>", output);
  408. }
  409. [Fact]
  410. public void Should_ignore_item_for_implicit_has_support_when_item_isnt_a_collection()
  411. {
  412. const string input = @"<html><head></head><body>@If.HasUsers;<p>Users!</p>@EndIf;</body></html>";
  413. var model = new { Users = new object() };
  414. var output = viewEngine.Render(input, model, this.fakeHost);
  415. Assert.Equal(@"<html><head></head><body></body></html>", output);
  416. }
  417. [Fact]
  418. public void Should_give_precedence_to_hasitem_bool_when_model_has_bool_and_collection()
  419. {
  420. const string input = @"<html><head></head><body>@If.HasUsers;<ul>@Each.Users;<li>Hello @Current;, @Model.Name; says hello!</li>@EndEach;</ul>@EndIf;</body></html>";
  421. var model = new { HasUsers = false, Users = new List<string>() { "Bob", "Jim", "Bill" }, Name = "Nancy" };
  422. var output = viewEngine.Render(input, model, this.fakeHost);
  423. Assert.Equal(@"<html><head></head><body></body></html>", output);
  424. }
  425. [Fact]
  426. public void Should_allow_property_name_in_current_inside_each_loop_for_dynamic_model_and_dynamic_collection()
  427. {
  428. const string input = @"<html><head></head><body><ul>@Each.Users;<li>@Current.Name;</li>@EndEach;</ul></body></html>";
  429. dynamic model = new ExpandoObject();
  430. dynamic user1 = new ExpandoObject();
  431. user1.Name = "Bob";
  432. dynamic user2 = new ExpandoObject();
  433. user2.Name = "Jim";
  434. dynamic user3 = new ExpandoObject();
  435. user3.Name = "Bill";
  436. model.Users = new List<object>() { user1, user2, user3 };
  437. var output = viewEngine.Render(input, model, this.fakeHost);
  438. Assert.Equal(@"<html><head></head><body><ul><li>Bob</li><li>Jim</li><li>Bill</li></ul></body></html>", output);
  439. }
  440. [Fact]
  441. public void Should_allow_property_name_in_current_inside_each_loop_for_dynamic_model_and_normal_collection()
  442. {
  443. const string input = @"<html><head></head><body><ul>@Each.Users;<li>@Current.Name;</li>@EndEach;</ul></body></html>";
  444. dynamic model = new ExpandoObject();
  445. model.Users = new List<User>() { new User("Bob"), new User("Jim"), new User("Bill") };
  446. var output = viewEngine.Render(input, model, this.fakeHost);
  447. Assert.Equal(@"<html><head></head><body><ul><li>Bob</li><li>Jim</li><li>Bill</li></ul></body></html>", output);
  448. }
  449. [Fact]
  450. public void Should_allow_property_name_in_current_inside_each_loop_for_normal_model_and_dynamic_collection()
  451. {
  452. const string input = @"<html><head></head><body><ul>@Each.Users;<li>@Current.Name;</li>@EndEach;</ul></body></html>";
  453. dynamic user1 = new ExpandoObject();
  454. user1.Name = "Bob";
  455. dynamic user2 = new ExpandoObject();
  456. user2.Name = "Jim";
  457. dynamic user3 = new ExpandoObject();
  458. user3.Name = "Bill";
  459. var model = new { Users = new List<object> { user1, user2, user3 } };
  460. var output = viewEngine.Render(input, model, this.fakeHost);
  461. Assert.Equal(@"<html><head></head><body><ul><li>Bob</li><li>Jim</li><li>Bill</li></ul></body></html>", output);
  462. }
  463. [Fact]
  464. public void Should_allow_sub_properties_using_model_statement()
  465. {
  466. const string input = @"<h1>Hello @Model.User.Name;</h1>";
  467. var model = new { User = new User("Bob") };
  468. var output = viewEngine.Render(input, model, this.fakeHost);
  469. Assert.Equal(@"<h1>Hello Bob</h1>", output);
  470. }
  471. [Fact]
  472. public void Should_allow_sub_properties_using_if_statement()
  473. {
  474. const string input = @"<h1>Hello @If.User.IsFriend;Friend!@EndIf;</h1>";
  475. var model = new { User = new User("Bob", true) };
  476. var output = viewEngine.Render(input, model, this.fakeHost);
  477. Assert.Equal(@"<h1>Hello Friend!</h1>", output);
  478. }
  479. [Fact]
  480. public void Should_allow_sub_properties_using_ifnot_statement()
  481. {
  482. const string input = @"<h1>Hello @IfNot.User.IsFriend;Friend!@EndIf;</h1>";
  483. var model = new { User = new User("Bob", true) };
  484. var output = viewEngine.Render(input, model, this.fakeHost);
  485. Assert.Equal(@"<h1>Hello </h1>", output);
  486. }
  487. [Fact]
  488. public void Should_allow_sub_properties_for_each_statement()
  489. {
  490. const string input = @"<html><head></head><body><ul>@Each.Sub.Users;<li>@Current;</li>@EndEach;</ul></body></html>";
  491. var model = new { Sub = new { Users = new List<string>() { "Bob", "Jim", "Bill" } } };
  492. var output = viewEngine.Render(input, model, this.fakeHost);
  493. Assert.Equal(@"<html><head></head><body><ul><li>Bob</li><li>Jim</li><li>Bill</li></ul></body></html>", output);
  494. }
  495. [Fact]
  496. public void Should_allow_sub_properties_for_current_statement_inside_each()
  497. {
  498. const string input = @"<html><head></head><body><ul>@Each.Users;<li>@Current.Item2.Name;</li>@EndEach;</ul></body></html>";
  499. var model = new { Users = new List<Tuple<int, User>>() { new Tuple<int, User>(1, new User("Bob")), new Tuple<int, User>(1, new User("Jim")), new Tuple<int, User>(1, new User("Bill")) } };
  500. var output = viewEngine.Render(input, model, this.fakeHost);
  501. Assert.Equal(@"<html><head></head><body><ul><li>Bob</li><li>Jim</li><li>Bill</li></ul></body></html>", output);
  502. }
  503. [Fact]
  504. public void Should_allow_Model_substitutions_wihout_semi_colon()
  505. {
  506. const string input = @"<html><head></head><body>Hello there @Model.Name</body></html>";
  507. dynamic model = new ExpandoObject();
  508. model.Name = "Bob";
  509. var output = viewEngine.Render(input, model, this.fakeHost);
  510. Assert.Equal(@"<html><head></head><body>Hello there Bob</body></html>", output);
  511. }
  512. [Fact]
  513. public void Should_allow_each_without_semi_colon()
  514. {
  515. const string input = @"<html><head></head><body><ul>@Each.Users<li>@Current;</li>@EndEach;</ul></body></html>";
  516. dynamic model = new ExpandoObject();
  517. model.Users = new List<string>() { "Bob", "Jim", "Bill" };
  518. var output = viewEngine.Render(input, model, this.fakeHost);
  519. Assert.Equal(@"<html><head></head><body><ul><li>Bob</li><li>Jim</li><li>Bill</li></ul></body></html>", output);
  520. }
  521. [Fact]
  522. public void Should_allow_each_and_end_each_without_semi_colon()
  523. {
  524. const string input = @"<html><head></head><body><ul>@Each.Users<li>@Current;</li>@EndEach</ul></body></html>";
  525. dynamic model = new ExpandoObject();
  526. model.Users = new List<string>() { "Bob", "Jim", "Bill" };
  527. var output = viewEngine.Render(input, model, this.fakeHost);
  528. Assert.Equal(@"<html><head></head><body><ul><li>Bob</li><li>Jim</li><li>Bill</li></ul></body></html>", output);
  529. }
  530. [Fact]
  531. public void Should_allow_current_within_each_without_semi_colon()
  532. {
  533. const string input = @"<html><head></head><body><ul>@Each.Users;<li>@Current</li>@EndEach;</ul></body></html>";
  534. dynamic model = new ExpandoObject();
  535. model.Users = new List<string>() { "Bob", "Jim", "Bill" };
  536. var output = viewEngine.Render(input, model, this.fakeHost);
  537. Assert.Equal(@"<html><head></head><body><ul><li>Bob</li><li>Jim</li><li>Bill</li></ul></body></html>", output);
  538. }
  539. [Fact]
  540. public void Should_allow_if_and_endif_without_semi_colon()
  541. {
  542. const string input = @"<html><head></head><body>@If.HasUsers<ul>@Each.Users;<li>Hello @Current;, @Model.Name; says hello!</li>@EndEach;</ul>@EndIf</body></html>";
  543. var model = new FakeModel("Nancy", new List<string>() { "Bob", "Jim", "Bill" });
  544. var output = viewEngine.Render(input, model, this.fakeHost);
  545. Assert.Equal(@"<html><head></head><body><ul><li>Hello Bob, Nancy says hello!</li><li>Hello Jim, Nancy says hello!</li><li>Hello Bill, Nancy says hello!</li></ul></body></html>", output);
  546. }
  547. [Fact]
  548. public void Should_allow_ifnot_and_endif_without_semi_colon()
  549. {
  550. const string input = @"<html><head></head><body>@IfNot.HasUsers<p>No users found!</p>@EndIf<ul>@Each.Users;<li>Hello @Current;, @Model.Name; says hello!</li>@EndEach;</ul></body></html>";
  551. var model = new FakeModel("Nancy", new List<string>() { "Bob", "Jim", "Bill" });
  552. var output = viewEngine.Render(input, model, this.fakeHost);
  553. Assert.Equal(@"<html><head></head><body><ul><li>Hello Bob, Nancy says hello!</li><li>Hello Jim, Nancy says hello!</li><li>Hello Bill, Nancy says hello!</li></ul></body></html>", output);
  554. }
  555. [Fact]
  556. public void Should_allow_each_without_a_variable_and_iterate_over_the_model_if_it_is_enumerable()
  557. {
  558. const string input = @"<html><head></head><body><ul>@Each<li>Hello @Current</li>@EndEach</ul></body></html>";
  559. var model = new List<string>() { "Bob", "Jim", "Bill" };
  560. var output = viewEngine.Render(input, model, this.fakeHost);
  561. Assert.Equal(@"<html><head></head><body><ul><li>Hello Bob</li><li>Hello Jim</li><li>Hello Bill</li></ul></body></html>", output);
  562. }
  563. [Fact]
  564. public void Should_allow_variableless_each_with_semicolon()
  565. {
  566. const string input = @"<html><head></head><body><ul>@Each;<li>Hello @Current</li>@EndEach</ul></body></html>";
  567. var model = new List<string>() { "Bob", "Jim", "Bill" };
  568. var output = viewEngine.Render(input, model, this.fakeHost);
  569. Assert.Equal(@"<html><head></head><body><ul><li>Hello Bob</li><li>Hello Jim</li><li>Hello Bill</li></ul></body></html>", output);
  570. }
  571. [Fact]
  572. public void Model_with_exclaimation_should_html_encode()
  573. {
  574. const string input = @"<html><head></head><body>Hello there @!Model.Name;</body></html>";
  575. dynamic model = new ExpandoObject();
  576. model.Name = "<b>Bob</b>";
  577. var output = viewEngine.Render(input, model, this.fakeHost);
  578. Assert.Equal(@"<html><head></head><body>Hello there &lt;b&gt;Bob&lt;/b&gt;</body></html>", output);
  579. }
  580. [Fact]
  581. public void Current_with_exclaimation_and_no_parameters_should_html_encode()
  582. {
  583. const string input = @"<html><head></head><body><ul>@Each;<li>Hello @!Current</li>@EndEach</ul></body></html>";
  584. var model = new List<string>() { "Bob<br/>", "Jim<br/>", "Bill<br/>" };
  585. var output = viewEngine.Render(input, model, this.fakeHost);
  586. Assert.Equal(@"<html><head></head><body><ul><li>Hello Bob&lt;br/&gt;</li><li>Hello Jim&lt;br/&gt;</li><li>Hello Bill&lt;br/&gt;</li></ul></body></html>", output);
  587. }
  588. [Fact]
  589. public void Current_with_explaimation_and_parameters_should_html_encode()
  590. {
  591. const string input = @"<html><head></head><body><ul>@Each.Users;<li>@!Current.Name;</li>@EndEach;</ul></body></html>";
  592. dynamic model = new ExpandoObject();
  593. dynamic user1 = new ExpandoObject();
  594. user1.Name = "Bob<br/>";
  595. dynamic user2 = new ExpandoObject();
  596. user2.Name = "Jim<br/>";
  597. dynamic user3 = new ExpandoObject();
  598. user3.Name = "Bill<br/>";
  599. model.Users = new List<object>() { user1, user2, user3 };
  600. var output = viewEngine.Render(input, model, this.fakeHost);
  601. Assert.Equal(@"<html><head></head><body><ul><li>Bob&lt;br/&gt;</li><li>Jim&lt;br/&gt;</li><li>Bill&lt;br/&gt;</li></ul></body></html>", output);
  602. }
  603. [Fact]
  604. public void Should_expand_basic_partials()
  605. {
  606. const string input = @"<html><head></head><body>@Partial['testing'];</body></html>";
  607. var fakeViewEngineHost = new FakeViewEngineHost();
  608. fakeViewEngineHost.GetTemplateCallback = (s, m) => "Test partial content";
  609. var result = viewEngine.Render(input, new object(), fakeViewEngineHost);
  610. Assert.Equal(@"<html><head></head><body>Test partial content</body></html>", result);
  611. }
  612. [Fact]
  613. public void Should_expand_partial_content_with_model_if_no_model_specified()
  614. {
  615. const string input = @"<html><head></head><body>@Partial['testing'];</body></html>";
  616. var fakeViewEngineHost = new FakeViewEngineHost();
  617. fakeViewEngineHost.GetTemplateCallback = (s, m) => "Hello @Model.Name";
  618. dynamic model = new ExpandoObject();
  619. model.Name = "Bob";
  620. var result = viewEngine.Render(input, model, fakeViewEngineHost);
  621. Assert.Equal(@"<html><head></head><body>Hello Bob</body></html>", result);
  622. }
  623. [Fact]
  624. public void Should_expand_partial_content_with_specified_model_property_if_specified()
  625. {
  626. const string input = @"<html><head></head><body>@Partial['testing', Model.User];</body></html>";
  627. var fakeViewEngineHost = new FakeViewEngineHost();
  628. fakeViewEngineHost.GetTemplateCallback = (s, m) => "Hello @Model.Name";
  629. dynamic model = new ExpandoObject();
  630. dynamic subModel = new ExpandoObject();
  631. model.Name = "Jim";
  632. subModel.Name = "Bob";
  633. model.User = subModel;
  634. var result = viewEngine.Render(input, model, fakeViewEngineHost);
  635. Assert.Equal(@"<html><head></head><body>Hello Bob</body></html>", result);
  636. }
  637. [Fact]
  638. public void Should_expand_partial_content_even_with_no_model()
  639. {
  640. const string input = @"<html><head></head><body>@Partial['testing'];</body></html>";
  641. var fakeViewEngineHost = new FakeViewEngineHost();
  642. fakeViewEngineHost.GetTemplateCallback = (s, m) => "Test partial content";
  643. var result = this.viewEngine.Render(input, null, fakeViewEngineHost);
  644. Assert.Equal(@"<html><head></head><body>Test partial content</body></html>", result);
  645. }
  646. [Fact]
  647. public void Should_try_to_locate_master_page_if_one_specified()
  648. {
  649. const string input = "@Master['myMaster']\r\n@Section['Header'];\r\nHeader\r\n@EndSection\r\n@Section['Footer']\r\nFooter\r\n@EndSection";
  650. var called = false;
  651. var fakeViewEngineHost = new FakeViewEngineHost();
  652. fakeViewEngineHost.GetTemplateCallback = (s, m) =>
  653. {
  654. called = (s == "myMaster");
  655. return "";
  656. };
  657. this.viewEngine.Render(input, null, fakeViewEngineHost);
  658. Assert.True(called);
  659. }
  660. [Fact]
  661. public void Should_replace_sections_in_master_page()
  662. {
  663. const string input = "@Master['myMaster']\r\n@Section['Header'];\r\nHeader\r\n@EndSection\r\n@Section['Footer']\r\nFooter\r\n@EndSection";
  664. const string master = @"<div id='header'>@Section['Header'];</div><div id='footer'>@Section['Footer'];</div>";
  665. var fakeViewEngineHost = new FakeViewEngineHost();
  666. fakeViewEngineHost.GetTemplateCallback = (s, m) => master;
  667. var result = this.viewEngine.Render(input, null, fakeViewEngineHost);
  668. Assert.Equal("<div id='header'>\r\nHeader\r\n</div><div id='footer'>\r\nFooter\r\n</div>", result);
  669. }
  670. [Fact]
  671. public void Should_also_expand_master_page_with_same_model()
  672. {
  673. const string input = "@Master['myMaster']\r\n@Section['Header'];\r\nHeader\r\n@EndSection\r\n@Section['Footer']\r\nFooter\r\n@EndSection";
  674. const string master = @"Hello @Model.Name!<div id='header'>@Section['Header'];</div><div id='footer'>@Section['Footer'];</div>";
  675. var fakeViewEngineHost = new FakeViewEngineHost();
  676. fakeViewEngineHost.GetTemplateCallback = (s, m) => master;
  677. var result = viewEngine.Render(input, new { Name = "Bob" }, fakeViewEngineHost);
  678. Assert.Equal("Hello Bob!<div id='header'>\r\nHeader\r\n</div><div id='footer'>\r\nFooter\r\n</div>", result);
  679. }
  680. [Fact]
  681. public void Should_handle_master_page_hierarchies()
  682. {
  683. const string input = "@Master['middle']\r\n@Section['MiddleContent']Middle@EndSection";
  684. const string middle = "@Master['top']\r\n@Section['TopContent']Top\r\n@Section['MiddleContent']@EndSection";
  685. const string top = "Top! @Section['TopContent']";
  686. var fakeViewEngineHost = new FakeViewEngineHost();
  687. fakeViewEngineHost.GetTemplateCallback = (s, m) => s == "middle" ? middle : top;
  688. var result = viewEngine.Render(input, null, fakeViewEngineHost);
  689. Assert.Equal("Top! Top\r\nMiddle", result);
  690. }
  691. [Fact]
  692. public void Should_call_to_expand_paths()
  693. {
  694. const string input = @"<script src='@Path['~/scripts/test.js']'></script>";
  695. var fakeViewEngineHost = new FakeViewEngineHost();
  696. fakeViewEngineHost.ExpandPathCallBack = s => s.Replace("~/", "/BasePath/");
  697. var result = viewEngine.Render(input, null, fakeViewEngineHost);
  698. Assert.Equal("<script src='/BasePath/scripts/test.js'></script>", result);
  699. }
  700. [Fact]
  701. public void Should_expand_paths_in_attribute_values()
  702. {
  703. const string input = @"<script src='~/scripts/test.js'></script> <link href=""~/stylesheets/style.css"" />";
  704. var fakeViewEngineHost = new FakeViewEngineHost();
  705. fakeViewEngineHost.ExpandPathCallBack = s => s.Replace("~/", "/BasePath/");
  706. var result = viewEngine.Render(input, null, fakeViewEngineHost);
  707. Assert.Equal(@"<script src='/BasePath/scripts/test.js'></script> <link href=""/BasePath/stylesheets/style.css"" />", result);
  708. }
  709. [Fact]
  710. public void Should_expand_anti_forgery_tokens()
  711. {
  712. const string input = "<html><body><form>@AntiForgeryToken</form><body></html>";
  713. var fakeViewEngineHost = new FakeViewEngineHost();
  714. var result = viewEngine.Render(input, null, fakeViewEngineHost);
  715. Assert.Equal("<html><body><form>CSRF</form><body></html>", result);
  716. }
  717. [Fact]
  718. public void Should_replace_primitive_context_with_value()
  719. {
  720. // Given
  721. const string input = @"<html><head></head><body>Hello there @Context</body></html>";
  722. ((FakeViewEngineHost)this.fakeHost).Context = "Frank";
  723. // When
  724. var output = viewEngine.Render(input, null, this.fakeHost);
  725. // Then
  726. Assert.Equal(@"<html><head></head><body>Hello there Frank</body></html>", output);
  727. }
  728. [Fact]
  729. public void Should_replace_primitive_context_with_value_when_followed_by_closing_tag()
  730. {
  731. // Given
  732. const string input = @"<html><head></head><body>Hello there @Context;</body></html>";
  733. ((FakeViewEngineHost)this.fakeHost).Context = "Frank";
  734. // When
  735. var output = viewEngine.Render(input, null, this.fakeHost);
  736. // Then
  737. Assert.Equal(@"<html><head></head><body>Hello there Frank</body></html>", output);
  738. }
  739. [Fact]
  740. public void Should_replaces_valid_context_property_when_followed_by_closing_tag()
  741. {
  742. const string input = @"<html><head></head><body>Hello there @Context.Name;</body></html>";
  743. dynamic context = new ExpandoObject();
  744. context.Name = "Frank";
  745. ((FakeViewEngineHost)this.fakeHost).Context = context;
  746. var output = viewEngine.Render(input, null, this.fakeHost);
  747. Assert.Equal(@"<html><head></head><body>Hello there Frank</body></html>", output);
  748. }
  749. [Fact]
  750. public void Should_replace_multiple_context_properties_with_the_same_name()
  751. {
  752. const string input = @"<html><head></head><body>Hello there @Context.Name;, nice to see you @Context.Name;</body></html>";
  753. dynamic context = new ExpandoObject();
  754. context.Name = "Frank";
  755. ((FakeViewEngineHost)this.fakeHost).Context = context;
  756. var output = viewEngine.Render(input, null, this.fakeHost);
  757. Assert.Equal(@"<html><head></head><body>Hello there Frank, nice to see you Frank</body></html>", output);
  758. }
  759. [Fact]
  760. public void Should_replace_invalid_context_properties_with_error_string()
  761. {
  762. const string input = @"<html><head></head><body>Hello there @Context.Wrong;</body></html>";
  763. dynamic context = new ExpandoObject();
  764. context.Name = "Frank";
  765. ((FakeViewEngineHost)this.fakeHost).Context = context;
  766. var output = viewEngine.Render(input, null, this.fakeHost);
  767. Assert.Equal(@"<html><head></head><body>Hello there [ERR!]</body></html>", output);
  768. }
  769. [Fact]
  770. public void Should_not_replace_context_properties_if_case_is_incorrect()
  771. {
  772. const string input = @"<html><head></head><body>Hello there @Context.name;</body></html>";
  773. dynamic context = new ExpandoObject();
  774. context.Name = "Franke";
  775. ((FakeViewEngineHost)this.fakeHost).Context = context;
  776. var output = viewEngine.Render(input, null, this.fakeHost);
  777. Assert.Equal(@"<html><head></head><body>Hello there [ERR!]</body></html>", output);
  778. }
  779. [Fact]
  780. public void Should_replace_multiple_context_properties_from_dictionary()
  781. {
  782. const string input = @"<html><head></head><body>Hello there @Context.Name; - welcome to @Context.SiteName;</body></html>";
  783. dynamic context = new ExpandoObject();
  784. context.Name = "Frank";
  785. context.SiteName = "Cool Site!";
  786. ((FakeViewEngineHost)this.fakeHost).Context = context;
  787. var output = viewEngine.Render(input, null, this.fakeHost);
  788. Assert.Equal(@"<html><head></head><body>Hello there Frank - welcome to Cool Site!</body></html>", output);
  789. }
  790. [Fact]
  791. public void Should_allow_context_statement_to_be_followed_by_a_newline()
  792. {
  793. const string input = "<html><head></head><body>Hello there @Context.Name;\n</body></html>";
  794. var output = viewEngine.Render(input, null, this.fakeHost);
  795. Assert.Equal("<html><head></head><body>Hello there Frank\n</body></html>", output);
  796. }
  797. [Fact]
  798. public void Context_substitutions_work_with_standard_anonymous_type_objects()
  799. {
  800. const string input = @"<html><head></head><body>Hello there @Context.Name; - welcome to @Context.SiteName;</body></html>";
  801. var context = new { Name = "Bob", SiteName = "Cool Site!" };
  802. ((FakeViewEngineHost)this.fakeHost).Context = context;
  803. var output = viewEngine.Render(input, null, this.fakeHost);
  804. Assert.Equal(@"<html><head></head><body>Hello there Bob - welcome to Cool Site!</body></html>", output);
  805. }
  806. [Fact]
  807. public void Should_allow_sub_properties_using_context_statement()
  808. {
  809. const string input = @"<h1>Hello @Context.User.Username;</h1>";
  810. var output = viewEngine.Render(input, null, this.fakeHost);
  811. Assert.Equal(@"<h1>Hello Frank123</h1>", output);
  812. }
  813. [Fact]
  814. public void Should_allow_Context_substitutions_wihout_semi_colon()
  815. {
  816. const string input = @"<html><head></head><body>Hello there @Context.Name</body></html>";
  817. var output = viewEngine.Render(input, null, this.fakeHost);
  818. Assert.Equal(@"<html><head></head><body>Hello there Frank</body></html>", output);
  819. }
  820. [Fact]
  821. public void Should_expand_partial_content_with_context()
  822. {
  823. const string input = @"<html><head></head><body>@Partial['testing'];</body></html>";
  824. var fakeViewEngineHost = new FakeViewEngineHost();
  825. fakeViewEngineHost.GetTemplateCallback = (s, m) => "Hello @Context.Name";
  826. var result = viewEngine.Render(input, null, fakeViewEngineHost);
  827. Assert.Equal(@"<html><head></head><body>Hello Frank</body></html>", result);
  828. }
  829. [Fact]
  830. public void Should_also_expand_master_page_with_same_context()
  831. {
  832. const string input = "@Master['myMaster']\r\n@Section['Header'];\r\nHeader\r\n@EndSection\r\n@Section['Footer']\r\nFooter\r\n@EndSection";
  833. const string master = @"Hello @Context.Name!<div id='header'>@Section['Header'];</div><div id='footer'>@Section['Footer'];</div>";
  834. var

Large files files are truncated, but you can click here to view the full file