Esempio n. 1
0
        void RenderViewImpl(ViewContext viewContext, Func <XcstTemplateEvaluator, XcstOutputter> getOutputter, object instance)
        {
            if (viewContext is null)
            {
                throw new ArgumentNullException(nameof(viewContext));
            }
            if (instance is null)
            {
                throw new ArgumentNullException(nameof(instance));
            }

            XcstViewPage viewPage = instance as XcstViewPage
                                    ?? throw new InvalidOperationException($"The view at '{ViewPath}' must derive from {nameof(XcstViewPage)}, or {nameof(XcstViewPage)}<TModel>.");

            viewPage.ViewContext = viewContext;

            AddFileDependencies(instance, viewContext.HttpContext.Response);

            XcstEvaluator evaluator = XcstEvaluator.Using((object)viewPage);

            foreach (var item in viewContext.ViewData)
            {
                evaluator.WithParam(item.Key, item.Value);
            }

            getOutputter(evaluator.CallInitialTemplate())
            .Run();
        }
Esempio n. 2
0
        static bool OutputEqualsToExpected(Type packageType, Uri packageUri, bool printCode)
        {
            XcstViewPage package = CreatePackage(packageType);

            var expectedDoc = new XDocument();
            var actualDoc   = new XDocument();

            XcstEvaluator evaluator = XcstEvaluator.Using((object)package);

            using (XmlWriter actualWriter = actualDoc.CreateWriter()) {
                evaluator.CallInitialTemplate()
                .OutputTo(actualWriter)
                .WithBaseUri(packageUri)
                .WithBaseOutputUri(packageUri)
                .Run();
            }

            using (XmlWriter expectedWriter = expectedDoc.CreateWriter()) {
                evaluator.CallTemplate(_expectedName)
                .OutputTo(expectedWriter)
                .Run();
            }

            XDocument normalizedExpected = XDocumentNormalizer.Normalize(expectedDoc);
            XDocument normalizedActual   = XDocumentNormalizer.Normalize(actualDoc);
            bool      equals             = XNode.DeepEquals(normalizedExpected, normalizedActual);

            if (printCode || !equals)
            {
                Console.WriteLine("/*");
                Console.WriteLine("<!-- expected -->");
                Console.WriteLine(normalizedExpected.ToString());
                Console.WriteLine();
                Console.WriteLine("<!-- actual -->");
                Console.WriteLine(normalizedActual.ToString());
                Console.WriteLine("*/");
            }

            return(equals);
        }