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


C# ViewEngineCollection.FindPartialView方法代码示例

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


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

示例1: FindPartialView

 // copied from HtmlHelper.FindPartialView because it's original is internal
 internal static IView FindPartialView(ViewContext viewContext, string partialViewName, ViewEngineCollection viewEngineCollection)
 {
   ViewEngineResult result = viewEngineCollection.FindPartialView(viewContext, partialViewName);
   if (result.View != null)
   {
     return result.View;
   }
   StringBuilder builder = new StringBuilder();
   foreach (string str in result.SearchedLocations)
   {
     builder.AppendLine();
     builder.Append(str);
   }
   throw new InvalidOperationException(string.Format(CultureInfo.CurrentCulture, 
     "The partial view '{0}' was not found or no view engine supports the searched locations. The following locations were searched:{1}",
     new object[] { partialViewName, builder }));
 }
开发者ID:q42jaap,项目名称:PartialMagic.Mvc,代码行数:18,代码来源:PartialExtensions.cs

示例2: FindPartialViewAggregatesAllSearchedLocationsIfAllEnginesFail

        public void FindPartialViewAggregatesAllSearchedLocationsIfAllEnginesFail() {
            // Arrange
            ControllerContext context = new Mock<ControllerContext>().Object;
            ViewEngineCollection viewEngineCollection = new ViewEngineCollection();
            Mock<IViewEngine> engine1 = new Mock<IViewEngine>();
            ViewEngineResult engine1Result = new ViewEngineResult(new[] { "location1", "location2" });
            engine1.Setup(e => e.FindPartialView(context, "partial", It.IsAny<bool>())).Returns(engine1Result);
            Mock<IViewEngine> engine2 = new Mock<IViewEngine>();
            ViewEngineResult engine2Result = new ViewEngineResult(new[] { "location3", "location4" });
            engine2.Setup(e => e.FindPartialView(context, "partial", It.IsAny<bool>())).Returns(engine2Result);
            viewEngineCollection.Add(engine1.Object);
            viewEngineCollection.Add(engine2.Object);

            // Act
            ViewEngineResult result = viewEngineCollection.FindPartialView(context, "partial");

            // Assert
            Assert.IsNull(result.View);
            Assert.AreEqual(4, result.SearchedLocations.Count());
            Assert.IsTrue(result.SearchedLocations.Contains("location1"));
            Assert.IsTrue(result.SearchedLocations.Contains("location2"));
            Assert.IsTrue(result.SearchedLocations.Contains("location3"));
            Assert.IsTrue(result.SearchedLocations.Contains("location4"));
        }
开发者ID:adrianvallejo,项目名称:MVC3_Source,代码行数:24,代码来源:ViewEngineCollectionTest.cs

示例3: FindPartialViewThrowsIfControllerContextIsNull

        public void FindPartialViewThrowsIfControllerContextIsNull()
        {
            // Arrange
            ViewEngineCollection collection = new ViewEngineCollection();

            // Act & Assert
            Assert.ThrowsArgumentNull(
                () => collection.FindPartialView(null, "partial"),
                "controllerContext");
        }
开发者ID:balajivasudevan,项目名称:aspnetwebstack,代码行数:10,代码来源:ViewEngineCollectionTest.cs

示例4: FindPartialViewThrowsIfPartialViewNameIsNull

        public void FindPartialViewThrowsIfPartialViewNameIsNull()
        {
            // Arrange
            ControllerContext context = new Mock<ControllerContext>().Object;
            ViewEngineCollection collection = new ViewEngineCollection();

            // Act & Assert
            Assert.ThrowsArgumentNullOrEmpty(
                () => collection.FindPartialView(context, null),
                "partialViewName");
        }
开发者ID:balajivasudevan,项目名称:aspnetwebstack,代码行数:11,代码来源:ViewEngineCollectionTest.cs

