本文整理汇总了C#中TestableVirtualPathProviderViewEngine.FindView方法的典型用法代码示例。如果您正苦于以下问题:C# TestableVirtualPathProviderViewEngine.FindView方法的具体用法?C# TestableVirtualPathProviderViewEngine.FindView怎么用?C# TestableVirtualPathProviderViewEngine.FindView使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类TestableVirtualPathProviderViewEngine
的用法示例。
在下文中一共展示了TestableVirtualPathProviderViewEngine.FindView方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: FindViewWithNullControllerContextThrows
public void FindViewWithNullControllerContextThrows() {
// Arrange
TestableVirtualPathProviderViewEngine engine = new TestableVirtualPathProviderViewEngine();
// Act & Assert
ExceptionHelper.ExpectArgumentNullException(
() => engine.FindView(null, "view name", null, false),
"controllerContext"
);
}
示例2: FindView_NullControllerContext_Throws
public void FindView_NullControllerContext_Throws()
{
// Arrange
TestableVirtualPathProviderViewEngine engine = new TestableVirtualPathProviderViewEngine();
// Act & Assert
Assert.ThrowsArgumentNull(
() => engine.FindView(null, "view name", null, false),
"controllerContext"
);
}
示例3: FindViewWithEmptyViewNameThrows
public void FindViewWithEmptyViewNameThrows() {
// Arrange
ControllerContext context = CreateContext();
TestableVirtualPathProviderViewEngine engine = new TestableVirtualPathProviderViewEngine();
// Act & Assert
ExceptionHelper.ExpectArgumentExceptionNullOrEmpty(
() => engine.FindView(context, "", null, false),
"viewName"
);
}
示例4: FindViewViewLocationsCannotBeEmpty
public void FindViewViewLocationsCannotBeEmpty() {
// Arrange
ControllerContext context = CreateContext();
TestableVirtualPathProviderViewEngine engine = new TestableVirtualPathProviderViewEngine();
engine.ClearViewLocations();
// Act & Assert
ExceptionHelper.ExpectInvalidOperationException(
() => engine.FindView(context, "viewName", null, false),
"The property 'ViewLocationFormats' cannot be null or empty."
);
}
示例5: FindViewControllerNameMustExistInRequestContext
public void FindViewControllerNameMustExistInRequestContext() {
// Arrange
TestableVirtualPathProviderViewEngine engine = new TestableVirtualPathProviderViewEngine();
ControllerContext context = CreateContext();
context.RouteData.Values.Remove("controller");
// Act & Assert
ExceptionHelper.ExpectInvalidOperationException(
() => engine.FindView(context, "viewName", null, false),
"The RouteData must contain an item named 'controller' with a non-empty string value."
);
}
示例6: FindView_EmptyViewName_Throws
public void FindView_EmptyViewName_Throws()
{
// Arrange
ControllerContext context = CreateContext();
TestableVirtualPathProviderViewEngine engine = new TestableVirtualPathProviderViewEngine();
// Act & Assert
Assert.ThrowsArgumentNullOrEmpty(
() => engine.FindView(context, "", null, false),
"viewName"
);
}
示例7: FindView_AbsolutePathViewNotSupportedAndNoMaster_ReturnsSearchedLocationsResult
public void FindView_AbsolutePathViewNotSupportedAndNoMaster_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.FindView(context, "/foo/bar.unsupported", null, false);
// Assert
Assert.Null(result.View);
Assert.Single(result.SearchedLocations);
Assert.True(result.SearchedLocations.Contains("/foo/bar.unsupported"));
engine.MockPathProvider.Verify(vpp => vpp.FileExists("/foo/bar.unsupported"), Times.Never());
engine.MockCache.Verify();
}
示例8: NoValueInCacheButFileExistsReturnsNullIfUsingCache
public void NoValueInCacheButFileExistsReturnsNullIfUsingCache()
{
// Arrange
ControllerContext mobileContext = CreateContext(isMobileDevice: true);
TestableVirtualPathProviderViewEngine engine = new TestableVirtualPathProviderViewEngine();
engine.MockPathProvider
.Setup(vpp => vpp.FileExists(MOBILE_VIEW_VIRTUAL))
.Returns(true);
engine.MockPathProvider
.Setup(vpp => vpp.FileExists(VIEW_VIRTUAL))
.Returns(true);
engine.MockCache
.Setup(c => c.GetViewLocation(It.IsAny<HttpContextBase>(), It.IsAny<string>()))
.Returns((string)null)
.Verifiable();
engine.MockCache
.Setup(c => c.InsertViewLocation(It.IsAny<HttpContextBase>(), It.IsAny<string>(), It.IsAny<string>()));
// Act
IView viewNotInCacheResult = engine.FindView(mobileContext, "name", masterName: null, useCache: true).View;
// Assert
Assert.Null(viewNotInCacheResult);
// On a cache miss we should never check the file system. FindView will be called on a second pass
// without using the cache.
engine.MockPathProvider.Verify(vpp => vpp.FileExists(MOBILE_VIEW_VIRTUAL), Times.Never());
engine.MockPathProvider.Verify(vpp => vpp.FileExists(VIEW_VIRTUAL), Times.Never());
// Act & Assert
//At this point the view on disk should be found and cached.
Assert.NotNull(engine.FindView(mobileContext, "name", masterName: null, useCache: false).View);
}
示例9: FindView_VirtualPathViewDoesNotExistAndNoMaster_ReturnsSearchedLocationsResult
public void FindView_VirtualPathViewDoesNotExistAndNoMaster_ReturnsSearchedLocationsResult() {
// Arrange
ControllerContext context = CreateContext();
TestableVirtualPathProviderViewEngine engine = new TestableVirtualPathProviderViewEngine();
engine.MockPathProvider
.Setup(vpp => vpp.FileExists("~/foo/bar.view"))
.Returns(false)
.Verifiable();
engine.MockCache
.Setup(c => c.InsertViewLocation(It.IsAny<HttpContextBase>(), It.IsAny<string>(), ""))
.Verifiable();
// Act
ViewEngineResult result = engine.FindView(context, "~/foo/bar.view", null, false);
// Assert
Assert.IsNull(result.View);
Assert.AreEqual(1, result.SearchedLocations.Count());
Assert.IsTrue(result.SearchedLocations.Contains("~/foo/bar.view"));
engine.MockPathProvider.Verify();
engine.MockCache.Verify();
}
示例10: FindView_ViewDoesNotExistAndNoMaster_ReturnsSearchedLocationsResult
public void FindView_ViewDoesNotExistAndNoMaster_ReturnsSearchedLocationsResult()
{
// Arrange
ControllerContext context = CreateContext();
TestableVirtualPathProviderViewEngine engine = new TestableVirtualPathProviderViewEngine();
engine.MockPathProvider
.Setup(vpp => vpp.FileExists("~/vpath/controllerName/viewName.view"))
.Returns(false)
.Verifiable();
// Act
ViewEngineResult result = engine.FindView(context, "viewName", null, false);
// Assert
Assert.Null(result.View);
Assert.Single(result.SearchedLocations);
Assert.True(result.SearchedLocations.Contains("~/vpath/controllerName/viewName.view"));
engine.MockPathProvider.Verify();
}
示例11: FindView_MasterInAreaDoesNotExist_ReturnsSearchedLocationsResult
public void FindView_MasterInAreaDoesNotExist_ReturnsSearchedLocationsResult()
{
// Arrange
ControllerContext context = CreateContext();
context.RouteData.DataTokens["area"] = "areaName";
TestableVirtualPathProviderViewEngine engine = new TestableVirtualPathProviderViewEngine();
engine.MockPathProvider
.Setup(vpp => vpp.FileExists("~/vpath/areaName/controllerName/viewName.view"))
.Returns(true)
.Verifiable();
engine.MockCache
.Setup(c => c.InsertViewLocation(It.IsAny<HttpContextBase>(), It.IsAny<string>(), "~/vpath/areaName/controllerName/viewName.view"))
.Verifiable();
engine.MockPathProvider
.Setup(vpp => vpp.FileExists("~/vpath/areaName/controllerName/viewName.Mobile.view"))
.Returns(false)
.Verifiable();
engine.MockPathProvider
.Setup(vpp => vpp.FileExists("~/vpath/areaName/controllerName/masterName.master"))
.Returns(false)
.Verifiable();
engine.MockPathProvider
.Setup(vpp => vpp.FileExists("~/vpath/controllerName/masterName.master"))
.Returns(false)
.Verifiable();
// Act
ViewEngineResult result = engine.FindView(context, "viewName", "masterName", false);
// Assert
Assert.Null(result.View);
Assert.Equal(2, result.SearchedLocations.Count()); // View was found, not included in 'searched locations'
Assert.True(result.SearchedLocations.Contains("~/vpath/areaName/controllerName/masterName.master"));
Assert.True(result.SearchedLocations.Contains("~/vpath/controllerName/masterName.master"));
engine.MockPathProvider.Verify();
engine.MockCache.Verify();
}
示例12: FindView_ViewExistsAndMasterNameProvidedButEmptyMasterLocations_Throws
public void FindView_ViewExistsAndMasterNameProvidedButEmptyMasterLocations_Throws()
{
// Arrange
ControllerContext context = CreateContext();
TestableVirtualPathProviderViewEngine engine = new TestableVirtualPathProviderViewEngine();
engine.ClearMasterLocations();
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();
// Act & Assert
Assert.Throws<InvalidOperationException>(
() => engine.FindView(context, "viewName", "masterName", false),
"The property 'MasterLocationFormats' cannot be null or empty."
);
engine.MockPathProvider.Verify();
engine.MockCache.Verify();
}
示例13: CannotFindViewNoMaster
public void CannotFindViewNoMaster() {
// Arrange
ControllerContext context = CreateContext();
TestableVirtualPathProviderViewEngine engine = new TestableVirtualPathProviderViewEngine();
engine.MockPathProvider
.Expect(vpp => vpp.FileExists("~/vpath/controllerName/viewName.view"))
.Returns(false)
.Verifiable();
// Act
ViewEngineResult result = engine.FindView(context, "viewName", null, false);
// Assert
Assert.IsNull(result.View);
Assert.AreEqual(1, result.SearchedLocations.Count());
Assert.IsTrue(result.SearchedLocations.Contains("~/vpath/controllerName/viewName.view"));
engine.MockPathProvider.Verify();
}
示例14: ValueInCacheBypassesVirtualPathProvider
public void ValueInCacheBypassesVirtualPathProvider() {
// Arrange
ControllerContext context = CreateContext();
TestableVirtualPathProviderViewEngine engine = new TestableVirtualPathProviderViewEngine();
engine.MockPathProvider // It wasn't found, so they call vpp.FileExists
.Expect(vpp => vpp.FileExists(VIEW_VIRTUAL))
.Returns(true)
.AtMostOnce()
.Verifiable();
engine.MockCache // Then they set the value into the cache
.Expect(c => c.InsertViewLocation(It.IsAny<HttpContextBase>(), It.IsAny<string>(), VIEW_VIRTUAL))
.Callback<HttpContextBase, string, string>((httpContext, key, virtualPath) => {
engine.MockCache // Second time through, we give them a cache hit
.Expect(c => c.GetViewLocation(It.IsAny<HttpContextBase>(), key))
.Returns(VIEW_VIRTUAL)
.AtMostOnce()
.Verifiable();
})
.AtMostOnce()
.Verifiable();
// Act
engine.FindView(context, "name", null, false); // Call it once with false to seed the cache
engine.FindView(context, "name", null, true); // Call it once with true to check the cache
// Assert
engine.MockPathProvider.Verify();
engine.MockCache.Verify();
}
示例15: FoundViewCannotFindMaster
public void FoundViewCannotFindMaster() {
// Arrange
ControllerContext context = CreateContext();
TestableVirtualPathProviderViewEngine engine = new TestableVirtualPathProviderViewEngine();
engine.MockPathProvider
.Expect(vpp => vpp.FileExists("~/vpath/controllerName/viewName.view"))
.Returns(true)
.Verifiable();
engine.MockCache
.Expect(c => c.InsertViewLocation(It.IsAny<HttpContextBase>(), It.IsAny<string>(), "~/vpath/controllerName/viewName.view"))
.Verifiable();
engine.MockPathProvider
.Expect(vpp => vpp.FileExists("~/vpath/controllerName/masterName.master"))
.Returns(false)
.Verifiable();
// Act
ViewEngineResult result = engine.FindView(context, "viewName", "masterName", false);
// Assert
Assert.IsNull(result.View);
Assert.AreEqual(1, result.SearchedLocations.Count()); // View was found, not included in 'searched locations'
Assert.IsTrue(result.SearchedLocations.Contains("~/vpath/controllerName/masterName.master"));
engine.MockPathProvider.Verify();
engine.MockCache.Verify();
}