当前位置: 首页>>代码示例>>C#>>正文


C# TestableVirtualPathProviderViewEngine.FindPartialView方法代码示例

本文整理汇总了C#中TestableVirtualPathProviderViewEngine.FindPartialView方法的典型用法代码示例。如果您正苦于以下问题:C# TestableVirtualPathProviderViewEngine.FindPartialView方法的具体用法?C# TestableVirtualPathProviderViewEngine.FindPartialView怎么用?C# TestableVirtualPathProviderViewEngine.FindPartialView使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在TestableVirtualPathProviderViewEngine的用法示例。


在下文中一共展示了TestableVirtualPathProviderViewEngine.FindPartialView方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: FindPartialView_AbsolutePathViewExists_ReturnsView

        public void FindPartialView_AbsolutePathViewExists_ReturnsView()
        {
            // Arrange
            ControllerContext context = CreateContext();
            TestableVirtualPathProviderViewEngine engine = new TestableVirtualPathProviderViewEngine();
            engine.MockPathProvider
                .Setup(vpp => vpp.FileExists("/foo/bar.partial"))
                .Returns(true)
                .Verifiable();
            engine.MockCache
                .Setup(c => c.InsertViewLocation(It.IsAny<HttpContextBase>(), It.IsAny<string>(), "/foo/bar.partial"))
                .Verifiable();

            // Act
            ViewEngineResult result = engine.FindPartialView(context, "/foo/bar.partial", false);

            // Assert
            Assert.Same(engine.CreatePartialViewResult, result.View);
            Assert.Null(result.SearchedLocations);
            Assert.Same(context, engine.CreatePartialViewControllerContext);
            Assert.Equal("/foo/bar.partial", engine.CreatePartialViewPartialPath);
            engine.MockPathProvider.Verify();
            engine.MockCache.Verify();
        }
开发者ID:chrisortman,项目名称:aspnetwebstack,代码行数:24,代码来源:VirtualPathProviderViewEngineTest.cs

示例2: DisplayModeSetOncePerRequest

        public void DisplayModeSetOncePerRequest()
        {
            // Arrange
            RouteData routeData = new RouteData();
            routeData.Values["controller"] = "controllerName";
            routeData.Values["action"] = "actionName";

            Mock<ControllerContext> mockControllerContext = new Mock<ControllerContext>();
            mockControllerContext.Setup(c => c.HttpContext.Request.Browser.IsMobileDevice).Returns(true);
            mockControllerContext.Setup(c => c.HttpContext.Request.Cookies).Returns(new HttpCookieCollection());
            mockControllerContext.Setup(c => c.HttpContext.Response.Cookies).Returns(new HttpCookieCollection());
            mockControllerContext.Setup(c => c.HttpContext.Items).Returns(new Hashtable());
            mockControllerContext.Setup(c => c.RouteData).Returns(routeData);

            ControllerContext context = mockControllerContext.Object;
            TestableVirtualPathProviderViewEngine engine = new TestableVirtualPathProviderViewEngine();

            engine.MockPathProvider
                .Setup(vpp => vpp.FileExists("~/vpath/controllerName/viewName.view"))
                .Returns(true)
                .Verifiable();
            engine.MockCache
                .Setup(c => c.InsertViewLocation(It.IsAny<HttpContextBase>(), It.IsAny<string>(), "~/vpath/controllerName/viewName.view"))
                .Verifiable();
            engine.MockPathProvider
                .Setup(vpp => vpp.FileExists("~/vpath/controllerName/viewName.Mobile.view"))
                .Returns(false)
                .Verifiable();

            engine.MockPathProvider
                .Setup(vpp => vpp.FileExists("~/vpath/controllerName/partialName.partial"))
                .Returns(false)
                .Verifiable();
            engine.MockPathProvider
                .Setup(vpp => vpp.FileExists("~/vpath/controllerName/partialName.Mobile.partial"))
                .Returns(true)
                .Verifiable();
            engine.MockCache
                .Setup(c => c.InsertViewLocation(It.IsAny<HttpContextBase>(), It.IsAny<string>(), "~/vpath/controllerName/partialName.Mobile.partial"))
                .Callback<HttpContextBase, string, string>((httpContext, key, virtualPath) =>
                {
                    engine.MockCache
                        .Setup(c => c.GetViewLocation(It.IsAny<HttpContextBase>(), key))
                        .Returns("~/vpath/controllerName/partialName.Mobile.partial")
                        .Verifiable();
                })
                .Verifiable();

            // Act
            ViewEngineResult viewResult = engine.FindView(context, "viewName", masterName: null, useCache: false);

            // Mobile display mode will be used to locate the view with and without the cache.
            // In neither case should this set the DisplayModeId to Mobile because it has already been set.
            ViewEngineResult partialResult = engine.FindPartialView(context, "partialName", useCache: false);
            ViewEngineResult cachedPartialResult = engine.FindPartialView(context, "partialName", useCache: true);

            // Assert
            engine.MockPathProvider.Verify();
            engine.MockCache.Verify();
            Assert.Same(engine.CreateViewResult, viewResult.View);
            Assert.Same(engine.CreatePartialViewResult, partialResult.View);
            Assert.Same(engine.CreatePartialViewResult, cachedPartialResult.View);

            Assert.Equal(DisplayModeProvider.DefaultDisplayModeId, context.DisplayMode.DisplayModeId);
        }
