Пример #1
0
        public void Instantiate_WithoutRootName()
        {
            string expectedSnippet = "<Root><MyElementID>1</MyElementID></Root>";
            var dataSource = new XslDataSource(new MockXslDataSource(expectedSnippet));

            Assert.IsNotNull(dataSource);
            Assert.IsTrue(dataSource.DataSource is MockXslDataSource);
            Assert.AreEqual(expectedSnippet, dataSource.XmlFragment.OuterXml);
        }
Пример #2
0
        public void Instantiate()
        {
            string formatString = "<{0}><MyElementID>1</MyElementID></{0}>";
            string expectedRootName = "MyRoot";
            string expectedSnippet = string.Format(formatString, expectedRootName);
            var dataSource = new XslDataSource(expectedRootName, new MockXslDataSource(formatString));

            Assert.IsNotNull(dataSource);
            Assert.IsTrue(dataSource.DataSource is MockXslDataSource);
            Assert.AreEqual(expectedRootName, dataSource.RootName);
            Assert.AreEqual(expectedSnippet, dataSource.XmlFragment.OuterXml);
        }
Пример #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);
        }