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


C# ViewEngineCollection.FindView方法代码示例

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


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

示例1: AsksEachViewEngineInTheOrderItWasCalled

        public void AsksEachViewEngineInTheOrderItWasCalled()
        {
            var redEngine = new Mock<IViewEngine>();
            var redResult = new ViewEngineResult(false, new[] { "Whatever"});
            redEngine.Setup(x => x.FindView(It.IsAny<ControllerContext>(), It.IsAny<ViewResultOptions>(), It.IsAny<string>())).Returns(redResult);

            var orangeEngine = new Mock<IViewEngine>();
            orangeEngine.Setup(x => x.FindView(It.IsAny<ControllerContext>(), It.IsAny<ViewResultOptions>(), It.IsAny<string>())).Returns((ViewEngineResult)null);

            var blueEngine = new Mock<IViewEngine>();
            var blueResult = new ViewEngineResult(true, new string[0]);
            blueEngine.Setup(x => x.FindView(It.IsAny<ControllerContext>(), It.IsAny<ViewResultOptions>(), It.IsAny<string>())).Returns(blueResult);

            var greenEngine = new Mock<IViewEngine>();
            var greenResult = new ViewEngineResult(true, new string[0]);
            greenEngine.Setup(x => x.FindView(It.IsAny<ControllerContext>(), It.IsAny<ViewResultOptions>(), It.IsAny<string>())).Returns(greenResult);

            var collection = new ViewEngineCollection();
            collection.Add(redEngine.Object);
            collection.Add(orangeEngine.Object);
            collection.Add(blueEngine.Object);
            collection.Add(greenEngine.Object);
            var result = collection.FindView(RequestBuilder.CreateRequest().BuildControllerContext(), new ViewResultOptions(), "Foo");
            Assert.AreEqual(blueResult, result);
        }
开发者ID:p69,项目名称:magellan-framework,代码行数:25,代码来源:ViewEngineCollectionTests.cs

示例2: MustRegisterViewEnginesBeforeFindingViews

        public void MustRegisterViewEnginesBeforeFindingViews()
        {
            var collection = new ViewEngineCollection();
            var context = RequestBuilder.CreateRequest().BuildControllerContext();
            var parameters = new ViewResultOptions();

            Assert.Throws<NavigationConfigurationException>(() => collection.FindView(context, parameters, "Foo"));
        }
开发者ID:p69,项目名称:magellan-framework,代码行数:8,代码来源:ViewEngineCollectionTests.cs

示例3: CombinesAllErrorsWhenResultIsNotFound

        public void CombinesAllErrorsWhenResultIsNotFound()
        {
            var redEngine = new Mock<IViewEngine>();
            var redResult = new ViewEngineResult(false, new[] { "red whatever" });
            redEngine.Setup(x => x.FindView(It.IsAny<ControllerContext>(), It.IsAny<ViewResultOptions>(), It.IsAny<string>())).Returns(redResult);

            var blueEngine = new Mock<IViewEngine>();
            var blueResult = new ViewEngineResult(false, new[] { "blue whatever" });
            blueEngine.Setup(x => x.FindView(It.IsAny<ControllerContext>(), It.IsAny<ViewResultOptions>(), It.IsAny<string>())).Returns(blueResult);

            var collection = new ViewEngineCollection();
            collection.Add(redEngine.Object);
            collection.Add(blueEngine.Object);
            var result = collection.FindView(RequestBuilder.CreateRequest().BuildControllerContext(), new ViewResultOptions(), "Foo");
            Assert.IsFalse(result.Success);
            Assert.AreEqual(2, result.SearchLocations.Count());
            Assert.AreEqual("red whatever", result.SearchLocations.ElementAt(0));
            Assert.AreEqual("blue whatever", result.SearchLocations.ElementAt(1));
        }
开发者ID:p69,项目名称:magellan-framework,代码行数:19,代码来源:ViewEngineCollectionTests.cs

示例4: FindViewThrowsIfControllerContextIsNull

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

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