开发者ID:chrisortman,项目名称:aspnetwebstack,代码行数:65,代码来源:VirtualPathProviderViewEngineTest.cs

示例3: FindPartialView_VirtualPathViewDoesNotExist_ReturnsSearchedLocationsResult

        public void FindPartialView_VirtualPathViewDoesNotExist_ReturnsSearchedLocationsResult()
        {
            // Arrange
            ControllerContext context = CreateContext();
            TestableVirtualPathProviderViewEngine engine = new TestableVirtualPathProviderViewEngine();
            engine.MockPathProvider
                .Setup(vpp => vpp.FileExists("~/foo/bar.partial"))
                .Returns(false)
                .Verifiable();
            engine.MockCache
                .Setup(c => c.InsertViewLocation(It.IsAny<HttpContextBase>(), It.IsAny<string>(), ""))
                .Verifiable();

            // Act
            ViewEngineResult result = engine.FindPartialView(context, "~/foo/bar.partial", false);

            // Assert
            Assert.Null(result.View);
            Assert.Single(result.SearchedLocations);
            Assert.True(result.SearchedLocations.Contains("~/foo/bar.partial"));
            engine.MockPathProvider.Verify();
            engine.MockCache.Verify();
        }
开发者ID:chrisortman,项目名称:aspnetwebstack,代码行数:23,代码来源:VirtualPathProviderViewEngineTest.cs

示例4: FindPartialView_AbsolutePathViewNotSupported_ReturnsSearchedLocationsResult

        public void FindPartialView_AbsolutePathViewNotSupported_ReturnsSearchedLocationsResult()
        {
            // Arrange
            ControllerContext context = CreateContext();
            TestableVirtualPathProviderViewEngine engine = new TestableVirtualPathProviderViewEngine();
            engine.MockCache
                .Setup(c => c.InsertViewLocation(It.IsAny<HttpContextBase>(), It.IsAny<string>(), ""))
                .Verifiable();

            // Act
            ViewEngineResult result = engine.FindPartialView(context, "/foo/bar.unsupported", false);

            // Assert
            Assert.Null(result.View);
            Assert.Single(result.SearchedLocations);
            Assert.True(result.SearchedLocations.Contains("/foo/bar.unsupported"));
            engine.MockPathProvider.Verify<bool>(vpp => vpp.FileExists("/foo/bar.unsupported"), Times.Never());
            engine.MockCache.Verify();
        }
开发者ID:chrisortman,项目名称:aspnetwebstack,代码行数:19,代码来源:VirtualPathProviderViewEngineTest.cs

