public void RenderWithViewPageRendersView() { // Arrange ViewContext context = new Mock <ViewContext>().Object; MockBuildManager buildManager = new MockBuildManager("view path", typeof(object)); Mock <IViewPageActivator> activator = new Mock <IViewPageActivator>(MockBehavior.Strict); ControllerContext controllerContext = new ControllerContext(); StubViewPage viewPage = new StubViewPage(); activator.Setup(l => l.Create(controllerContext, typeof(object))).Returns(viewPage); WebFormView view = new WebFormView( controllerContext, "view path", null, activator.Object ); view.BuildManager = buildManager; // Act view.Render(context, null); // Assert Assert.Equal(context, viewPage.ResultViewContext); Assert.Equal(String.Empty, viewPage.MasterLocation); }
public void Render(ViewContext viewContext, TextWriter writer) { var view = BuildManager.CreateInstanceFromVirtualPath(_view.ViewPath, typeof(object)); _container.BuildUp(view.GetType(), view); var viewPage = view as System.Web.Mvc.ViewPage; if (viewPage != null) { viewPage.ViewData = viewContext.ViewData; viewPage.RenderView(viewContext); return; } var viewUserControl = view as System.Web.Mvc.ViewUserControl; if (viewUserControl != null) { viewUserControl.ViewData = viewContext.ViewData; viewUserControl.RenderView(viewContext); return; } _view.Render(viewContext, writer); }
public void RenderWithNullContextThrows() { // Arrange WebFormView view = new WebFormView("~/view", "~/master"); // Act & Assert ExceptionHelper.ExpectArgumentNullException( () => view.Render(null, new Mock <TextWriter>().Object), "viewContext" ); }
public void RenderWithUnsupportedTypeThrows() { // Arrange ViewContext context = new Mock<ViewContext>().Object; MockBuildManager buildManagerMock = new MockBuildManager("view path", typeof(int)); WebFormView view = new WebFormView(new ControllerContext(), "view path", null); view.BuildManager = buildManagerMock; // Act & Assert Assert.Throws<InvalidOperationException>( () => view.Render(context, null), "The view at 'view path' must derive from ViewPage, ViewPage<TModel>, ViewUserControl, or ViewUserControl<TModel>." ); }
public void RenderWithUnsupportedTypeThrows() { // Arrange ViewContext context = new Mock <ViewContext>().Object; MockBuildManager buildManagerMock = new MockBuildManager("view path", typeof(int)); WebFormView view = new WebFormView(new ControllerContext(), "view path", null); view.BuildManager = buildManagerMock; // Act & Assert ExceptionHelper.ExpectException <InvalidOperationException>( () => view.Render(context, null), "The view at 'view path' must derive from ViewPage, ViewPage<TModel>, ViewUserControl, or ViewUserControl<TModel>." ); }
public void RenderWithViewUserControlAndMasterThrows() { // Arrange ViewContext context = new Mock <ViewContext>().Object; MockBuildManager buildManagerMock = new MockBuildManager("view path", typeof(StubViewUserControl)); WebFormView view = new WebFormView(new ControllerContext(), "view path", "master path"); view.BuildManager = buildManagerMock; // Act & Assert ExceptionHelper.ExpectException <InvalidOperationException>( () => view.Render(context, null), "A master name cannot be specified when the view is a ViewUserControl." ); }
public void RenderWithNullViewInstanceThrows() { // Arrange ViewContext context = new Mock <ViewContext>().Object; MockBuildManager buildManager = new MockBuildManager("view path", typeof(object), null); WebFormView view = new WebFormView("view path", null); view.BuildManager = buildManager; // Act & Assert ExceptionHelper.ExpectException <InvalidOperationException>( () => view.Render(context, null), "The view found at 'view path' could not be created." ); }
public void RenderWithViewUserControlRendersView() { // Arrange ViewContext context = new Mock <ViewContext>().Object; StubViewUserControl viewUserControl = new StubViewUserControl(); MockBuildManager buildManagerMock = new MockBuildManager("view path", typeof(object), viewUserControl); WebFormView view = new WebFormView("view path", null); view.BuildManager = buildManagerMock; // Act view.Render(context, null); // Assert Assert.AreEqual(context, viewUserControl.ResultViewContext); }
public void RenderWithViewPageRendersView() { // Arrange ViewContext context = new Mock <ViewContext>().Object; StubViewPage viewPage = new StubViewPage(); MockBuildManager buildManager = new MockBuildManager("view path", typeof(object), viewPage); WebFormView view = new WebFormView("view path", null); view.BuildManager = buildManager; // Act view.Render(context, null); // Assert Assert.AreEqual(context, viewPage.ResultViewContext); Assert.AreEqual(String.Empty, viewPage.MasterLocation); }
public void RenderWithViewPageAndMasterRendersView() { // Arrange ViewContext context = new Mock<ViewContext>().Object; MockBuildManager buildManager = new MockBuildManager("view path", typeof(object)); Mock<IViewPageActivator> activator = new Mock<IViewPageActivator>(MockBehavior.Strict); ControllerContext controllerContext = new ControllerContext(); StubViewPage viewPage = new StubViewPage(); activator.Setup(l => l.Create(controllerContext, typeof(object))).Returns(viewPage); WebFormView view = new WebFormView(controllerContext, "view path", "master path", activator.Object); view.BuildManager = buildManager; // Act view.Render(context, null); // Assert Assert.Equal(context, viewPage.ResultViewContext); Assert.Equal("master path", viewPage.MasterLocation); }
public void RenderWithViewUserControlRendersView() { // Arrange ViewContext context = new Mock <ViewContext>().Object; MockBuildManager buildManager = new MockBuildManager("view path", typeof(object)); Mock <IViewPageActivator> activator = new Mock <IViewPageActivator>(MockBehavior.Strict); ControllerContext controllerContext = new ControllerContext(); StubViewUserControl viewUserControl = new StubViewUserControl(); activator.Setup(l => l.Create(controllerContext, typeof(object))).Returns(viewUserControl); WebFormView view = new WebFormView(controllerContext, "view path", null, activator.Object) { BuildManager = buildManager }; // Act view.Render(context, null); // Assert Assert.AreEqual(context, viewUserControl.ResultViewContext); }
public void RenderWithViewUserControlRendersView() { // Arrange ViewContext context = new Mock<ViewContext>().Object; MockBuildManager buildManager = new MockBuildManager("view path", typeof(object)); Mock<IViewPageActivator> activator = new Mock<IViewPageActivator>(MockBehavior.Strict); ControllerContext controllerContext = new ControllerContext(); StubViewUserControl viewUserControl = new StubViewUserControl(); activator.Setup(l => l.Create(controllerContext, typeof(object))).Returns(viewUserControl); WebFormView view = new WebFormView(controllerContext, "view path", null, activator.Object) { BuildManager = buildManager }; // Act view.Render(context, null); // Assert Assert.Equal(context, viewUserControl.ResultViewContext); }
public void RenderWithViewUserControlAndMasterThrows() { // Arrange ViewContext context = new Mock<ViewContext>().Object; MockBuildManager buildManagerMock = new MockBuildManager("view path", typeof(StubViewUserControl)); WebFormView view = new WebFormView(new ControllerContext(), "view path", "master path"); view.BuildManager = buildManagerMock; // Act & Assert Assert.Throws<InvalidOperationException>( () => view.Render(context, null), "A master name cannot be specified when the view is a ViewUserControl." ); }