PageRenderTime 27ms CodeModel.GetById 21ms RepoModel.GetById 0ms app.codeStats 0ms

/test/System.Web.Mvc.Test/Test/UrlHelperTest.cs

https://bitbucket.org/mdavid/aspnetwebstack
C# | 694 lines | 448 code | 139 blank | 107 comment | 0 complexity | 8e1036a4888e4837ed38438e046f3c59 MD5 | raw file
  1. using System.Web.Routing;
  2. using Microsoft.Web.UnitTestUtil;
  3. using Moq;
  4. using Xunit;
  5. using Assert = Microsoft.TestCommon.AssertEx;
  6. namespace System.Web.Mvc.Test
  7. {
  8. public class UrlHelperTest
  9. {
  10. [Fact]
  11. public void IsLocalUrl_RejectsNull()
  12. {
  13. UrlHelper helper = GetUrlHelperForIsLocalUrl();
  14. Assert.False(helper.IsLocalUrl(null));
  15. }
  16. [Fact]
  17. public void IsLocalUrl_RejectsEmptyString()
  18. {
  19. UrlHelper helper = GetUrlHelperForIsLocalUrl();
  20. Assert.False(helper.IsLocalUrl(String.Empty));
  21. Assert.False(helper.IsLocalUrl(" "));
  22. }
  23. [Fact]
  24. public void IsLocalUrl_AcceptsRootedUrls()
  25. {
  26. UrlHelper helper = GetUrlHelperForIsLocalUrl();
  27. Assert.True(helper.IsLocalUrl("/fooo"));
  28. Assert.True(helper.IsLocalUrl("/www.hackerz.com"));
  29. Assert.True(helper.IsLocalUrl("/"));
  30. }
  31. [Fact]
  32. public void IsLocalUrl_AcceptsAppRelativeUrls()
  33. {
  34. UrlHelper helper = GetUrlHelperForIsLocalUrl();
  35. Assert.True(helper.IsLocalUrl("~/"));
  36. Assert.True(helper.IsLocalUrl("~/foobar.html"));
  37. }
  38. [Fact]
  39. public void IsLocalUrl_RejectsRelativeUrls()
  40. {
  41. UrlHelper helper = GetUrlHelperForIsLocalUrl();
  42. Assert.False(helper.IsLocalUrl("foobar.html"));
  43. Assert.False(helper.IsLocalUrl("../foobar.html"));
  44. Assert.False(helper.IsLocalUrl("fold/foobar.html"));
  45. }
  46. [Fact]
  47. public void IsLocalUrl_RejectValidButUnsafeRelativeUrls()
  48. {
  49. UrlHelper helper = GetUrlHelperForIsLocalUrl();
  50. Assert.False(helper.IsLocalUrl("http:/foobar.html"));
  51. Assert.False(helper.IsLocalUrl("hTtP:foobar.html"));
  52. Assert.False(helper.IsLocalUrl("http:/www.hackerz.com"));
  53. Assert.False(helper.IsLocalUrl("HtTpS:/www.hackerz.com"));
  54. }
  55. [Fact]
  56. public void IsLocalUrl_RejectsUrlsOnTheSameHost()
  57. {
  58. UrlHelper helper = GetUrlHelperForIsLocalUrl();
  59. Assert.False(helper.IsLocalUrl("http://www.mysite.com/appDir/foobar.html"));
  60. Assert.False(helper.IsLocalUrl("http://WWW.MYSITE.COM"));
  61. }
  62. [Fact]
  63. public void IsLocalUrl_RejectsUrlsOnLocalHost()
  64. {
  65. UrlHelper helper = GetUrlHelperForIsLocalUrl();
  66. Assert.False(helper.IsLocalUrl("http://localhost/foobar.html"));
  67. Assert.False(helper.IsLocalUrl("http://127.0.0.1/foobar.html"));
  68. }
  69. [Fact]
  70. public void IsLocalUrl_RejectsUrlsOnTheSameHostButDifferentScheme()
  71. {
  72. UrlHelper helper = GetUrlHelperForIsLocalUrl();
  73. Assert.False(helper.IsLocalUrl("https://www.mysite.com/"));
  74. }
  75. [Fact]
  76. public void IsLocalUrl_RejectsUrlsOnDifferentHost()
  77. {
  78. UrlHelper helper = GetUrlHelperForIsLocalUrl();
  79. Assert.False(helper.IsLocalUrl("http://www.hackerz.com"));
  80. Assert.False(helper.IsLocalUrl("https://www.hackerz.com"));
  81. Assert.False(helper.IsLocalUrl("hTtP://www.hackerz.com"));
  82. Assert.False(helper.IsLocalUrl("HtTpS://www.hackerz.com"));
  83. }
  84. [Fact]
  85. public void IsLocalUrl_RejectsUrlsWithTooManySchemeSeparatorCharacters()
  86. {
  87. UrlHelper helper = GetUrlHelperForIsLocalUrl();
  88. Assert.False(helper.IsLocalUrl("http://///www.hackerz.com/foobar.html"));
  89. Assert.False(helper.IsLocalUrl("https://///www.hackerz.com/foobar.html"));
  90. Assert.False(helper.IsLocalUrl("HtTpS://///www.hackerz.com/foobar.html"));
  91. Assert.False(helper.IsLocalUrl("http:///www.hackerz.com/foobar.html"));
  92. Assert.False(helper.IsLocalUrl("http:////www.hackerz.com/foobar.html"));
  93. Assert.False(helper.IsLocalUrl("http://///www.hackerz.com/foobar.html"));
  94. }
  95. [Fact]
  96. public void IsLocalUrl_RejectsUrlsWithMissingSchemeName()
  97. {
  98. UrlHelper helper = GetUrlHelperForIsLocalUrl();
  99. Assert.False(helper.IsLocalUrl("//www.hackerz.com"));
  100. Assert.False(helper.IsLocalUrl("//www.hackerz.com/foobar.html"));
  101. Assert.False(helper.IsLocalUrl("///www.hackerz.com"));
  102. Assert.False(helper.IsLocalUrl("//////www.hackerz.com"));
  103. }
  104. [Fact]
  105. public void IsLocalUrl_RejectsInvalidUrls()
  106. {
  107. UrlHelper helper = GetUrlHelperForIsLocalUrl();
  108. Assert.False(helper.IsLocalUrl(@"http:\\www.hackerz.com"));
  109. Assert.False(helper.IsLocalUrl(@"http:\\www.hackerz.com\"));
  110. }
  111. [Fact]
  112. public void RequestContextProperty()
  113. {
  114. // Arrange
  115. RequestContext requestContext = new RequestContext(new Mock<HttpContextBase>().Object, new RouteData());
  116. UrlHelper urlHelper = new UrlHelper(requestContext);
  117. // Assert
  118. Assert.Equal(requestContext, urlHelper.RequestContext);
  119. }
  120. [Fact]
  121. public void ConstructorWithNullRequestContextThrows()
  122. {
  123. // Assert
  124. Assert.ThrowsArgumentNull(
  125. delegate { new UrlHelper(null); },
  126. "requestContext");
  127. }
  128. [Fact]
  129. public void ConstructorWithNullRouteCollectionThrows()
  130. {
  131. // Assert
  132. Assert.ThrowsArgumentNull(
  133. delegate { new UrlHelper(GetRequestContext(), null); },
  134. "routeCollection");
  135. }
  136. [Fact]
  137. public void Action()
  138. {
  139. // Arrange
  140. UrlHelper urlHelper = GetUrlHelper();
  141. // Act
  142. string url = urlHelper.Action("newaction");
  143. // Assert
  144. Assert.Equal(MvcHelper.AppPathModifier + "/app/home/newaction", url);
  145. }
  146. [Fact]
  147. public void ActionWithControllerName()
  148. {
  149. // Arrange
  150. UrlHelper urlHelper = GetUrlHelper();
  151. // Act
  152. string url = urlHelper.Action("newaction", "home2");
  153. // Assert
  154. Assert.Equal(MvcHelper.AppPathModifier + "/app/home2/newaction", url);
  155. }
  156. [Fact]
  157. public void ActionWithControllerNameAndDictionary()
  158. {
  159. // Arrange
  160. UrlHelper urlHelper = GetUrlHelper();
  161. // Act
  162. string url = urlHelper.Action("newaction", "home2", new RouteValueDictionary(new { id = "someid" }));
  163. // Assert
  164. Assert.Equal(MvcHelper.AppPathModifier + "/app/home2/newaction/someid", url);
  165. }
  166. [Fact]
  167. public void ActionWithControllerNameAndObjectProperties()
  168. {
  169. // Arrange
  170. UrlHelper urlHelper = GetUrlHelper();
  171. // Act
  172. string url = urlHelper.Action("newaction", "home2", new { id = "someid" });
  173. // Assert
  174. Assert.Equal(MvcHelper.AppPathModifier + "/app/home2/newaction/someid", url);
  175. }
  176. [Fact]
  177. public void ActionWithDictionary()
  178. {
  179. // Arrange
  180. UrlHelper urlHelper = GetUrlHelper();
  181. // Act
  182. string url = urlHelper.Action("newaction", new RouteValueDictionary(new { Controller = "home2", id = "someid" }));
  183. // Assert
  184. Assert.Equal(MvcHelper.AppPathModifier + "/app/home2/newaction/someid", url);
  185. }
  186. [Fact]
  187. public void ActionWithNullActionName()
  188. {
  189. // Arrange
  190. UrlHelper urlHelper = GetUrlHelper();
  191. // Act
  192. string url = urlHelper.Action(null);
  193. // Assert
  194. Assert.Equal(MvcHelper.AppPathModifier + "/app/home/oldaction", url);
  195. }
  196. [Fact]
  197. public void ActionWithNullProtocol()
  198. {
  199. // Arrange
  200. UrlHelper urlHelper = GetUrlHelper();
  201. // Act
  202. string url = urlHelper.Action("newaction", "home2", new { id = "someid" }, null /* protocol */);
  203. // Assert
  204. Assert.Equal(MvcHelper.AppPathModifier + "/app/home2/newaction/someid", url);
  205. }
  206. [Fact]
  207. public void ActionParameterOverridesObjectProperties()
  208. {
  209. // Arrange
  210. UrlHelper urlHelper = GetUrlHelper();
  211. // Act
  212. string url = urlHelper.Action("newaction", new { Action = "action" });
  213. // Assert
  214. Assert.Equal(MvcHelper.AppPathModifier + "/app/home/newaction", url);
  215. }
  216. [Fact]
  217. public void ActionWithObjectProperties()
  218. {
  219. // Arrange
  220. UrlHelper urlHelper = GetUrlHelper();
  221. // Act
  222. string url = urlHelper.Action("newaction", new { Controller = "home2", id = "someid" });
  223. // Assert
  224. Assert.Equal(MvcHelper.AppPathModifier + "/app/home2/newaction/someid", url);
  225. }
  226. [Fact]
  227. public void ActionWithProtocol()
  228. {
  229. // Arrange
  230. UrlHelper urlHelper = GetUrlHelper();
  231. // Act
  232. string url = urlHelper.Action("newaction", "home2", new { id = "someid" }, "https");
  233. // Assert
  234. Assert.Equal("https://localhost" + MvcHelper.AppPathModifier + "/app/home2/newaction/someid", url);
  235. }
  236. [Fact]
  237. public void ContentWithAbsolutePath()
  238. {
  239. // Arrange
  240. UrlHelper urlHelper = GetUrlHelper();
  241. // Act
  242. string url = urlHelper.Content("/Content/Image.jpg");
  243. // Assert
  244. Assert.Equal("/Content/Image.jpg", url);
  245. }
  246. [Fact]
  247. public void ContentWithAppRelativePath()
  248. {
  249. // Arrange
  250. UrlHelper urlHelper = GetUrlHelper();
  251. // Act
  252. string url = urlHelper.Content("~/Content/Image.jpg");
  253. // Assert
  254. Assert.Equal(MvcHelper.AppPathModifier + "/app/Content/Image.jpg", url);
  255. }
  256. [Fact]
  257. public void ContentWithEmptyPathThrows()
  258. {
  259. // Arrange
  260. UrlHelper urlHelper = GetUrlHelper();
  261. // Act & Assert
  262. Assert.ThrowsArgumentNullOrEmpty(
  263. delegate() { urlHelper.Content(String.Empty); },
  264. "contentPath");
  265. }
  266. [Fact]
  267. public void ContentWithRelativePath()
  268. {
  269. // Arrange
  270. UrlHelper urlHelper = GetUrlHelper();
  271. // Act
  272. string url = urlHelper.Content("Content/Image.jpg");
  273. // Assert
  274. Assert.Equal("Content/Image.jpg", url);
  275. }
  276. [Fact]
  277. public void ContentWithExternalUrl()
  278. {
  279. // Arrange
  280. UrlHelper urlHelper = GetUrlHelper();
  281. // Act
  282. string url = urlHelper.Content("http://www.asp.net/App_Themes/Standard/i/logo.png");
  283. // Assert
  284. Assert.Equal("http://www.asp.net/App_Themes/Standard/i/logo.png", url);
  285. }
  286. [Fact]
  287. public void Encode()
  288. {
  289. // Arrange
  290. UrlHelper urlHelper = GetUrlHelper();
  291. // Act
  292. string encodedUrl = urlHelper.Encode(@"SomeUrl /+\");
  293. // Assert
  294. Assert.Equal(encodedUrl, "SomeUrl+%2f%2b%5c");
  295. }
  296. [Fact]
  297. public void GenerateContentUrlWithNullContentPathThrows()
  298. {
  299. // Act & Assert
  300. Assert.ThrowsArgumentNullOrEmpty(
  301. delegate() { UrlHelper.GenerateContentUrl(null, null); },
  302. "contentPath");
  303. }
  304. [Fact]
  305. public void GenerateContentUrlWithNullContextThrows()
  306. {
  307. // Act & Assert
  308. Assert.ThrowsArgumentNull(
  309. delegate() { UrlHelper.GenerateContentUrl("Content/foo.png", null); },
  310. "httpContext");
  311. }
  312. [Fact]
  313. public void GenerateUrlWithNullRequestContextThrows()
  314. {
  315. // Act & Assert
  316. Assert.ThrowsArgumentNull(
  317. delegate() { UrlHelper.GenerateUrl(null /* routeName */, null /* actionName */, null /* controllerName */, null /* routeValues */, new RouteCollection(), null /* requestContext */, false); },
  318. "requestContext");
  319. }
  320. [Fact]
  321. public void GenerateUrlWithNullRouteCollectionThrows()
  322. {
  323. // Act & Assert
  324. Assert.ThrowsArgumentNull(
  325. delegate() { UrlHelper.GenerateUrl(null /* routeName */, null /* actionName */, null /* controllerName */, null /* routeValues */, null /* routeCollection */, null /* requestContext */, false); },
  326. "routeCollection");
  327. }
  328. [Fact]
  329. public void GenerateUrlWithEmptyCollectionsReturnsNull()
  330. {
  331. // Arrange
  332. RequestContext requestContext = GetRequestContext();
  333. // Act
  334. string url = UrlHelper.GenerateUrl(null, null, null, null, new RouteCollection(), requestContext, true);
  335. // Assert
  336. Assert.Null(url);
  337. }
  338. [Fact]
  339. public void GenerateUrlWithAction()
  340. {
  341. // Arrange
  342. RequestContext requestContext = GetRequestContext(GetRouteData());
  343. // Act
  344. string url = UrlHelper.GenerateUrl(null, "newaction", null, null, GetRouteCollection(), requestContext, true);
  345. // Assert
  346. Assert.Equal(MvcHelper.AppPathModifier + "/app/home/newaction", url);
  347. }
  348. [Fact]
  349. public void GenerateUrlWithActionAndController()
  350. {
  351. // Arrange
  352. RequestContext requestContext = GetRequestContext(GetRouteData());
  353. // Act
  354. string url = UrlHelper.GenerateUrl(null, "newaction", "newcontroller", null, GetRouteCollection(), requestContext, true);
  355. // Assert
  356. Assert.Equal(MvcHelper.AppPathModifier + "/app/newcontroller/newaction", url);
  357. }
  358. [Fact]
  359. public void GenerateUrlWithImplicitValues()
  360. {
  361. // Arrange
  362. RequestContext requestContext = GetRequestContext(GetRouteData());
  363. // Act
  364. string url = UrlHelper.GenerateUrl(null, null, null, null, GetRouteCollection(), requestContext, true);
  365. // Assert
  366. Assert.Equal(MvcHelper.AppPathModifier + "/app/home/oldaction", url);
  367. }
  368. [Fact]
  369. public void RouteUrlCanUseNamedRouteWithoutSpecifyingDefaults()
  370. {
  371. // DevDiv 217072: Non-mvc specific helpers should not give default values for controller and action
  372. // Arrange
  373. UrlHelper urlHelper = GetUrlHelper();
  374. urlHelper.RouteCollection.MapRoute("MyRouteName", "any/url", new { controller = "Charlie" });
  375. // Act
  376. string result = urlHelper.RouteUrl("MyRouteName");
  377. // Assert
  378. Assert.Equal(MvcHelper.AppPathModifier + "/app/any/url", result);
  379. }
  380. [Fact]
  381. public void RouteUrlWithDictionary()
  382. {
  383. // Arrange
  384. UrlHelper urlHelper = GetUrlHelper();
  385. // Act
  386. string url = urlHelper.RouteUrl(new RouteValueDictionary(new { Action = "newaction", Controller = "home2", id = "someid" }));
  387. // Assert
  388. Assert.Equal(MvcHelper.AppPathModifier + "/app/home2/newaction/someid", url);
  389. }
  390. [Fact]
  391. public void RouteUrlWithEmptyHostName()
  392. {
  393. // Arrange
  394. UrlHelper urlHelper = GetUrlHelper();
  395. // Act
  396. string url = urlHelper.RouteUrl("namedroute", new RouteValueDictionary(new { Action = "newaction", Controller = "home2", id = "someid" }), "http", String.Empty /* hostName */);
  397. // Assert
  398. Assert.Equal("http://localhost" + MvcHelper.AppPathModifier + "/app/named/home2/newaction/someid", url);
  399. }
  400. [Fact]
  401. public void RouteUrlWithEmptyProtocol()
  402. {
  403. // Arrange
  404. UrlHelper urlHelper = GetUrlHelper();
  405. // Act
  406. string url = urlHelper.RouteUrl("namedroute", new RouteValueDictionary(new { Action = "newaction", Controller = "home2", id = "someid" }), String.Empty /* protocol */, "foo.bar.com");
  407. // Assert
  408. Assert.Equal("http://foo.bar.com" + MvcHelper.AppPathModifier + "/app/named/home2/newaction/someid", url);
  409. }
  410. [Fact]
  411. public void RouteUrlWithNullProtocol()
  412. {
  413. // Arrange
  414. UrlHelper urlHelper = GetUrlHelper();
  415. // Act
  416. string url = urlHelper.RouteUrl("namedroute", new RouteValueDictionary(new { Action = "newaction", Controller = "home2", id = "someid" }), null /* protocol */, "foo.bar.com");
  417. // Assert
  418. Assert.Equal("http://foo.bar.com" + MvcHelper.AppPathModifier + "/app/named/home2/newaction/someid", url);
  419. }
  420. [Fact]
  421. public void RouteUrlWithNullProtocolAndNullHostName()
  422. {
  423. // Arrange
  424. UrlHelper urlHelper = GetUrlHelper();
  425. // Act
  426. string url = urlHelper.RouteUrl("namedroute", new RouteValueDictionary(new { Action = "newaction", Controller = "home2", id = "someid" }), null /* protocol */, null /* hostName */);
  427. // Assert
  428. Assert.Equal(MvcHelper.AppPathModifier + "/app/named/home2/newaction/someid", url);
  429. }
  430. [Fact]
  431. public void RouteUrlWithObjectProperties()
  432. {
  433. // Arrange
  434. UrlHelper urlHelper = GetUrlHelper();
  435. // Act
  436. string url = urlHelper.RouteUrl(new { Action = "newaction", Controller = "home2", id = "someid" });
  437. // Assert
  438. Assert.Equal(MvcHelper.AppPathModifier + "/app/home2/newaction/someid", url);
  439. }
  440. [Fact]
  441. public void RouteUrlWithProtocol()
  442. {
  443. // Arrange
  444. UrlHelper urlHelper = GetUrlHelper();
  445. // Act
  446. string url = urlHelper.RouteUrl("namedroute", new { Action = "newaction", Controller = "home2", id = "someid" }, "https");
  447. // Assert
  448. Assert.Equal("https://localhost" + MvcHelper.AppPathModifier + "/app/named/home2/newaction/someid", url);
  449. }
  450. [Fact]
  451. public void RouteUrlWithRouteNameAndDefaults()
  452. {
  453. // Arrange
  454. UrlHelper urlHelper = GetUrlHelper();
  455. // Act
  456. string url = urlHelper.RouteUrl("namedroute");
  457. // Assert
  458. Assert.Equal(MvcHelper.AppPathModifier + "/app/named/home/oldaction", url);
  459. }
  460. [Fact]
  461. public void RouteUrlWithRouteNameAndDictionary()
  462. {
  463. // Arrange
  464. UrlHelper urlHelper = GetUrlHelper();
  465. // Act
  466. string url = urlHelper.RouteUrl("namedroute", new RouteValueDictionary(new { Action = "newaction", Controller = "home2", id = "someid" }));
  467. // Assert
  468. Assert.Equal(MvcHelper.AppPathModifier + "/app/named/home2/newaction/someid", url);
  469. }
  470. [Fact]
  471. public void RouteUrlWithRouteNameAndObjectProperties()
  472. {
  473. // Arrange
  474. UrlHelper urlHelper = GetUrlHelper();
  475. // Act
  476. string url = urlHelper.RouteUrl("namedroute", new { Action = "newaction", Controller = "home2", id = "someid" });
  477. // Assert
  478. Assert.Equal(MvcHelper.AppPathModifier + "/app/named/home2/newaction/someid", url);
  479. }
  480. [Fact]
  481. public void UrlGenerationDoesNotChangeProvidedDictionary()
  482. {
  483. // Arrange
  484. UrlHelper urlHelper = GetUrlHelper();
  485. RouteValueDictionary valuesDictionary = new RouteValueDictionary();
  486. // Act
  487. urlHelper.Action("actionName", valuesDictionary);
  488. // Assert
  489. Assert.Empty(valuesDictionary);
  490. Assert.False(valuesDictionary.ContainsKey("action"));
  491. }
  492. [Fact]
  493. public void UrlGenerationReturnsNullWhenSubsequentSegmentHasValue()
  494. { // Dev10 Bug #924729
  495. // Arrange
  496. RouteCollection routes = new RouteCollection();
  497. routes.MapRoute("SampleRoute", "testing/{a}/{b}/{c}",
  498. new
  499. {
  500. controller = "controller",
  501. action = "action",
  502. b = UrlParameter.Optional,
  503. c = UrlParameter.Optional
  504. });
  505. UrlHelper helper = GetUrlHelper(routeCollection: routes);
  506. // Act
  507. string url = helper.Action("action", "controller", new { a = 42, c = 2112 });
  508. // Assert
  509. Assert.Null(url);
  510. }
  511. private static RequestContext GetRequestContext()
  512. {
  513. HttpContextBase httpcontext = MvcHelper.GetHttpContext("/app/", null, null);
  514. RouteData rd = new RouteData();
  515. return new RequestContext(httpcontext, rd);
  516. }
  517. private static RequestContext GetRequestContext(RouteData routeData)
  518. {
  519. HttpContextBase httpcontext = MvcHelper.GetHttpContext("/app/", null, null);
  520. return new RequestContext(httpcontext, routeData);
  521. }
  522. private static RouteCollection GetRouteCollection()
  523. {
  524. RouteCollection rt = new RouteCollection();
  525. rt.Add(new Route("{controller}/{action}/{id}", null) { Defaults = new RouteValueDictionary(new { id = "defaultid" }) });
  526. rt.Add("namedroute", new Route("named/{controller}/{action}/{id}", null) { Defaults = new RouteValueDictionary(new { id = "defaultid" }) });
  527. return rt;
  528. }
  529. private static RouteData GetRouteData()
  530. {
  531. RouteData rd = new RouteData();
  532. rd.Values.Add("controller", "home");
  533. rd.Values.Add("action", "oldaction");
  534. return rd;
  535. }
  536. private static UrlHelper GetUrlHelper()
  537. {
  538. return GetUrlHelper(GetRouteData(), GetRouteCollection());
  539. }
  540. private static UrlHelper GetUrlHelper(RouteData routeData = null, RouteCollection routeCollection = null)
  541. {
  542. HttpContextBase httpcontext = MvcHelper.GetHttpContext("/app/", null, null);
  543. UrlHelper urlHelper = new UrlHelper(new RequestContext(httpcontext, routeData ?? new RouteData()), routeCollection ?? new RouteCollection());
  544. return urlHelper;
  545. }
  546. private static UrlHelper GetUrlHelperForIsLocalUrl()
  547. {
  548. Mock<HttpContextBase> contextMock = new Mock<HttpContextBase>();
  549. contextMock.SetupGet(context => context.Request.Url).Returns(new Uri("http://www.mysite.com/"));
  550. RequestContext requestContext = new RequestContext(contextMock.Object, new RouteData());
  551. UrlHelper helper = new UrlHelper(requestContext);
  552. return helper;
  553. }
  554. }
  555. }