示例5: FindPartialView_ViewDoesNotExist_ReturnsSearchLocationsResult

        public void FindPartialView_ViewDoesNotExist_ReturnsSearchLocationsResult()
        {
            // Arrange
            ControllerContext context = CreateContext();
            TestableVirtualPathProviderViewEngine engine = new TestableVirtualPathProviderViewEngine();
            engine.MockPathProvider
                .Setup(vpp => vpp.FileExists("~/vpath/controllerName/partialName.partial"))
                .Returns(false)
                .Verifiable();

            // Act
            ViewEngineResult result = engine.FindPartialView(context, "partialName", false);

            // Assert
            Assert.Null(result.View);
            Assert.Single(result.SearchedLocations);
            Assert.True(result.SearchedLocations.Contains("~/vpath/controllerName/partialName.partial"));
            engine.MockPathProvider.Verify();
        }
开发者ID:chrisortman,项目名称:aspnetwebstack,代码行数:19,代码来源:VirtualPathProviderViewEngineTest.cs

示例6: FindPartialView_VirtualPathViewExists_Legacy_ReturnsView

        public void FindPartialView_VirtualPathViewExists_Legacy_ReturnsView()
        {
            // Arrange
            ControllerContext context = CreateContext();
            TestableVirtualPathProviderViewEngine engine = new TestableVirtualPathProviderViewEngine()
            {
                FileExtensions = null, // Set FileExtensions to null to simulate View Engines that do not set this property
            };
            engine.MockPathProvider
                .Setup(vpp => vpp.FileExists("~/foo/bar.unsupported"))
                .Returns(true)
                .Verifiable();
            engine.MockCache
                .Setup(c => c.InsertViewLocation(It.IsAny<HttpContextBase>(), It.IsAny<string>(), "~/foo/bar.unsupported"))
                .Verifiable();

            // Act
            ViewEngineResult result = engine.FindPartialView(context, "~/foo/bar.unsupported", false);

            // Assert
            Assert.Same(engine.CreatePartialViewResult, result.View);
            Assert.Null(result.SearchedLocations);
            Assert.Same(context, engine.CreatePartialViewControllerContext);
            Assert.Equal("~/foo/bar.unsupported", engine.CreatePartialViewPartialPath);
            engine.MockPathProvider.Verify();
            engine.MockCache.Verify();
        }
开发者ID:chrisortman,项目名称:aspnetwebstack,代码行数:27,代码来源:VirtualPathProviderViewEngineTest.cs

示例7: FindPartialView_ControllerNameNotInRequestContext_Throws

        public void FindPartialView_ControllerNameNotInRequestContext_Throws()
        {
            // Arrange
            TestableVirtualPathProviderViewEngine engine = new TestableVirtualPathProviderViewEngine();
            ControllerContext context = CreateContext();
            context.RouteData.Values.Remove("controller");

            // Act & Assert
            Assert.Throws<InvalidOperationException>(
                () => engine.FindPartialView(context, "partialName", false),
                "The RouteData must contain an item named 'controller' with a non-empty string value."
                );
        }
开发者ID:chrisortman,项目名称:aspnetwebstack,代码行数:13,代码来源:VirtualPathProviderViewEngineTest.cs

示例8: FindPartialView_EmptyPartialViewLocations_Throws

        public void FindPartialView_EmptyPartialViewLocations_Throws()
        {
            // Arrange
            ControllerContext context = CreateContext();
            TestableVirtualPathProviderViewEngine engine = new TestableVirtualPathProviderViewEngine();
            engine.ClearPartialViewLocations();

            // Act & Assert
            Assert.Throws<InvalidOperationException>(
                () => engine.FindPartialView(context, "partialName", false),
                "The property 'PartialViewLocationFormats' cannot be null or empty."
                );
        }
开发者ID:chrisortman,项目名称:aspnetwebstack,代码行数:13,代码来源:VirtualPathProviderViewEngineTest.cs

示例9: FindPartialView_NullControllerContext_Throws

        public void FindPartialView_NullControllerContext_Throws()
        {
            // Arrange
            TestableVirtualPathProviderViewEngine engine = new TestableVirtualPathProviderViewEngine();

            // Act & Assert
            Assert.ThrowsArgumentNull(
                () => engine.FindPartialView(null, "view name", false),
                "controllerContext"
                );
        }
