Пример #1
0
        public void RenderWithNullContextThrows() {
            // Arrange
            WebFormView view = new WebFormView("~/view", "~/master");

            // Act & Assert
            ExceptionHelper.ExpectArgumentNullException(
                () => view.Render(null, new Mock<TextWriter>().Object),
                "viewContext"
            );
        }
Пример #2
0
        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."
            );
        }
Пример #3
0
        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>."
            );
        }
Пример #4
0
        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.AreEqual(context, viewPage.ResultViewContext);
            Assert.AreEqual("master path", viewPage.MasterLocation);
        }
Пример #5
0
        public void RenderWithViewPageAndMasterRendersView() {
            // 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", "master path");
            view.BuildManager = buildManager;

            // Act
            view.Render(context, null);

            // Assert
            Assert.AreEqual(context, viewPage.ResultViewContext);
            Assert.AreEqual("master path", viewPage.MasterLocation);
        }
Пример #6
0
        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);
        }
Пример #7
0
        public void RenderWithViewUserControlAndMasterThrows() {
            // 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", "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."
            );
        }
Пример #8
0
        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);
        }