Exemple #1
0
        public static IEnumerable <string> ConvertFiles(IEnumerable <string> filesToConvert)
        {
            var parser = new WebFormsParser(new WebFormsNodeFactory(),
                                            new WebFormsNodeFilterProvider(new WebFormsCodeGroupFactory()));
            var renderer  = new RazorViewRenderer(new RazorNodeRendererProvider());
            var converter =
                new WebFormsToRazorConverter(new RazorNodeConverterProvider(new RazorDirectiveNodeFactory(),
                                                                            new RazorSectionNodeFactory(),
                                                                            new RazorCodeNodeFactory(),
                                                                            new RazorTextNodeFactory(),
                                                                            new RazorCommentNodeFactory(),
                                                                            new RazorExpressionNodeFactory(),
                                                                            new ContentTagConverterConfiguration()));
            var convertedFiles = new List <string>();

            foreach (var file in filesToConvert)
            {
                var webFormsPageSource = File.ReadAllText(file, Encoding.UTF8);
                var webFormsDocument   = parser.Parse(webFormsPageSource);
                var razorDom           = converter.Convert(webFormsDocument);
                var razorPage          = renderer.Render(razorDom);
                var outputFileName     = Path.Combine(Path.GetDirectoryName(file), Path.GetFileNameWithoutExtension(file) + ".cshtml");
                File.WriteAllText(outputFileName, razorPage, Encoding.UTF8);
                convertedFiles.Add(outputFileName);
            }
            return(convertedFiles);
        }
        public static IEnumerable<string> ConvertFiles(IEnumerable<string> filesToConvert)
        {
            var parser = new WebFormsParser(new WebFormsNodeFactory(),
                                            new WebFormsNodeFilterProvider(new WebFormsCodeGroupFactory()));
            var renderer = new RazorViewRenderer(new RazorNodeRendererProvider());
            var converter =
                new WebFormsToRazorConverter(new RazorNodeConverterProvider(new RazorDirectiveNodeFactory(),
                                                                            new RazorSectionNodeFactory(),
                                                                            new RazorCodeNodeFactory(),
                                                                            new RazorTextNodeFactory(),
                                                                            new RazorCommentNodeFactory(),
                                                                            new RazorExpressionNodeFactory(),
                                                                            new ContentTagConverterConfiguration()));
            var convertedFiles = new List<string>();

            foreach (var file in filesToConvert)
            {
                var webFormsPageSource = File.ReadAllText(file, Encoding.UTF8);
                var webFormsDocument = parser.Parse(webFormsPageSource);
                var razorDom = converter.Convert(webFormsDocument);
                var razorPage = renderer.Render(razorDom);
                var outputFileName = Path.Combine(Path.GetDirectoryName(file), Path.GetFileNameWithoutExtension(file) + ".cshtml");
                File.WriteAllText(outputFileName, razorPage, Encoding.UTF8);
                convertedFiles.Add(outputFileName);
            }
            return convertedFiles;
        }
        public WebFormsToRazorConverterTests()
        {
            firstNodeConverter = new Mock<INodeConverter<IRazorNode>>();

            converterProviderMock = new Mock<IRazorNodeConverterProvider>();
            converterProviderMock.SetupGet(c => c.NodeConverters)
                .Returns(new INodeConverter<IRazorNode>[] { firstNodeConverter.Object });
            converter = new WebFormsToRazorConverter(converterProviderMock.Object);

            childNodeMock = new Mock<IWebFormsNode>();
            var rootNodeMock = new Mock<IWebFormsNode>();
            rootNodeMock.SetupGet(n => n.Children).Returns(new IWebFormsNode[] { childNodeMock.Object });
            documentMock = new Mock<IDocument<IWebFormsNode>>();
            documentMock.SetupGet(d => d.RootNode).Returns(rootNodeMock.Object);
        }
Exemple #4
0
        public WebFormsToRazorConverterTests()
        {
            firstNodeConverter = new Mock <INodeConverter <IRazorNode> >();

            converterProviderMock = new Mock <IRazorNodeConverterProvider>();
            converterProviderMock.SetupGet(c => c.NodeConverters)
            .Returns(new INodeConverter <IRazorNode>[] { firstNodeConverter.Object });
            converter = new WebFormsToRazorConverter(converterProviderMock.Object);

            childNodeMock = new Mock <IWebFormsNode>();
            var rootNodeMock = new Mock <IWebFormsNode>();

            rootNodeMock.SetupGet(n => n.Children).Returns(new IWebFormsNode[] { childNodeMock.Object });
            documentMock = new Mock <IDocument <IWebFormsNode> >();
            documentMock.SetupGet(d => d.RootNode).Returns(rootNodeMock.Object);
        }