PageRenderTime 46ms CodeModel.GetById 11ms RepoModel.GetById 0ms app.codeStats 0ms

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

https://bitbucket.org/mdavid/aspnetwebstack
C# | 1115 lines | 877 code | 125 blank | 113 comment | 0 complexity | 298ee9c8ae49ca87cc9b6f0024db8946 MD5 | raw file
  1. using System.Collections;
  2. using System.IO;
  3. using System.Linq;
  4. using System.Web.Hosting;
  5. using System.Web.Routing;
  6. using System.Web.WebPages;
  7. using Moq;
  8. using Xunit;
  9. using Assert = Microsoft.TestCommon.AssertEx;
  10. namespace System.Web.Mvc.Test
  11. {
  12. public class VirtualPathProviderViewEngineTest
  13. {
  14. [Fact]
  15. public void FindView_NullControllerContext_Throws()
  16. {
  17. // Arrange
  18. TestableVirtualPathProviderViewEngine engine = new TestableVirtualPathProviderViewEngine();
  19. // Act & Assert
  20. Assert.ThrowsArgumentNull(
  21. () => engine.FindView(null, "view name", null, false),
  22. "controllerContext"
  23. );
  24. }
  25. [Fact]
  26. public void FindView_NullViewName_Throws()
  27. {
  28. // Arrange
  29. ControllerContext context = CreateContext();
  30. TestableVirtualPathProviderViewEngine engine = new TestableVirtualPathProviderViewEngine();
  31. // Act & Assert
  32. Assert.ThrowsArgumentNullOrEmpty(
  33. () => engine.FindView(context, null, null, false),
  34. "viewName"
  35. );
  36. }
  37. [Fact]
  38. public void FindView_EmptyViewName_Throws()
  39. {
  40. // Arrange
  41. ControllerContext context = CreateContext();
  42. TestableVirtualPathProviderViewEngine engine = new TestableVirtualPathProviderViewEngine();
  43. // Act & Assert
  44. Assert.ThrowsArgumentNullOrEmpty(
  45. () => engine.FindView(context, "", null, false),
  46. "viewName"
  47. );
  48. }
  49. [Fact]
  50. public void FindView_ControllerNameNotInRequestContext_Throws()
  51. {
  52. // Arrange
  53. TestableVirtualPathProviderViewEngine engine = new TestableVirtualPathProviderViewEngine();
  54. ControllerContext context = CreateContext();
  55. context.RouteData.Values.Remove("controller");
  56. // Act & Assert
  57. Assert.Throws<InvalidOperationException>(
  58. () => engine.FindView(context, "viewName", null, false),
  59. "The RouteData must contain an item named 'controller' with a non-empty string value."
  60. );
  61. }
  62. [Fact]
  63. public void FindView_EmptyViewLocations_Throws()
  64. {
  65. // Arrange
  66. ControllerContext context = CreateContext();
  67. TestableVirtualPathProviderViewEngine engine = new TestableVirtualPathProviderViewEngine();
  68. engine.ClearViewLocations();
  69. // Act & Assert
  70. Assert.Throws<InvalidOperationException>(
  71. () => engine.FindView(context, "viewName", null, false),
  72. "The property 'ViewLocationFormats' cannot be null or empty."
  73. );
  74. }
  75. [Fact]
  76. public void FindView_ViewDoesNotExistAndNoMaster_ReturnsSearchedLocationsResult()
  77. {
  78. // Arrange
  79. ControllerContext context = CreateContext();
  80. TestableVirtualPathProviderViewEngine engine = new TestableVirtualPathProviderViewEngine();
  81. engine.MockPathProvider
  82. .Setup(vpp => vpp.FileExists("~/vpath/controllerName/viewName.view"))
  83. .Returns(false)
  84. .Verifiable();
  85. // Act
  86. ViewEngineResult result = engine.FindView(context, "viewName", null, false);
  87. // Assert
  88. Assert.Null(result.View);
  89. Assert.Single(result.SearchedLocations);
  90. Assert.True(result.SearchedLocations.Contains("~/vpath/controllerName/viewName.view"));
  91. engine.MockPathProvider.Verify();
  92. }
  93. [Fact]
  94. public void FindView_VirtualPathViewDoesNotExistAndNoMaster_ReturnsSearchedLocationsResult()
  95. {
  96. // Arrange
  97. ControllerContext context = CreateContext();
  98. TestableVirtualPathProviderViewEngine engine = new TestableVirtualPathProviderViewEngine();
  99. engine.MockPathProvider
  100. .Setup(vpp => vpp.FileExists("~/foo/bar.view"))
  101. .Returns(false)
  102. .Verifiable();
  103. engine.MockCache
  104. .Setup(c => c.InsertViewLocation(It.IsAny<HttpContextBase>(), It.IsAny<string>(), ""))
  105. .Verifiable();
  106. // Act
  107. ViewEngineResult result = engine.FindView(context, "~/foo/bar.view", null, false);
  108. // Assert
  109. Assert.Null(result.View);
  110. Assert.Single(result.SearchedLocations);
  111. Assert.True(result.SearchedLocations.Contains("~/foo/bar.view"));
  112. engine.MockPathProvider.Verify();
  113. engine.MockCache.Verify();
  114. }
  115. [Fact]
  116. public void FindView_VirtualPathViewNotSupportedAndNoMaster_ReturnsSearchedLocationsResult()
  117. {
  118. // Arrange
  119. ControllerContext context = CreateContext();
  120. TestableVirtualPathProviderViewEngine engine = new TestableVirtualPathProviderViewEngine();
  121. engine.MockCache
  122. .Setup(c => c.InsertViewLocation(It.IsAny<HttpContextBase>(), It.IsAny<string>(), ""))
  123. .Verifiable();
  124. // Act
  125. ViewEngineResult result = engine.FindView(context, "~/foo/bar.unsupported", null, false);
  126. // Assert
  127. Assert.Null(result.View);
  128. Assert.Single(result.SearchedLocations);
  129. Assert.True(result.SearchedLocations.Contains("~/foo/bar.unsupported"));
  130. engine.MockPathProvider.Verify(vpp => vpp.FileExists("~/foo/bar.unsupported"), Times.Never());
  131. engine.MockCache.Verify();
  132. }
  133. [Fact]
  134. public void FindView_AbsolutePathViewDoesNotExistAndNoMaster_ReturnsSearchedLocationsResult()
  135. {
  136. // Arrange
  137. ControllerContext context = CreateContext();
  138. TestableVirtualPathProviderViewEngine engine = new TestableVirtualPathProviderViewEngine();
  139. engine.MockPathProvider
  140. .Setup(vpp => vpp.FileExists("/foo/bar.view"))
  141. .Returns(false)
  142. .Verifiable();
  143. engine.MockCache
  144. .Setup(c => c.InsertViewLocation(It.IsAny<HttpContextBase>(), It.IsAny<string>(), ""))
  145. .Verifiable();
  146. // Act
  147. ViewEngineResult result = engine.FindView(context, "/foo/bar.view", null, false);
  148. // Assert
  149. Assert.Null(result.View);
  150. Assert.Single(result.SearchedLocations);
  151. Assert.True(result.SearchedLocations.Contains("/foo/bar.view"));
  152. engine.MockPathProvider.Verify();
  153. engine.MockCache.Verify();
  154. }
  155. [Fact]
  156. public void FindView_AbsolutePathViewNotSupportedAndNoMaster_ReturnsSearchedLocationsResult()
  157. {
  158. // Arrange
  159. ControllerContext context = CreateContext();
  160. TestableVirtualPathProviderViewEngine engine = new TestableVirtualPathProviderViewEngine();
  161. engine.MockCache
  162. .Setup(c => c.InsertViewLocation(It.IsAny<HttpContextBase>(), It.IsAny<string>(), ""))
  163. .Verifiable();
  164. // Act
  165. ViewEngineResult result = engine.FindView(context, "/foo/bar.unsupported", null, false);
  166. // Assert
  167. Assert.Null(result.View);
  168. Assert.Single(result.SearchedLocations);
  169. Assert.True(result.SearchedLocations.Contains("/foo/bar.unsupported"));
  170. engine.MockPathProvider.Verify(vpp => vpp.FileExists("/foo/bar.unsupported"), Times.Never());
  171. engine.MockCache.Verify();
  172. }
  173. [Fact]
  174. public void FindView_ViewExistsAndNoMaster_ReturnsView()
  175. {
  176. // Arrange
  177. ControllerContext context = CreateContext();
  178. TestableVirtualPathProviderViewEngine engine = new TestableVirtualPathProviderViewEngine();
  179. engine.ClearMasterLocations(); // If master is not provided, master locations can be empty
  180. engine.MockPathProvider
  181. .Setup(vpp => vpp.FileExists("~/vpath/controllerName/viewName.view"))
  182. .Returns(true)
  183. .Verifiable();
  184. engine.MockPathProvider
  185. .Setup(vpp => vpp.FileExists("~/vpath/controllerName/viewName.Mobile.view"))
  186. .Returns(false)
  187. .Verifiable();
  188. engine.MockCache
  189. .Setup(c => c.InsertViewLocation(It.IsAny<HttpContextBase>(), It.IsAny<string>(), "~/vpath/controllerName/viewName.view"))
  190. .Verifiable();
  191. // Act
  192. ViewEngineResult result = engine.FindView(context, "viewName", null, false);
  193. // Assert
  194. Assert.Same(engine.CreateViewResult, result.View);
  195. Assert.Null(result.SearchedLocations);
  196. Assert.Same(context, engine.CreateViewControllerContext);
  197. Assert.Equal("~/vpath/controllerName/viewName.view", engine.CreateViewViewPath);
  198. Assert.Equal(String.Empty, engine.CreateViewMasterPath);
  199. engine.MockPathProvider.Verify();
  200. engine.MockCache.Verify();
  201. }
  202. [Fact]
  203. public void FindView_VirtualPathViewExistsAndNoMaster_ReturnsView()
  204. {
  205. // Arrange
  206. ControllerContext context = CreateContext();
  207. TestableVirtualPathProviderViewEngine engine = new TestableVirtualPathProviderViewEngine();
  208. engine.ClearMasterLocations();
  209. engine.MockPathProvider
  210. .Setup(vpp => vpp.FileExists("~/foo/bar.view"))
  211. .Returns(true)
  212. .Verifiable();
  213. engine.MockCache
  214. .Setup(c => c.InsertViewLocation(It.IsAny<HttpContextBase>(), It.IsAny<string>(), "~/foo/bar.view"))
  215. .Verifiable();
  216. // Act
  217. ViewEngineResult result = engine.FindView(context, "~/foo/bar.view", null, false);
  218. // Assert
  219. Assert.Same(engine.CreateViewResult, result.View);
  220. Assert.Null(result.SearchedLocations);
  221. Assert.Same(context, engine.CreateViewControllerContext);
  222. Assert.Equal("~/foo/bar.view", engine.CreateViewViewPath);
  223. Assert.Equal(String.Empty, engine.CreateViewMasterPath);
  224. engine.MockPathProvider.Verify();
  225. engine.MockCache.Verify();
  226. }
  227. [Fact]
  228. public void FindView_VirtualPathViewExistsAndNoMaster_Legacy_ReturnsView()
  229. {
  230. // Arrange
  231. ControllerContext context = CreateContext();
  232. TestableVirtualPathProviderViewEngine engine = new TestableVirtualPathProviderViewEngine()
  233. {
  234. FileExtensions = null, // Set FileExtensions to null to simulate View Engines that do not set this property
  235. };
  236. engine.ClearMasterLocations();
  237. engine.MockPathProvider
  238. .Setup(vpp => vpp.FileExists("~/foo/bar.unsupported"))
  239. .Returns(true)
  240. .Verifiable();
  241. engine.MockCache
  242. .Setup(c => c.InsertViewLocation(It.IsAny<HttpContextBase>(), It.IsAny<string>(), "~/foo/bar.unsupported"))
  243. .Verifiable();
  244. // Act
  245. ViewEngineResult result = engine.FindView(context, "~/foo/bar.unsupported", null, false);
  246. // Assert
  247. Assert.Same(engine.CreateViewResult, result.View);
  248. Assert.Null(result.SearchedLocations);
  249. Assert.Same(context, engine.CreateViewControllerContext);
  250. Assert.Equal("~/foo/bar.unsupported", engine.CreateViewViewPath);
  251. Assert.Equal(String.Empty, engine.CreateViewMasterPath);
  252. engine.MockPathProvider.Verify();
  253. engine.MockCache.Verify();
  254. }
  255. [Fact]
  256. public void FindView_AbsolutePathViewExistsAndNoMaster_ReturnsView()
  257. {
  258. // Arrange
  259. ControllerContext context = CreateContext();
  260. TestableVirtualPathProviderViewEngine engine = new TestableVirtualPathProviderViewEngine();
  261. engine.ClearMasterLocations();
  262. engine.MockPathProvider
  263. .Setup(vpp => vpp.FileExists("/foo/bar.view"))
  264. .Returns(true)
  265. .Verifiable();
  266. engine.MockCache
  267. .Setup(c => c.InsertViewLocation(It.IsAny<HttpContextBase>(), It.IsAny<string>(), "/foo/bar.view"))
  268. .Verifiable();
  269. // Act
  270. ViewEngineResult result = engine.FindView(context, "/foo/bar.view", null, false);
  271. // Assert
  272. Assert.Same(engine.CreateViewResult, result.View);
  273. Assert.Null(result.SearchedLocations);
  274. Assert.Same(context, engine.CreateViewControllerContext);
  275. Assert.Equal("/foo/bar.view", engine.CreateViewViewPath);
  276. Assert.Equal(String.Empty, engine.CreateViewMasterPath);
  277. engine.MockPathProvider.Verify();
  278. engine.MockCache.Verify();
  279. }
  280. [Fact]
  281. public void FindView_AbsolutePathViewExistsAndNoMaster_Legacy_ReturnsView()
  282. {
  283. // Arrange
  284. ControllerContext context = CreateContext();
  285. TestableVirtualPathProviderViewEngine engine = new TestableVirtualPathProviderViewEngine()
  286. {
  287. FileExtensions = null, // Set FileExtensions to null to simulate View Engines that do not set this property
  288. };
  289. engine.ClearMasterLocations();
  290. engine.MockPathProvider
  291. .Setup(vpp => vpp.FileExists("/foo/bar.unsupported"))
  292. .Returns(true)
  293. .Verifiable();
  294. engine.MockCache
  295. .Setup(c => c.InsertViewLocation(It.IsAny<HttpContextBase>(), It.IsAny<string>(), "/foo/bar.unsupported"))
  296. .Verifiable();
  297. // Act
  298. ViewEngineResult result = engine.FindView(context, "/foo/bar.unsupported", null, false);
  299. // Assert
  300. Assert.Same(engine.CreateViewResult, result.View);
  301. Assert.Null(result.SearchedLocations);
  302. Assert.Same(context, engine.CreateViewControllerContext);
  303. Assert.Equal("/foo/bar.unsupported", engine.CreateViewViewPath);
  304. Assert.Equal(String.Empty, engine.CreateViewMasterPath);
  305. engine.MockPathProvider.Verify();
  306. engine.MockCache.Verify();
  307. }
  308. [Fact]
  309. public void FindView_ViewExistsAndMasterNameProvidedButEmptyMasterLocations_Throws()
  310. {
  311. // Arrange
  312. ControllerContext context = CreateContext();
  313. TestableVirtualPathProviderViewEngine engine = new TestableVirtualPathProviderViewEngine();
  314. engine.ClearMasterLocations();
  315. engine.MockPathProvider
  316. .Setup(vpp => vpp.FileExists("~/vpath/controllerName/viewName.view"))
  317. .Returns(true)
  318. .Verifiable();
  319. engine.MockCache
  320. .Setup(c => c.InsertViewLocation(It.IsAny<HttpContextBase>(), It.IsAny<string>(), "~/vpath/controllerName/viewName.view"))
  321. .Verifiable();
  322. engine.MockPathProvider
  323. .Setup(vpp => vpp.FileExists("~/vpath/controllerName/viewName.Mobile.view"))
  324. .Returns(false)
  325. .Verifiable();
  326. // Act & Assert
  327. Assert.Throws<InvalidOperationException>(
  328. () => engine.FindView(context, "viewName", "masterName", false),
  329. "The property 'MasterLocationFormats' cannot be null or empty."
  330. );
  331. engine.MockPathProvider.Verify();
  332. engine.MockCache.Verify();
  333. }
  334. [Fact]
  335. public void FindView_ViewDoesNotExistAndMasterDoesNotExist_ReturnsSearchedLocationsResult()
  336. {
  337. // Arrange
  338. ControllerContext context = CreateContext();
  339. TestableVirtualPathProviderViewEngine engine = new TestableVirtualPathProviderViewEngine();
  340. engine.MockPathProvider
  341. .Setup(vpp => vpp.FileExists("~/vpath/controllerName/viewName.view"))
  342. .Returns(false)
  343. .Verifiable();
  344. engine.MockPathProvider
  345. .Setup(vpp => vpp.FileExists("~/vpath/controllerName/masterName.master"))
  346. .Returns(false)
  347. .Verifiable();
  348. // Act
  349. ViewEngineResult result = engine.FindView(context, "viewName", "masterName", false);
  350. // Assert
  351. Assert.Null(result.View);
  352. Assert.Equal(2, result.SearchedLocations.Count()); // Both view and master locations
  353. Assert.True(result.SearchedLocations.Contains("~/vpath/controllerName/viewName.view"));
  354. Assert.True(result.SearchedLocations.Contains("~/vpath/controllerName/masterName.master"));
  355. engine.MockPathProvider.Verify();
  356. }
  357. [Fact]
  358. public void FindView_ViewExistsButMasterDoesNotExist_ReturnsSearchedLocationsResult()
  359. {
  360. // Arrange
  361. ControllerContext context = CreateContext();
  362. TestableVirtualPathProviderViewEngine engine = new TestableVirtualPathProviderViewEngine();
  363. engine.MockPathProvider
  364. .Setup(vpp => vpp.FileExists("~/vpath/controllerName/viewName.view"))
  365. .Returns(true)
  366. .Verifiable();
  367. engine.MockPathProvider
  368. .Setup(vpp => vpp.FileExists("~/vpath/controllerName/viewName.Mobile.view"))
  369. .Returns(false)
  370. .Verifiable();
  371. engine.MockCache
  372. .Setup(c => c.InsertViewLocation(It.IsAny<HttpContextBase>(), It.IsAny<string>(), "~/vpath/controllerName/viewName.view"))
  373. .Verifiable();
  374. engine.MockPathProvider
  375. .Setup(vpp => vpp.FileExists("~/vpath/controllerName/masterName.master"))
  376. .Returns(false)
  377. .Verifiable();
  378. // Act
  379. ViewEngineResult result = engine.FindView(context, "viewName", "masterName", false);
  380. // Assert
  381. Assert.Null(result.View);
  382. Assert.Single(result.SearchedLocations); // View was found, not included in 'searched locations'
  383. Assert.True(result.SearchedLocations.Contains("~/vpath/controllerName/masterName.master"));
  384. engine.MockPathProvider.Verify();
  385. engine.MockCache.Verify();
  386. }
  387. [Fact]
  388. public void FindView_MasterInAreaDoesNotExist_ReturnsSearchedLocationsResult()
  389. {
  390. // Arrange
  391. ControllerContext context = CreateContext();
  392. context.RouteData.DataTokens["area"] = "areaName";
  393. TestableVirtualPathProviderViewEngine engine = new TestableVirtualPathProviderViewEngine();
  394. engine.MockPathProvider
  395. .Setup(vpp => vpp.FileExists("~/vpath/areaName/controllerName/viewName.view"))
  396. .Returns(true)
  397. .Verifiable();
  398. engine.MockCache
  399. .Setup(c => c.InsertViewLocation(It.IsAny<HttpContextBase>(), It.IsAny<string>(), "~/vpath/areaName/controllerName/viewName.view"))
  400. .Verifiable();
  401. engine.MockPathProvider
  402. .Setup(vpp => vpp.FileExists("~/vpath/areaName/controllerName/viewName.Mobile.view"))
  403. .Returns(false)
  404. .Verifiable();
  405. engine.MockPathProvider
  406. .Setup(vpp => vpp.FileExists("~/vpath/areaName/controllerName/masterName.master"))
  407. .Returns(false)
  408. .Verifiable();
  409. engine.MockPathProvider
  410. .Setup(vpp => vpp.FileExists("~/vpath/controllerName/masterName.master"))
  411. .Returns(false)
  412. .Verifiable();
  413. // Act
  414. ViewEngineResult result = engine.FindView(context, "viewName", "masterName", false);
  415. // Assert
  416. Assert.Null(result.View);
  417. Assert.Equal(2, result.SearchedLocations.Count()); // View was found, not included in 'searched locations'
  418. Assert.True(result.SearchedLocations.Contains("~/vpath/areaName/controllerName/masterName.master"));
  419. Assert.True(result.SearchedLocations.Contains("~/vpath/controllerName/masterName.master"));
  420. engine.MockPathProvider.Verify();
  421. engine.MockCache.Verify();
  422. }
  423. [Fact]
  424. public void FindView_ViewExistsAndMasterExists_ReturnsView()
  425. {
  426. // Arrange
  427. ControllerContext context = CreateContext();
  428. TestableVirtualPathProviderViewEngine engine = new TestableVirtualPathProviderViewEngine();
  429. engine.MockPathProvider
  430. .Setup(vpp => vpp.FileExists("~/vpath/controllerName/viewName.view"))
  431. .Returns(true)
  432. .Verifiable();
  433. engine.MockCache
  434. .Setup(c => c.InsertViewLocation(It.IsAny<HttpContextBase>(), It.IsAny<string>(), "~/vpath/controllerName/viewName.view"))
  435. .Verifiable();
  436. engine.MockPathProvider
  437. .Setup(vpp => vpp.FileExists("~/vpath/controllerName/viewName.Mobile.view"))
  438. .Returns(false)
  439. .Verifiable();
  440. engine.MockPathProvider
  441. .Setup(vpp => vpp.FileExists("~/vpath/controllerName/masterName.master"))
  442. .Returns(true)
  443. .Verifiable();
  444. engine.MockCache
  445. .Setup(c => c.InsertViewLocation(It.IsAny<HttpContextBase>(), It.IsAny<string>(), "~/vpath/controllerName/masterName.master"))
  446. .Verifiable();
  447. engine.MockPathProvider
  448. .Setup(vpp => vpp.FileExists("~/vpath/controllerName/masterName.Mobile.master"))
  449. .Returns(false)
  450. .Verifiable();
  451. // Act
  452. ViewEngineResult result = engine.FindView(context, "viewName", "masterName", false);
  453. // Assert
  454. Assert.Same(engine.CreateViewResult, result.View);
  455. Assert.Null(result.SearchedLocations);
  456. Assert.Same(context, engine.CreateViewControllerContext);
  457. Assert.Equal("~/vpath/controllerName/viewName.view", engine.CreateViewViewPath);
  458. Assert.Equal("~/vpath/controllerName/masterName.master", engine.CreateViewMasterPath);
  459. engine.MockPathProvider.Verify();
  460. engine.MockCache.Verify();
  461. }
  462. [Fact]
  463. public void FindView_ViewInAreaExistsAndMasterExists_ReturnsView()
  464. {
  465. // Arrange
  466. ControllerContext context = CreateContext();
  467. context.RouteData.DataTokens["area"] = "areaName";
  468. TestableVirtualPathProviderViewEngine engine = new TestableVirtualPathProviderViewEngine();
  469. engine.MockPathProvider
  470. .Setup(vpp => vpp.FileExists("~/vpath/areaName/controllerName/viewName.view"))
  471. .Returns(true)
  472. .Verifiable();
  473. engine.MockCache
  474. .Setup(c => c.InsertViewLocation(It.IsAny<HttpContextBase>(), It.IsAny<string>(), "~/vpath/areaName/controllerName/viewName.view"))
  475. .Verifiable();
  476. engine.MockPathProvider
  477. .Setup(vpp => vpp.FileExists("~/vpath/areaName/controllerName/viewName.Mobile.view"))
  478. .Returns(false)
  479. .Verifiable();
  480. engine.MockPathProvider
  481. .Setup(vpp => vpp.FileExists("~/vpath/areaName/controllerName/masterName.master"))
  482. .Returns(false)
  483. .Verifiable();
  484. engine.MockPathProvider
  485. .Setup(vpp => vpp.FileExists("~/vpath/controllerName/masterName.master"))
  486. .Returns(true)
  487. .Verifiable();
  488. engine.MockCache
  489. .Setup(c => c.InsertViewLocation(It.IsAny<HttpContextBase>(), It.IsAny<string>(), "~/vpath/controllerName/masterName.master"))
  490. .Verifiable();
  491. engine.MockPathProvider
  492. .Setup(vpp => vpp.FileExists("~/vpath/controllerName/masterName.Mobile.master"))
  493. .Returns(false)
  494. .Verifiable();
  495. // Act
  496. ViewEngineResult result = engine.FindView(context, "viewName", "masterName", false);
  497. // Assert
  498. Assert.Same(engine.CreateViewResult, result.View);
  499. Assert.Null(result.SearchedLocations);
  500. Assert.Same(context, engine.CreateViewControllerContext);
  501. Assert.Equal("~/vpath/areaName/controllerName/viewName.view", engine.CreateViewViewPath);
  502. Assert.Equal("~/vpath/controllerName/masterName.master", engine.CreateViewMasterPath);
  503. engine.MockPathProvider.Verify();
  504. engine.MockCache.Verify();
  505. }
  506. [Fact]
  507. public void FindView_ViewInAreaExistsAndMasterExists_ReturnsView_Mobile()
  508. {
  509. // Arrange
  510. ControllerContext context = CreateContext(isMobileDevice: true);
  511. context.RouteData.DataTokens["area"] = "areaName";
  512. TestableVirtualPathProviderViewEngine engine = new TestableVirtualPathProviderViewEngine();
  513. engine.MockPathProvider
  514. .Setup(vpp => vpp.FileExists("~/vpath/areaName/controllerName/viewName.view"))
  515. .Returns(true)
  516. .Verifiable();
  517. engine.MockCache
  518. .Setup(c => c.InsertViewLocation(It.IsAny<HttpContextBase>(), It.IsAny<string>(), "~/vpath/areaName/controllerName/viewName.view"))
  519. .Verifiable();
  520. engine.MockPathProvider
  521. .Setup(vpp => vpp.FileExists("~/vpath/areaName/controllerName/viewName.Mobile.view"))
  522. .Returns(true)
  523. .Verifiable();
  524. engine.MockCache
  525. .Setup(c => c.InsertViewLocation(It.IsAny<HttpContextBase>(), It.IsAny<string>(), "~/vpath/areaName/controllerName/viewName.Mobile.view"))
  526. .Verifiable();
  527. engine.MockPathProvider
  528. .Setup(vpp => vpp.FileExists("~/vpath/areaName/controllerName/masterName.master"))
  529. .Returns(false)
  530. .Verifiable();
  531. engine.MockPathProvider
  532. .Setup(vpp => vpp.FileExists("~/vpath/areaName/controllerName/masterName.Mobile.master"))
  533. .Returns(false)
  534. .Verifiable();
  535. engine.MockPathProvider
  536. .Setup(vpp => vpp.FileExists("~/vpath/controllerName/masterName.master"))
  537. .Returns(true)
  538. .Verifiable();
  539. engine.MockCache
  540. .Setup(c => c.InsertViewLocation(It.IsAny<HttpContextBase>(), It.IsAny<string>(), "~/vpath/controllerName/masterName.master"))
  541. .Verifiable();
  542. engine.MockPathProvider
  543. .Setup(vpp => vpp.FileExists("~/vpath/controllerName/masterName.Mobile.master"))
  544. .Returns(true)
  545. .Verifiable();
  546. engine.MockCache
  547. .Setup(c => c.InsertViewLocation(It.IsAny<HttpContextBase>(), It.IsAny<string>(), "~/vpath/controllerName/masterName.Mobile.master"))
  548. .Verifiable();
  549. // Act
  550. ViewEngineResult result = engine.FindView(context, "viewName", "masterName", false);
  551. // Assert
  552. Assert.Same(engine.CreateViewResult, result.View);
  553. Assert.Null(result.SearchedLocations);
  554. Assert.Same(context, engine.CreateViewControllerContext);
  555. Assert.Equal("~/vpath/areaName/controllerName/viewName.Mobile.view", engine.CreateViewViewPath);
  556. Assert.Equal("~/vpath/controllerName/masterName.Mobile.master", engine.CreateViewMasterPath);
  557. engine.MockPathProvider.Verify();
  558. engine.MockCache.Verify();
  559. }
  560. [Fact]
  561. public void FindPartialView_NullControllerContext_Throws()
  562. {
  563. // Arrange
  564. TestableVirtualPathProviderViewEngine engine = new TestableVirtualPathProviderViewEngine();
  565. // Act & Assert
  566. Assert.ThrowsArgumentNull(
  567. () => engine.FindPartialView(null, "view name", false),
  568. "controllerContext"
  569. );
  570. }
  571. [Fact]
  572. public void FindPartialView_NullPartialViewName_Throws()
  573. {
  574. // Arrange
  575. ControllerContext context = CreateContext();
  576. TestableVirtualPathProviderViewEngine engine = new TestableVirtualPathProviderViewEngine();
  577. // Act & Assert
  578. Assert.ThrowsArgumentNullOrEmpty(
  579. () => engine.FindPartialView(context, null, false),
  580. "partialViewName"
  581. );
  582. }
  583. [Fact]
  584. public void FindPartialView_EmptyPartialViewName_Throws()
  585. {
  586. // Arrange
  587. ControllerContext context = CreateContext();
  588. TestableVirtualPathProviderViewEngine engine = new TestableVirtualPathProviderViewEngine();
  589. // Act & Assert
  590. Assert.ThrowsArgumentNullOrEmpty(
  591. () => engine.FindPartialView(context, "", false),
  592. "partialViewName"
  593. );
  594. }
  595. [Fact]
  596. public void FindPartialView_ControllerNameNotInRequestContext_Throws()
  597. {
  598. // Arrange
  599. TestableVirtualPathProviderViewEngine engine = new TestableVirtualPathProviderViewEngine();
  600. ControllerContext context = CreateContext();
  601. context.RouteData.Values.Remove("controller");
  602. // Act & Assert
  603. Assert.Throws<InvalidOperationException>(
  604. () => engine.FindPartialView(context, "partialName", false),
  605. "The RouteData must contain an item named 'controller' with a non-empty string value."
  606. );
  607. }
  608. [Fact]
  609. public void FindPartialView_EmptyPartialViewLocations_Throws()
  610. {
  611. // Arrange
  612. ControllerContext context = CreateContext();
  613. TestableVirtualPathProviderViewEngine engine = new TestableVirtualPathProviderViewEngine();
  614. engine.ClearPartialViewLocations();
  615. // Act & Assert
  616. Assert.Throws<InvalidOperationException>(
  617. () => engine.FindPartialView(context, "partialName", false),
  618. "The property 'PartialViewLocationFormats' cannot be null or empty."
  619. );
  620. }
  621. [Fact]
  622. public void FindPartialView_ViewDoesNotExist_ReturnsSearchLocationsResult()
  623. {
  624. // Arrange
  625. ControllerContext context = CreateContext();
  626. TestableVirtualPathProviderViewEngine engine = new TestableVirtualPathProviderViewEngine();
  627. engine.MockPathProvider
  628. .Setup(vpp => vpp.FileExists("~/vpath/controllerName/partialName.partial"))
  629. .Returns(false)
  630. .Verifiable();
  631. // Act
  632. ViewEngineResult result = engine.FindPartialView(context, "partialName", false);
  633. // Assert
  634. Assert.Null(result.View);
  635. Assert.Single(result.SearchedLocations);
  636. Assert.True(result.SearchedLocations.Contains("~/vpath/controllerName/partialName.partial"));
  637. engine.MockPathProvider.Verify();
  638. }
  639. [Fact]
  640. public void FindPartialView_VirtualPathViewExists_Legacy_ReturnsView()
  641. {
  642. // Arrange
  643. ControllerContext context = CreateContext();
  644. TestableVirtualPathProviderViewEngine engine = new TestableVirtualPathProviderViewEngine()
  645. {
  646. FileExtensions = null, // Set FileExtensions to null to simulate View Engines that do not set this property
  647. };
  648. engine.MockPathProvider
  649. .Setup(vpp => vpp.FileExists("~/foo/bar.unsupported"))
  650. .Returns(true)
  651. .Verifiable();
  652. engine.MockCache
  653. .Setup(c => c.InsertViewLocation(It.IsAny<HttpContextBase>(), It.IsAny<string>(), "~/foo/bar.unsupported"))
  654. .Verifiable();
  655. // Act
  656. ViewEngineResult result = engine.FindPartialView(context, "~/foo/bar.unsupported", false);
  657. // Assert
  658. Assert.Same(engine.CreatePartialViewResult, result.View);
  659. Assert.Null(result.SearchedLocations);
  660. Assert.Same(context, engine.CreatePartialViewControllerContext);
  661. Assert.Equal("~/foo/bar.unsupported", engine.CreatePartialViewPartialPath);
  662. engine.MockPathProvider.Verify();
  663. engine.MockCache.Verify();
  664. }
  665. [Fact]
  666. public void FindPartialView_VirtualPathViewDoesNotExist_ReturnsSearchedLocationsResult()
  667. {
  668. // Arrange
  669. ControllerContext context = CreateContext();
  670. TestableVirtualPathProviderViewEngine engine = new TestableVirtualPathProviderViewEngine();
  671. engine.MockPathProvider
  672. .Setup(vpp => vpp.FileExists("~/foo/bar.partial"))
  673. .Returns(false)
  674. .Verifiable();
  675. engine.MockCache
  676. .Setup(c => c.InsertViewLocation(It.IsAny<HttpContextBase>(), It.IsAny<string>(), ""))
  677. .Verifiable();
  678. // Act
  679. ViewEngineResult result = engine.FindPartialView(context, "~/foo/bar.partial", false);
  680. // Assert
  681. Assert.Null(result.View);
  682. Assert.Single(result.SearchedLocations);
  683. Assert.True(result.SearchedLocations.Contains("~/foo/bar.partial"));
  684. engine.MockPathProvider.Verify();
  685. engine.MockCache.Verify();
  686. }
  687. [Fact]
  688. public void FindPartialView_VirtualPathViewNotSupported_ReturnsSearchedLocationsResult()
  689. {
  690. // Arrange
  691. ControllerContext context = CreateContext();
  692. TestableVirtualPathProviderViewEngine engine = new TestableVirtualPathProviderViewEngine();
  693. engine.MockCache
  694. .Setup(c => c.InsertViewLocation(It.IsAny<HttpContextBase>(), It.IsAny<string>(), ""))
  695. .Verifiable();
  696. // Act
  697. ViewEngineResult result = engine.FindPartialView(context, "~/foo/bar.unsupported", false);
  698. // Assert
  699. Assert.Null(result.View);
  700. Assert.Single(result.SearchedLocations);
  701. Assert.True(result.SearchedLocations.Contains("~/foo/bar.unsupported"));
  702. engine.MockPathProvider.Verify(vpp => vpp.FileExists("~/foo/bar.unsupported"), Times.Never());
  703. engine.MockCache.Verify();
  704. }
  705. [Fact]
  706. public void FindPartialView_AbsolutePathViewDoesNotExist_ReturnsSearchedLocationsResult()
  707. {
  708. // Arrange
  709. ControllerContext context = CreateContext();
  710. TestableVirtualPathProviderViewEngine engine = new TestableVirtualPathProviderViewEngine();
  711. engine.MockPathProvider
  712. .Setup(vpp => vpp.FileExists("/foo/bar.partial"))
  713. .Returns(false)
  714. .Verifiable();
  715. engine.MockCache
  716. .Setup(c => c.InsertViewLocation(It.IsAny<HttpContextBase>(), It.IsAny<string>(), ""))
  717. .Verifiable();
  718. // Act
  719. ViewEngineResult result = engine.FindPartialView(context, "/foo/bar.partial", false);
  720. // Assert
  721. Assert.Null(result.View);
  722. Assert.Single(result.SearchedLocations);
  723. Assert.True(result.SearchedLocations.Contains("/foo/bar.partial"));
  724. engine.MockPathProvider.Verify();
  725. engine.MockCache.Verify();
  726. }
  727. [Fact]
  728. public void FindPartialView_AbsolutePathViewNotSupported_ReturnsSearchedLocationsResult()
  729. {
  730. // Arrange
  731. ControllerContext context = CreateContext();
  732. TestableVirtualPathProviderViewEngine engine = new TestableVirtualPathProviderViewEngine();
  733. engine.MockCache
  734. .Setup(c => c.InsertViewLocation(It.IsAny<HttpContextBase>(), It.IsAny<string>(), ""))
  735. .Verifiable();
  736. // Act
  737. ViewEngineResult result = engine.FindPartialView(context, "/foo/bar.unsupported", false);
  738. // Assert
  739. Assert.Null(result.View);
  740. Assert.Single(result.SearchedLocations);
  741. Assert.True(result.SearchedLocations.Contains("/foo/bar.unsupported"));
  742. engine.MockPathProvider.Verify<bool>(vpp => vpp.FileExists("/foo/bar.unsupported"), Times.Never());
  743. engine.MockCache.Verify();
  744. }
  745. [Fact]
  746. public void FindPartialView_AbsolutePathViewExists_Legacy_ReturnsView()
  747. {
  748. // Arrange
  749. ControllerContext context = CreateContext();
  750. TestableVirtualPathProviderViewEngine engine = new TestableVirtualPathProviderViewEngine()
  751. {
  752. FileExtensions = null, // Set FileExtensions to null to simulate View Engines that do not set this property
  753. };
  754. engine.MockPathProvider
  755. .Setup(vpp => vpp.FileExists("/foo/bar.unsupported"))
  756. .Returns(true)
  757. .Verifiable();
  758. engine.MockCache
  759. .Setup(c => c.InsertViewLocation(It.IsAny<HttpContextBase>(), It.IsAny<string>(), "/foo/bar.unsupported"))
  760. .Verifiable();
  761. // Act
  762. ViewEngineResult result = engine.FindPartialView(context, "/foo/bar.unsupported", false);
  763. // Assert
  764. Assert.Same(engine.CreatePartialViewResult, result.View);
  765. Assert.Null(result.SearchedLocations);
  766. Assert.Same(context, engine.CreatePartialViewControllerContext);
  767. Assert.Equal("/foo/bar.unsupported", engine.CreatePartialViewPartialPath);
  768. engine.MockPathProvider.Verify();
  769. engine.MockCache.Verify();
  770. }
  771. [Fact]
  772. public void FindPartialView_ViewExists_ReturnsView()
  773. {
  774. // Arrange
  775. ControllerContext context = CreateContext();
  776. TestableVirtualPathProviderViewEngine engine = new TestableVirtualPathProviderViewEngine();
  777. engine.MockPathProvider
  778. .Setup(vpp => vpp.FileExists("~/vpath/controllerName/partialName.partial"))
  779. .Returns(true)
  780. .Verifiable();
  781. engine.MockCache
  782. .Setup(c => c.InsertViewLocation(It.IsAny<HttpContextBase>(), It.IsAny<string>(), "~/vpath/controllerName/partialName.partial"))
  783. .Verifiable();
  784. engine.MockPathProvider
  785. .Setup(vpp => vpp.FileExists("~/vpath/controllerName/partialName.Mobile.partial"))
  786. .Returns(false)
  787. .Verifiable();
  788. // Act
  789. ViewEngineResult result = engine.FindPartialView(context, "partialName", false);
  790. // Assert
  791. Assert.Same(engine.CreatePartialViewResult, result.View);
  792. Assert.Null(result.SearchedLocations);
  793. Assert.Same(context, engine.CreatePartialViewControllerContext);
  794. Assert.Equal("~/vpath/controllerName/partialName.partial", engine.CreatePartialViewPartialPath);
  795. engine.MockPathProvider.Verify();
  796. engine.MockCache.Verify();
  797. }
  798. [Fact]
  799. public void FindPartialView_VirtualPathViewExists_ReturnsView()
  800. {
  801. // Arrange
  802. ControllerContext context = CreateContext();
  803. TestableVirtualPathProviderViewEngine engine = new TestableVirtualPathProviderViewEngine();
  804. engine.MockPathProvider
  805. .Setup(vpp => vpp.FileExists("~/foo/bar.partial"))
  806. .Returns(true)
  807. .Verifiable();
  808. engine.MockCache
  809. .Setup(c => c.InsertViewLocation(It.IsAny<HttpContextBase>(), It.IsAny<string>(), "~/foo/bar.partial"))
  810. .Verifiable();
  811. // Act
  812. ViewEngineResult result = engine.FindPartialView(context, "~/foo/bar.partial", false);
  813. // Assert
  814. Assert.Same(engine.CreatePartialViewResult, result.View);
  815. Assert.Null(result.SearchedLocations);
  816. Assert.Same(context, engine.CreatePartialViewControllerContext);
  817. Assert.Equal("~/foo/bar.partial", engine.CreatePartialViewPartialPath);
  818. engine.MockPathProvider.Verify();
  819. engine.MockCache.Verify();
  820. }
  821. [Fact]
  822. public void FindPartialView_AbsolutePathViewExists_ReturnsView()
  823. {
  824. // Arrange
  825. ControllerContext context = CreateContext();
  826. TestableVirtualPathProviderViewEngine engine = new TestableVirtualPathProviderViewEngine();
  827. engine.MockPathProvider
  828. .Setup(vpp => vpp.FileExists("/foo/bar.partial"))
  829. .Returns(true)
  830. .Verifiable();
  831. engine.MockCache
  832. .Setup(c => c.InsertViewLocation(It.IsAny<HttpContextBase>(), It.IsAny<string>(), "/foo/bar.partial"))
  833. .Verifiable();
  834. // Act
  835. ViewEngineResult result = engine.FindPartialView(context, "/foo/bar.partial", false);
  836. // Assert
  837. Assert.Same(engine.CreatePartialViewResult, result.View);
  838. Assert.Null(result.SearchedLocations);
  839. Assert.Same(context, engine.CreatePartialViewControllerContext);
  840. Assert.Equal("/foo/bar.partial", engine.CreatePartialViewPartialPath);
  841. engine.MockPathProvider.Verify();
  842. engine.MockCache.Verify();
  843. }
  844. [Fact]
  845. public void FileExtensions()
  846. {
  847. // Arrange + Assert
  848. Assert.Null(new Mock<VirtualPathProviderViewEngine>().Object.FileExtensions);
  849. }
  850. [Fact]
  851. public void GetExtensionThunk()
  852. {
  853. // Arrange and Assert
  854. Assert.Equal(VirtualPathUtility.GetExtension, new Mock<VirtualPathProviderViewEngine>().Object.GetExtensionThunk);
  855. }
  856. [Fact]
  857. public void DisplayModeSetOncePerRequest()
  858. {
  859. // Arrange
  860. RouteData routeData = new RouteData();
  861. routeData.Values["controller"] = "controllerName";
  862. routeData.Values["action"] = "actionName";
  863. Mock<ControllerContext> mockControllerContext = new Mock<ControllerContext>();
  864. mockControllerContext.Setup(c => c.HttpContext.Request.Browser.IsMobileDevice).Returns(true);
  865. mockControllerContext.Setup(c => c.HttpContext.Request.Cookies).Returns(new HttpCookieCollection());
  866. mockControllerContext.Setup(c => c.HttpContext.Response.Cookies).Returns(new HttpCookieCollection());
  867. mockControllerContext.Setup(c => c.HttpContext.Items).Returns(new Hashtable());
  868. mockControllerContext.Setup(c => c.RouteData).Returns(routeData);
  869. ControllerContext context = mockControllerContext.Object;
  870. TestableVirtualPathProviderViewEngine engine = new TestableVirtualPathProviderViewEngine();
  871. engine.MockPathProvider
  872. .Setup(vpp => vpp.FileExists("~/vpath/controllerName/viewName.view"))
  873. .Returns(true)
  874. .Verifiable();
  875. engine.MockCache
  876. .Setup(c => c.InsertViewLocation(It.IsAny<HttpContextBase>(), It.IsAny<string>(), "~/vpath/controllerName/viewName.view"))
  877. .Verifiable();
  878. engine.MockPathProvider
  879. .Setup(vpp => vpp.FileExists("~/vpath/controllerName/viewName.Mobile.view"))
  880. .Returns(false)
  881. .Verifiable();
  882. engine.MockPathProvider
  883. .Setup(vpp => vpp.FileExists("~/vpath/controllerName/partialName.partial"))
  884. .Returns(false)
  885. .Verifiable();
  886. engine.MockPathProvider
  887. .Setup(vpp => vpp.FileExists("~/vpath/controllerName/partialName.Mobile.partial"))
  888. .Returns(true)
  889. .Verifiable();
  890. engine.MockCache
  891. .Setup(c => c.InsertViewLocation(It.IsAny<HttpContextBase>(), It.IsAny<string>(), "~/vpath/controllerName/partialName.Mobile.partial"))
  892. .Callback<HttpContextBase, string, string>((httpContext, key, virtualPath) =>
  893. {
  894. engine.MockCache
  895. .Setup(c => c.GetViewLocation(It.IsAny<HttpContextBase>(), key))
  896. .Returns("~/vpath/controllerName/partialName.Mobile.partial")
  897. .Verifiable();
  898. })
  899. .Verifiable();
  900. // Act
  901. ViewEngineResult viewResult = engine.FindView(context, "viewName", masterName: null, useCache: false);
  902. // Mobile display mode will be used to locate the view with and without the cache.
  903. // In neither case should this set the DisplayModeId to Mobile because it has already been set.
  904. ViewEngineResult partialResult = engine.FindPartialView(context, "partialName", useCache: false);
  905. ViewEngineResult cachedPartialResult = engine.FindPartialView(context, "partialName", useCache: true);
  906. // Assert
  907. engine.MockPathProvider.Verify();
  908. engine.MockCache.Verify();
  909. Assert.Same(engine.CreateViewResult, viewResult.View);
  910. Assert.Same(engine.CreatePartialViewResult, partialResult.View);
  911. Assert.Same(engine.CreatePartialViewResult, cachedPartialResult.View);
  912. Assert.Equal(DisplayModeProvider.DefaultDisplayModeId, context.DisplayMode.DisplayModeId);
  913. }
  914. // The core caching scenarios are covered in the FindView/FindPartialView tests. These
  915. // extra tests deal with the cache itself, rather than specifics around finding views.
  916. private const string MASTER_VIRTUAL = "~/vpath/controllerName/name.master";
  917. private const string PARTIAL_VIRTUAL = "~/vpath/controllerName/name.partial";
  918. private const string VIEW_VIRTUAL = "~/vpath/controllerName/name.view";
  919. private const string MOBILE_VIEW_VIRTUAL = "~/vpath/controllerName/name.Mobile.view";
  920. [Fact]
  921. public void UsesDifferentKeysForViewMasterAndPartial()
  922. {
  923. string keyMaster = null;
  924. string keyPartial = null;
  925. string keyView = null;
  926. // Arrange
  927. ControllerContext context = CreateContext();
  928. TestableVirtualPathProviderViewEngine engine = new TestableVirtualPathProviderViewEngine();
  929. engine.MockPathProvider
  930. .Setup(vpp => vpp.FileExists(VIEW_VIRTUAL))
  931. .Returns(true)
  932. .Verifiable();
  933. engine.MockPathProvider
  934. .Setup(vpp => vpp.FileExists(MOBILE_VIEW_VIRTUAL))
  935. .Returns(false)
  936. .Verifiable();
  937. engine.MockPathProvider
  938. .Setup(vpp => vpp.FileExists(MASTER_VIRTUAL))
  939. .Returns(true)
  940. .Verifiable();
  941. engine.MockPathProvider
  942. .Setup(vpp => vpp.FileExists("~/vpath/controllerName/name.Mobile.master"))
  943. .Returns(false)
  944. .Verifiable();
  945. engine.MockPathProvider
  946. .Setup(vpp => vpp.FileExists(PARTIAL_VIRTUAL))
  947. .Returns(true)
  948. .Verifiable();
  949. engine.MockPathProvider
  950. .Setup(vpp => vpp.FileExists("~/vpath/controllerName/name.Mobile.partial"))
  951. .Returns(false)
  952. .Verifiable();
  953. engine.MockCache
  954. .Setup(c => c.InsertViewLocation(It.IsAny<HttpContextBase>(), It.IsAny<string>(), VIEW_VIRTUAL))
  955. .Callback<HttpContextBase, string, string>((httpContext, key, path) => keyView = key)
  956. .Verifiable();
  957. engine.MockCache
  958. .Setup(c => c.InsertViewLocation(It.IsAny<HttpContextBase>(), It.IsAny<string>(), MASTER_VIRTUAL))
  959. .Callback<HttpContextBase, string, string>((httpContext, key, path) => keyMaster = key)
  960. .Verifiable();
  961. engine.MockCache
  962. .Setup(c => c.InsertViewLocation(It.IsAny<HttpContextBase>(), It.IsAny<string>(), PARTIAL_VIRTUAL))
  963. .Callback<HttpContextBase, string, string>((httpContext, key, path) => keyPartial = key)
  964. .Verifiable();
  965. // Act
  966. engine.FindView(context, "name", "name", false);
  967. engine.FindPartialView(context, "name", false);
  968. // Assert
  969. Assert.NotNull(keyMaster);
  970. Assert.NotNull(keyPartial);
  971. Assert.NotNull(keyView);
  972. Assert.NotEqual(keyMaster, keyPartial);
  973. Assert.NotEqual(keyMaster, keyView);
  974. Assert.NotEqual(keyPartial, keyView);
  975. engine.MockPathProvider.Verify();
  976. engine.MockCache.Verify();
  977. engine.MockPathProvider
  978. .Verify(vpp => vpp.FileExists(VIEW_VIRTUAL), Times.AtMostOnce());
  979. engine.MockPathProvider
  980. .Verify(vpp => vpp.FileExists(MASTER_VIRTUAL), Times.AtMostOnce());
  981. engine.MockPathProvider
  982. .Verify(vpp => vpp.FileExists(PARTIAL_VIRTUAL), Times.AtMostOnce());
  983. engine.MockCache
  984. .Verify(c => c.InsertViewLocation(It.IsAny<HttpContextBase>(), It.IsAny<string>(), VIEW_VIRTUAL), Times.AtMostOnce());
  985. engine.MockCache
  986. .Verify(c => c.InsertViewLocation(It.IsAny<HttpContextBase>(), It.IsAny<string>(), MASTER_VIRTUAL), Times.AtMostOnce());
  987. engine.MockCache
  988. .Verify(c => c.InsertViewLocation(It.IsAny<HttpContextBase>(), It.IsAny<string>(), PARTIAL_VIRTUAL), Times.AtMostOnce());
  989. }
  990. // This tests the protocol involv