示例5: FindPartialViewSuccessWithOneEngine

        public void FindPartialViewSuccessWithOneEngine()
        {
            // Arrange
            ControllerContext context = new Mock<ControllerContext>().Object;
            ViewEngineCollection collection = new ViewEngineCollection();
            Mock<IViewEngine> engine = new Mock<IViewEngine>();
            ViewEngineResult engineResult = new ViewEngineResult(new Mock<IView>().Object, engine.Object);
            engine.Setup(e => e.FindPartialView(context, "partial", It.IsAny<bool>())).Returns(engineResult);
            collection.Add(engine.Object);

            // Act
            ViewEngineResult result = collection.FindPartialView(context, "partial");

            // Assert
            Assert.Same(engineResult, result);
        }
开发者ID:balajivasudevan,项目名称:aspnetwebstack,代码行数:16,代码来源:ViewEngineCollectionTest.cs

示例6: FindPartialViewReturnsNoViewAndEmptySearchedLocationsIfCollectionEmpty

        public void FindPartialViewReturnsNoViewAndEmptySearchedLocationsIfCollectionEmpty()
        {
            // Arrange
            ControllerContext context = new Mock<ControllerContext>().Object;
            ViewEngineCollection collection = new ViewEngineCollection();

            // Act
            ViewEngineResult result = collection.FindPartialView(context, "partial");

            // Assert
            Assert.Null(result.View);
            Assert.Empty(result.SearchedLocations);
        }
开发者ID:balajivasudevan,项目名称:aspnetwebstack,代码行数:13,代码来源:ViewEngineCollectionTest.cs

示例7: FindPartialViewRemovesDuplicateSearchedLocationsFromMultipleEngines

        public void FindPartialViewRemovesDuplicateSearchedLocationsFromMultipleEngines()
        {
            // Arrange
            ControllerContext context = new Mock<ControllerContext>().Object;
            Mock<IViewEngine> engine1 = new Mock<IViewEngine>();
            ViewEngineResult engine1Result = new ViewEngineResult(new[] { "repeatLocation", "location1" });
            engine1.Setup(e => e.FindPartialView(context, "partial", It.IsAny<bool>())).Returns(engine1Result);
            Mock<IViewEngine> engine2 = new Mock<IViewEngine>();
            ViewEngineResult engine2Result = new ViewEngineResult(new[] { "location2", "repeatLocation" });
            engine2.Setup(e => e.FindPartialView(context, "partial", It.IsAny<bool>())).Returns(engine2Result);
            ViewEngineCollection viewEngineCollection = new ViewEngineCollection()
            {
                engine1.Object,
                engine2.Object,
            };

            // Act
            ViewEngineResult result = viewEngineCollection.FindPartialView(context, "partial");

            // Assert
            var expectedLocations = new[] { "repeatLocation", "location1", "location2" };
            Assert.Null(result.View);
            Assert.Equal(expectedLocations, result.SearchedLocations.ToArray());
        }
开发者ID:balajivasudevan,项目名称:aspnetwebstack,代码行数:24,代码来源:ViewEngineCollectionTest.cs

示例8: FindPartialViewIteratesThroughCollectionUntilFindsSuccessfulEngine

        public void FindPartialViewIteratesThroughCollectionUntilFindsSuccessfulEngine()
        {
            // Arrange
            ControllerContext context = new Mock<ControllerContext>().Object;
            ViewEngineCollection collection = new ViewEngineCollection();
            Mock<IViewEngine> engine1 = new Mock<IViewEngine>();
            ViewEngineResult engine1Result = new ViewEngineResult(new[] { "location1", "location2" });
            engine1.Setup(e => e.FindPartialView(context, "partial", It.IsAny<bool>())).Returns(engine1Result);
            Mock<IViewEngine> engine2 = new Mock<IViewEngine>();
            ViewEngineResult engine2Result = new ViewEngineResult(new Mock<IView>().Object, engine2.Object);
            engine2.Setup(e => e.FindPartialView(context, "partial", It.IsAny<bool>())).Returns(engine2Result);
            collection.Add(engine1.Object);
            collection.Add(engine2.Object);

            // Act
            ViewEngineResult result = collection.FindPartialView(context, "partial");

            // Assert
            Assert.Same(engine2Result, result);
        }
