public void MasterPathProperty() { // Act WebFormView view = new WebFormView("view path", "master path"); // Assert Assert.AreEqual("master path", view.MasterPath); }
public void MasterPathPropertyReturnsEmptyStringIfMasterNotSpecified() { // Act WebFormView view = new WebFormView("view path", null); // Assert Assert.AreEqual(String.Empty, view.MasterPath); }
public void RenderWithNullContextThrows() { // Arrange WebFormView view = new WebFormView("~/view", "~/master"); // Act & Assert ExceptionHelper.ExpectArgumentNullException( () => view.Render(null, new Mock<TextWriter>().Object), "viewContext" ); }
public static string RenderViewToString(string viewPath, object model, ControllerContext controllerContext) { using (var writer = new StringWriter()) { var view = new WebFormView(viewPath); var vdd = new ViewDataDictionary(model); var viewCxt = new ViewContext(controllerContext, view, vdd, new TempDataDictionary(), writer); viewCxt.ViewData = new ViewDataDictionary(model); viewCxt.View.Render(viewCxt, writer); return writer.ToString(); } }
public void RenderWithUnsupportedTypeThrows() { // Arrange ViewContext context = new Mock<ViewContext>().Object; MockBuildManager buildManagerMock = new MockBuildManager("view path", typeof(object), 12345); WebFormView view = new WebFormView("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<TViewData>, ViewUserControl, or ViewUserControl<TViewData>." ); }
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." ); }
private static Type GetWebFormViewModelType(WebFormView view) { var viewPage = BuildManager.CreateInstanceFromVirtualPath(view.ViewPath, typeof (object)); if (viewPage == null) { return null; } var modelType = GetModelType(viewPage); TryDispose(viewPage); return modelType; }
private static void ExecuteTest(ControllerContext testControllerContext, string viewName, string viewPathExpected) { var testViewFormView = new WebFormView(viewPathExpected); var fakeViewEngine = new Mock<IViewEngine>(); var webFormViewEngine = new MockMobileCapableWebFormViewEngine( testViewFormView, fakeViewEngine.Object, viewPathExpected); var viewEngineResult = webFormViewEngine.FindView(testControllerContext, viewName, string.Empty, false); viewEngineResult.Should().Not.Be.Null(); viewEngineResult.View.Should().Not.Be.Null(); viewEngineResult.ViewEngine.Should().Not.Be.Null(); ((WebFormView)viewEngineResult.View).ViewPath.Should().Be(viewPathExpected); }
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); }
public void IncludePageScriptReturnsIncludeForPageScript() { var httpContext = MockRepository.GenerateStub<HttpContextBase>(); var viewContext = MockRepository.GenerateStub<ViewContext>(); var httpRequest = MockRepository.GenerateStub<HttpRequestBase>(); httpContext.Stub(c => c.Request).Return(httpRequest).Repeat.Any(); httpRequest.Stub(c => c.ApplicationPath).Return("http://localhost/TestComet/"); var view = new WebFormView("~/Views/Home/Index.aspx"); viewContext.View = view; viewContext.HttpContext = httpContext; viewContext.RequestContext = new RequestContext(httpContext, new RouteData()); var html = new HtmlHelper(viewContext, new ViewPage()); Assert.AreEqual(@"<script src=""http://localhost/TestComet/Scripts/Views/Home/Index.js"" type=""text/javascript""></script>", html.IncludePageScript() ); }
public void EnableQUnitIfTestMode() { var httpContext = MockRepository.GenerateStub<HttpContextBase>(); var viewContext = MockRepository.GenerateStub<ViewContext>(); var httpRequest = MockRepository.GenerateStub<HttpRequestBase>(); httpContext.Stub(c => c.Request).Return(httpRequest).Repeat.Any(); httpRequest.Stub(c => c.ApplicationPath).Return("http://localhost/CometGateway.Server.TelnetDemo"); viewContext.HttpContext = httpContext; viewContext.RequestContext = new RequestContext( httpContext, new RouteData() ); var viewData = new ViewDataDictionary() {{TestModeConstants.ENABLE_TEST_MODE, true}}; viewContext.ViewData = viewData; var view = new WebFormView("~/Views/Main/Index.aspx"); viewContext.View = view; var html = new HtmlHelper( viewContext, new ViewPage() ); html.ViewDataContainer.ViewData = viewData; const string expectedSnippet = @" <link href=""http://localhost/CometGateway.Server.TelnetDemo/Content/QUnit.css"" rel=""stylesheet"" type=""text/css""></link> <script src=""http://localhost/CometGateway.Server.TelnetDemo/Scripts/qunit.js"" type=""text/javascript""></script> <script src=""http://localhost/CometGateway.Server.TelnetDemo/Scripts/Views/Main/IndexTest.js"" type=""text/javascript""></script> <div id='testResults'> <h1 id='qunit-header'></h1> <h2 id='qunit-banner'></h2> <h2 id='qunit-userAgent'></h2> <ol id='qunit-tests'></ol> <div id='qunit-fixture'></div> </div> <script type='text/javascript'>var testmode = true;</script> <script type='text/javascript'> $('body').contents().hide(); $('#testResults').show(); </script>"; TestUtilities.AssertStringsMatch( expectedSnippet, html.EnableQUnitTesting()); }
public WrappedView(WebFormView baseView, IContainer container) { BaseView = baseView; Container = container; }
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); }
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 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." ); }
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); }