开发者ID:chrisortman,项目名称:aspnetwebstack,代码行数:11,代码来源:VirtualPathProviderViewEngineTest.cs

示例10: FindPartialView_EmptyPartialViewName_Throws

        public void FindPartialView_EmptyPartialViewName_Throws()
        {
            // Arrange
            ControllerContext context = CreateContext();
            TestableVirtualPathProviderViewEngine engine = new TestableVirtualPathProviderViewEngine();

            // Act & Assert
            Assert.ThrowsArgumentNullOrEmpty(
                () => engine.FindPartialView(context, "", false),
                "partialViewName"
                );
        }
开发者ID:chrisortman,项目名称:aspnetwebstack,代码行数:12,代码来源:VirtualPathProviderViewEngineTest.cs

示例11: UsesDifferentKeysForViewMasterAndPartial

        public void UsesDifferentKeysForViewMasterAndPartial()
        {
            string keyMaster = null;
            string keyPartial = null;
            string keyView = null;

            // Arrange
            ControllerContext context = CreateContext();
            TestableVirtualPathProviderViewEngine engine = new TestableVirtualPathProviderViewEngine();
            engine.MockPathProvider
                .Setup(vpp => vpp.FileExists(VIEW_VIRTUAL))
                .Returns(true)
                .Verifiable();
            engine.MockPathProvider
                .Setup(vpp => vpp.FileExists(MOBILE_VIEW_VIRTUAL))
                .Returns(false)
                .Verifiable();
            engine.MockPathProvider
                .Setup(vpp => vpp.FileExists(MASTER_VIRTUAL))
                .Returns(true)
                .Verifiable();
            engine.MockPathProvider
                .Setup(vpp => vpp.FileExists("~/vpath/controllerName/name.Mobile.master"))
                .Returns(false)
                .Verifiable();
            engine.MockPathProvider
                .Setup(vpp => vpp.FileExists(PARTIAL_VIRTUAL))
                .Returns(true)
                .Verifiable();
            engine.MockPathProvider
                .Setup(vpp => vpp.FileExists("~/vpath/controllerName/name.Mobile.partial"))
                .Returns(false)
                .Verifiable();
            engine.MockCache
                .Setup(c => c.InsertViewLocation(It.IsAny<HttpContextBase>(), It.IsAny<string>(), VIEW_VIRTUAL))
                .Callback<HttpContextBase, string, string>((httpContext, key, path) => keyView = key)
                .Verifiable();
            engine.MockCache
                .Setup(c => c.InsertViewLocation(It.IsAny<HttpContextBase>(), It.IsAny<string>(), MASTER_VIRTUAL))
                .Callback<HttpContextBase, string, string>((httpContext, key, path) => keyMaster = key)
                .Verifiable();
            engine.MockCache
                .Setup(c => c.InsertViewLocation(It.IsAny<HttpContextBase>(), It.IsAny<string>(), PARTIAL_VIRTUAL))
                .Callback<HttpContextBase, string, string>((httpContext, key, path) => keyPartial = key)
                .Verifiable();

            // Act
            engine.FindView(context, "name", "name", false);
            engine.FindPartialView(context, "name", false);

            // Assert
            Assert.NotNull(keyMaster);
            Assert.NotNull(keyPartial);
            Assert.NotNull(keyView);
            Assert.NotEqual(keyMaster, keyPartial);
            Assert.NotEqual(keyMaster, keyView);
            Assert.NotEqual(keyPartial, keyView);
            engine.MockPathProvider.Verify();
            engine.MockCache.Verify();
            engine.MockPathProvider
                .Verify(vpp => vpp.FileExists(VIEW_VIRTUAL), Times.AtMostOnce());
            engine.MockPathProvider
                .Verify(vpp => vpp.FileExists(MASTER_VIRTUAL), Times.AtMostOnce());
            engine.MockPathProvider
                .Verify(vpp => vpp.FileExists(PARTIAL_VIRTUAL), Times.AtMostOnce());
            engine.MockCache
                .Verify(c => c.InsertViewLocation(It.IsAny<HttpContextBase>(), It.IsAny<string>(), VIEW_VIRTUAL), Times.AtMostOnce());
            engine.MockCache
                .Verify(c => c.InsertViewLocation(It.IsAny<HttpContextBase>(), It.IsAny<string>(), MASTER_VIRTUAL), Times.AtMostOnce());
            engine.MockCache
                .Verify(c => c.InsertViewLocation(It.IsAny<HttpContextBase>(), It.IsAny<string>(), PARTIAL_VIRTUAL), Times.AtMostOnce());
        }