示例5: FindViewSuccessWithOneEngine

        public void FindViewSuccessWithOneEngine()
        {
            // 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.FindView(context, "view", "master", It.IsAny<bool>())).Returns(engineResult);
            collection.Add(engine.Object);

            // Act
            ViewEngineResult result = collection.FindView(context, "view", "master");

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

示例6: FindViewReturnsNoViewAndEmptySearchedLocationsIfCollectionEmpty

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

            // Act
            ViewEngineResult result = collection.FindView(context, "view", null);

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

示例7: FindViewRemovesDuplicateSearchedLocationsFromMultipleEngines

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

            // Act
            ViewEngineResult result = collection.FindView(context, "view", "master");

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

示例8: FindViewIteratesThroughCollectionUntilFindsSuccessfulEngine

        public void FindViewIteratesThroughCollectionUntilFindsSuccessfulEngine()
        {
            // 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.FindView(context, "view", "master", 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.FindView(context, "view", "master", It.IsAny<bool>())).Returns(engine2Result);
            collection.Add(engine1.Object);
            collection.Add(engine2.Object);

            // Act
            ViewEngineResult result = collection.FindView(context, "view", "master");

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

示例9: FindViewIgnoresSearchLocationsFromCache

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

            // Act
            ViewEngineResult result = collection.FindView(context, "view", "master");

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

示例10: FindViewFailureWithOneEngine

        public void FindViewFailureWithOneEngine()
        {
            // 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.FindView(context, "view", "master", It.IsAny<bool>())).Returns(engineResult);
            collection.Add(engine.Object);

            // Act
            ViewEngineResult result = collection.FindView(context, "view", "master");

            // 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: FindViewAggregatesAllSearchedLocationsIfAllEnginesFail

        public void FindViewAggregatesAllSearchedLocationsIfAllEnginesFail()
        {
            // 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.FindView(context, "view", "master", It.IsAny<bool>())).Returns(engine1Result);
            Mock<IViewEngine> engine2 = new Mock<IViewEngine>();
            ViewEngineResult engine2Result = new ViewEngineResult(new[] { "location3", "location4" });
            engine2.Setup(e => e.FindView(context, "view", "master", It.IsAny<bool>())).Returns(engine2Result);
            collection.Add(engine1.Object);
            collection.Add(engine2.Object);

            // Act
            ViewEngineResult result = collection.FindView(context, "view", "master");

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

示例12: FindViewDelegatesToResolver

        public void FindViewDelegatesToResolver()
        {
            // 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.FindView(context, "ViewName", "MasterName", 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.FindView(context, "ViewName", "MasterName");

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

示例13: FindViewThrowsIfViewNameIsEmpty

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

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

示例14: FindViewReturnsValueFromFirstSuccessfulEngine

        public void FindViewReturnsValueFromFirstSuccessfulEngine() {
            // 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.FindView(context, "view", "master", 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.FindView(context, "view", "master", It.IsAny<bool>())).Returns(engine2Result);
            collection.Add(engine1.Object);
            collection.Add(engine2.Object);

            // Act
            ViewEngineResult result = collection.FindView(context, "view", "master");

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

示例15: FindPartialView

        private static IView FindPartialView(ViewContext viewContext, string partialViewName, ViewEngineCollection viewEngineCollection, string masterName)
        {
            ViewEngineResult result = viewEngineCollection.FindView(viewContext, partialViewName, masterName);
            if (result.View != null)
            {
                return result.View;
            }

            StringBuilder locationsText = new StringBuilder();
            foreach (string location in result.SearchedLocations)
            {
                locationsText.AppendLine();
                locationsText.Append(location);
            }

            throw new InvalidOperationException(String.Format(CultureInfo.CurrentUICulture,
                "could not find view {0} looked in {1}", partialViewName, locationsText));
        }
开发者ID:philemn,项目名称:MvcContrib,代码行数:18,代码来源:HtmlHelperExtensions.cs


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