开发者ID:balajivasudevan,项目名称:aspnetwebstack,代码行数:20,代码来源:ViewEngineCollectionTest.cs

示例9: FindPartialViewLooksAtLocatorIfCacheEmpty

        public void FindPartialViewLooksAtLocatorIfCacheEmpty()
        {
            // Arrange
            ControllerContext context = new Mock<ControllerContext>().Object;
            Mock<IViewEngine> engine = new Mock<IViewEngine>();
            ViewEngineResult engineResult = new ViewEngineResult(new Mock<IView>().Object, engine.Object);
            engine.Setup(e => e.FindPartialView(context, "partial", true)).Returns(new ViewEngineResult(new[] { "path" }));
            engine.Setup(e => e.FindPartialView(context, "partial", false)).Returns(engineResult);
            ViewEngineCollection collection = new ViewEngineCollection()
            {
                engine.Object,
            };

            // Act
            ViewEngineResult result = collection.FindPartialView(context, "partial");

            // Assert
            Assert.Same(engineResult, result);
            engine.Verify(e => e.FindPartialView(context, "partial", true), Times.Once());
            engine.Verify(e => e.FindPartialView(context, "partial", false), Times.Once());
        }
开发者ID:balajivasudevan,项目名称:aspnetwebstack,代码行数:21,代码来源:ViewEngineCollectionTest.cs

示例10: FindPartialViewFailureWithOneEngine

        public void FindPartialViewFailureWithOneEngine()
        {
            // Arrange
            ControllerContext context = new Mock<ControllerContext>().Object;
            ViewEngineCollection collection = new ViewEngineCollection();
            Mock<IViewEngine> engine = new Mock<IViewEngine>();
            ViewEngineResult engineResult = new ViewEngineResult(new[] { "location1", "location2" });
            engine.Setup(e => e.FindPartialView(context, "partial", It.IsAny<bool>())).Returns(engineResult);
            collection.Add(engine.Object);

            // Act
            ViewEngineResult result = collection.FindPartialView(context, "partial");

            // Assert
            Assert.Null(result.View);
            Assert.Equal(2, result.SearchedLocations.Count());
            Assert.True(result.SearchedLocations.Contains("location1"));
            Assert.True(result.SearchedLocations.Contains("location2"));
        }
开发者ID:balajivasudevan,项目名称:aspnetwebstack,代码行数:19,代码来源:ViewEngineCollectionTest.cs

示例11: FindPartialViewDelegatesToResolver

        public void FindPartialViewDelegatesToResolver()
        {
            // Arrange
            Mock<IView> view = new Mock<IView>();
            ControllerContext context = new ControllerContext();
            Mock<IViewEngine> locatedEngine = new Mock<IViewEngine>();
            ViewEngineResult engineResult = new ViewEngineResult(view.Object, locatedEngine.Object);
            locatedEngine.Setup(e => e.FindPartialView(context, "ViewName", true))
                .Returns(engineResult);
            Mock<IViewEngine> secondEngine = new Mock<IViewEngine>();
            Resolver<IEnumerable<IViewEngine>> resolver = new Resolver<IEnumerable<IViewEngine>> { Current = new IViewEngine[] { locatedEngine.Object, secondEngine.Object } };
            ViewEngineCollection engines = new ViewEngineCollection(resolver);

            // Act
            ViewEngineResult result = engines.FindPartialView(context, "ViewName");

            // Assert
            Assert.Same(engineResult, result);
            secondEngine.Verify(e => e.FindPartialView(context, "ViewName", It.IsAny<bool>()), Times.Never());
        }
开发者ID:JokerMisfits,项目名称:linux-packaging-mono,代码行数:20,代码来源:ViewEngineCollectionTest.cs

示例12: FindPartialViewThrowsIfPartialViewNameIsEmpty

        public void FindPartialViewThrowsIfPartialViewNameIsEmpty() {
            // Arrange
            ControllerContext context = new Mock<ControllerContext>().Object;
            ViewEngineCollection collection = new ViewEngineCollection();

            // Act & Assert
            ExceptionHelper.ExpectArgumentExceptionNullOrEmpty(
                () => collection.FindPartialView(context, ""),
                "partialViewName");
        }