开发者ID:chrisortman,项目名称:aspnetwebstack,代码行数:72,代码来源:VirtualPathProviderViewEngineTest.cs

示例12: ViewFound

        public void ViewFound() {
            // Arrange
            ControllerContext context = CreateContext();
            TestableVirtualPathProviderViewEngine engine = new TestableVirtualPathProviderViewEngine();
            engine.MockPathProvider
                .Expect(vpp => vpp.FileExists("~/vpath/controllerName/partialName.partial"))
                .Returns(true)
                .Verifiable();
            engine.MockCache
                .Expect(c => c.InsertViewLocation(It.IsAny<HttpContextBase>(), It.IsAny<string>(), "~/vpath/controllerName/partialName.partial"))
                .Verifiable();

            // Act
            ViewEngineResult result = engine.FindPartialView(context, "partialName", false);

            // Assert
            Assert.AreSame(engine.CreatePartialViewResult, result.View);
            Assert.IsNull(result.SearchedLocations);
            Assert.AreSame(context, engine.CreatePartialViewControllerContext);
            Assert.AreEqual("~/vpath/controllerName/partialName.partial", engine.CreatePartialViewPartialPath);
            engine.MockPathProvider.Verify();
            engine.MockCache.Verify();
        }
开发者ID:pruiz,项目名称:AspMvc2,代码行数:23,代码来源:VirtualPathProviderViewEngineTest.cs

示例13: CannotFindView

        public void CannotFindView() {
            // Arrange
            ControllerContext context = CreateContext();
            TestableVirtualPathProviderViewEngine engine = new TestableVirtualPathProviderViewEngine();
            engine.MockPathProvider
                .Expect(vpp => vpp.FileExists("~/vpath/controllerName/partialName.partial"))
                .Returns(false)
                .Verifiable();

            // Act
            ViewEngineResult result = engine.FindPartialView(context, "partialName", false);

            // Assert
            Assert.IsNull(result.View);
            Assert.AreEqual(1, result.SearchedLocations.Count());
            Assert.IsTrue(result.SearchedLocations.Contains("~/vpath/controllerName/partialName.partial"));
            engine.MockPathProvider.Verify();
        }
开发者ID:pruiz,项目名称:AspMvc2,代码行数:18,代码来源:VirtualPathProviderViewEngineTest.cs

示例14: FindPartialViewWithEmptyViewNameThrows

        public void FindPartialViewWithEmptyViewNameThrows() {
            // Arrange
            ControllerContext context = CreateContext();
            TestableVirtualPathProviderViewEngine engine = new TestableVirtualPathProviderViewEngine();

            // Act & Assert
            ExceptionHelper.ExpectArgumentExceptionNullOrEmpty(
                () => engine.FindPartialView(context, "", false),
                "partialViewName"
            );
        }
开发者ID:pruiz,项目名称:AspMvc2,代码行数:11,代码来源:VirtualPathProviderViewEngineTest.cs

示例15: FindPartialViewWithNullControllerContextThrows

        public void FindPartialViewWithNullControllerContextThrows() {
            // Arrange
            TestableVirtualPathProviderViewEngine engine = new TestableVirtualPathProviderViewEngine();

            // Act & Assert
            ExceptionHelper.ExpectArgumentNullException(
                () => engine.FindPartialView(null, "view name", false),
                "controllerContext"
            );
        }
开发者ID:pruiz,项目名称:AspMvc2,代码行数:10,代码来源:VirtualPathProviderViewEngineTest.cs


注:本文中的TestableVirtualPathProviderViewEngine.FindPartialView方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。