本文整理汇总了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 }));
}
示例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"));
}
示例3: FindPartialViewThrowsIfControllerContextIsNull
public void FindPartialViewThrowsIfControllerContextIsNull()
{
// Arrange
ViewEngineCollection collection = new ViewEngineCollection();
// Act & Assert
Assert.ThrowsArgumentNull(
() => collection.FindPartialView(null, "partial"),
"controllerContext");
}
示例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");
}
示例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);
}
示例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);
}
示例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());
}
示例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);
}
示例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());
}
示例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"));
}
示例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());
}
示例12: FindPartialViewThrowsIfPartialViewNameIsEmpty
public void FindPartialViewThrowsIfPartialViewNameIsEmpty() {
// Arrange
ControllerContext context = new Mock<ControllerContext>().Object;
ViewEngineCollection collection = new ViewEngineCollection();
// Act & Assert
ExceptionHelper.ExpectArgumentExceptionNullOrEmpty(
() => collection.FindPartialView(context, ""),
"partialViewName");
}
示例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);
}
示例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());
}
示例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());
}