开发者ID:ledgarl,项目名称:Samples,代码行数:10,代码来源:ViewEngineCollectionTest.cs

示例13: FindPartialViewReturnsValueFromFirstSuccessfulEngine

        public void FindPartialViewReturnsValueFromFirstSuccessfulEngine() {
            // Arrange
            ControllerContext context = new Mock<ControllerContext>().Object;
            ViewEngineCollection collection = new ViewEngineCollection();
            Mock<IViewEngine> engine1 = new Mock<IViewEngine>();
            ViewEngineResult engine1Result = new ViewEngineResult(new Mock<IView>().Object, engine1.Object);
            engine1.Expect(e => e.FindPartialView(context, "partial", It.IsAny<bool>())).Returns(engine1Result);
            Mock<IViewEngine> engine2 = new Mock<IViewEngine>();
            ViewEngineResult engine2Result = new ViewEngineResult(new Mock<IView>().Object, engine2.Object);
            engine2.Expect(e => e.FindPartialView(context, "partial", It.IsAny<bool>())).Returns(engine2Result);
            collection.Add(engine1.Object);
            collection.Add(engine2.Object);

            // Act
            ViewEngineResult result = collection.FindPartialView(context, "partial");

            // Assert
            Assert.AreSame(engine1Result, result);
        }
开发者ID:ledgarl,项目名称:Samples,代码行数:19,代码来源:ViewEngineCollectionTest.cs

示例14: FindPartialViewDelegatesToResolver

        public void FindPartialViewDelegatesToResolver()
        {
            // Arrange
            Mock<IView> view = new Mock<IView>();
            ControllerContext context = new ControllerContext();
            Mock<IViewEngine> locatedEngine = new Mock<IViewEngine>();
            ViewEngineResult engineResult = new ViewEngineResult(view.Object, locatedEngine.Object);
            locatedEngine.Setup(e => e.FindPartialView(context, "ViewName", true))
                .Returns(engineResult);
            Mock<IViewEngine> secondEngine = new Mock<IViewEngine>();

            var resolver = new Mock<IDependencyResolver>();
            resolver.Setup(r => r.GetServices(typeof(IViewEngine))).Returns(new IViewEngine[] { locatedEngine.Object, secondEngine.Object });

            ViewEngineCollection engines = new ViewEngineCollection(new IViewEngine[0], resolver.Object);

            // Act
            ViewEngineResult result = engines.FindPartialView(context, "ViewName");

            // Assert
            Assert.Same(engineResult, result);
            secondEngine.Verify(e => e.FindPartialView(context, "ViewName", It.IsAny<bool>()), Times.Never());
        }
开发者ID:balajivasudevan,项目名称:aspnetwebstack,代码行数:23,代码来源:ViewEngineCollectionTest.cs

示例15: FindPartialViewIgnoresSearchLocationsFromCache

        public void FindPartialViewIgnoresSearchLocationsFromCache()
        {
            // Arrange
            ControllerContext context = new Mock<ControllerContext>().Object;
            Mock<IViewEngine> engine = new Mock<IViewEngine>();
            engine.Setup(e => e.FindPartialView(context, "partial", true)).Returns(new ViewEngineResult(new[] { "cachePath" }));
            engine.Setup(e => e.FindPartialView(context, "partial", false)).Returns(new ViewEngineResult(new[] { "locatorPath" }));
            ViewEngineCollection collection = new ViewEngineCollection()
            {
                engine.Object,
            };

            // Act
            ViewEngineResult result = collection.FindPartialView(context, "partial");

            // Assert
            string searchedLocation = Assert.Single(result.SearchedLocations);
            Assert.Equal("locatorPath", searchedLocation);
            engine.Verify(e => e.FindPartialView(context, "partial", true), Times.Once());
            engine.Verify(e => e.FindPartialView(context, "partial", false), Times.Once());
        }
开发者ID:balajivasudevan,项目名称:aspnetwebstack,代码行数:21,代码来源:ViewEngineCollectionTest.cs


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