예제 #1
0
        public void ThrowExceptionWhenDataTypeIsInvalid()
        {
            var routeData = new RouteData();
            routeData.Values["controller"] = "MyController";

            XsltViewFactory viewFactory = new XsltViewFactory(new XsltTestVirtualPathProvider());

            viewFactory.FindView(new ControllerContext(HttpContext, routeData, _fakeController), "MyView", null,false);
        }
예제 #2
0
        public void RendersViewWithCustomPageVar()
        {
            string xml = @"<greetings><greeting language=""english""><p>Hello...</p></greeting></greetings>";
            string expected = "Selected language: english<p>Hello...</p>";

            var viewData = new XsltViewData();
            viewData.PageVars.Add("language", "english");
            viewData.DataSources.Add(new XslDataSource(new MockXslDataSource(xml)));
            _context.Controller.ViewData.Model = viewData;

            var viewFactory = new XsltViewFactory(virtualPathProvider);
            var viewResult = viewFactory.FindView(_context, "Greetings", null, false);
            var viewContext = new ViewContext(_context, viewResult.View, new ViewDataDictionary(viewData), new TempDataDictionary());

            viewResult.View.Render(viewContext, Response.Output);
            string actual = Response.Output.ToString().Replace("\r\n", "").Replace("\t", "");
            actual.ShouldEqual(expected);
        }
예제 #3
0
        public void RenderViewTest()
        {
            var vData = new XsltViewData();
            string expectedSnippet = "<Root><MyElementID>1</MyElementID></Root>";
            var dataSource = new XslDataSource(new MockXslDataSource(expectedSnippet));
            vData.DataSources.Add(dataSource);
            vData.Messages.Add(new Message(MessageType.Info, "This is a message"));
            vData.Messages.Add(new Message(MessageType.Info, "This is a message for a control", "controlID"));
            vData.Messages.Add(new InfoMessage("This is an info message"));
            vData.Messages.Add(new InfoMessage("This is an info message", "controlId2"));
            vData.Messages.Add(new InfoHtmlMessage("This is a html message"));
            vData.Messages.Add(new InfoHtmlMessage("This is a html message", "controlId3"));
            vData.Messages.Add(new ErrorHtmlMessage("This is an error html message"));
            vData.Messages.Add(new ErrorHtmlMessage("This is an error html message", "controlId4"));
            vData.Messages.Add(new ErrorMessage("This is an error message"));
            vData.Messages.Add(new ErrorMessage("This is an error message", "controlId4"));
            vData.Messages.Add(new AlertMessage("This is an alert message", "controlId4"));
            vData.Messages.Add(new AlertMessage("This is an alert message"));
            vData.Messages.Add(new AlertHtmlMessage("This is an alert html message", "controlId4"));
            vData.Messages.Add(new AlertHtmlMessage("This is an alert html message"));

            Request.QueryString["myQueryString"] = "myQueryStringValue";

            _context.Controller.ViewData.Model = vData;

            var viewFactory = new XsltViewFactory(virtualPathProvider);
            var viewResult = viewFactory.FindView(_context, "MyView", null,false);

            Assert.IsNotNull(viewResult.View);

            var viewContext = new ViewContext(_context, viewResult.View, new ViewDataDictionary(vData), new TempDataDictionary());

            viewResult.View.Render(viewContext, Response.Output);

            string actual = Response.Output.ToString().Replace("\r\n", "");

            XmlDocument xDoc = LoadXmlDocument("ViewTest.xml");

            string expected = xDoc.OuterXml;

            Assert.AreEqual(expected, actual);
        }