コード例 #1
0
ファイル: WebFormViewTest.cs プロジェクト: ledgarl/Samples
        public void MasterPathProperty() {
            // Act
            WebFormView view = new WebFormView("view path", "master path");

            // Assert
            Assert.AreEqual("master path", view.MasterPath);
        }
コード例 #2
0
ファイル: WebFormViewTest.cs プロジェクト: ledgarl/Samples
        public void MasterPathPropertyReturnsEmptyStringIfMasterNotSpecified() {
            // Act
            WebFormView view = new WebFormView("view path", null);

            // Assert
            Assert.AreEqual(String.Empty, view.MasterPath);
        }
コード例 #3
0
ファイル: WebFormViewTest.cs プロジェクト: ledgarl/Samples
        public void RenderWithNullContextThrows() {
            // Arrange
            WebFormView view = new WebFormView("~/view", "~/master");

            // Act & Assert
            ExceptionHelper.ExpectArgumentNullException(
                () => view.Render(null, new Mock<TextWriter>().Object),
                "viewContext"
            );
        }
コード例 #4
0
ファイル: MailService.cs プロジェクト: kilonet/elfam
 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();
     }
 }
コード例 #5
0
ファイル: WebFormViewTest.cs プロジェクト: ledgarl/Samples
        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>."
            );
        }
コード例 #6
0
ファイル: WebFormViewTest.cs プロジェクト: ledgarl/Samples
        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."
            );
        }
コード例 #7
0
        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;
        }
コード例 #8
0
        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);
        }
コード例 #9
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);
        }
コード例 #10
0
        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()
                          );
        }
コード例 #11
0
        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());
        }
コード例 #12
0
ファイル: WrappedView.cs プロジェクト: jbogard/blogexamples
 public WrappedView(WebFormView baseView, IContainer container)
 {
     BaseView = baseView;
     Container = container;
 }
コード例 #13
0
ファイル: WebFormViewTest.cs プロジェクト: ledgarl/Samples
        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);
        }
コード例 #14
0
ファイル: WebFormViewTest.cs プロジェクト: ledgarl/Samples
        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);
        }
コード例 #15
0
ファイル: WebFormViewTest.cs プロジェクト: ledgarl/Samples
        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."
            );
        }
コード例 #16
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);
        }