Exemplo n.º 1
0
        public RazorViewEngineFixture()
        {
            StaticConfiguration.DisableErrorTraces = false;
            this.configuration = A.Fake <IRazorConfiguration>();
            this.engine        = new RazorViewEngine(this.configuration);

            var cache = A.Fake <IViewCache>();

            A.CallTo(() => cache.GetOrAdd(A <ViewLocationResult> .Ignored, A <Func <ViewLocationResult, Func <INancyRazorView> > > .Ignored))
            .ReturnsLazily(x =>
            {
                var result = x.GetArgument <ViewLocationResult>(0);
                return(x.GetArgument <Func <ViewLocationResult, Func <INancyRazorView> > >(1).Invoke(result));
            });

            this.renderContext = A.Fake <IRenderContext>();
            A.CallTo(() => this.renderContext.ViewCache).Returns(cache);
            A.CallTo(() => this.renderContext.LocateView(A <string> .Ignored, A <object> .Ignored))
            .ReturnsLazily(x =>
            {
                var viewName = x.GetArgument <string>(0);
                return(FindView(viewName));
            });

            this.rootPathProvider = A.Fake <IRootPathProvider>();
            A.CallTo(() => this.rootPathProvider.GetRootPath()).Returns(Path.Combine(Environment.CurrentDirectory, "TestViews"));

            this.fileSystemViewLocationProvider = new FileSystemViewLocationProvider(this.rootPathProvider, new DefaultFileSystemReader());

            AppDomainAssemblyTypeScanner.AddAssembliesToScan("Nancy.ViewEngines.Razor.Tests.Models.dll");
        }
Exemplo n.º 2
0
        public RazorViewEngineFixture()
        {
            var environment = new DefaultNancyEnvironment();
            environment.Tracing(
                enabled: true,
                displayErrorTraces: true);

            this.configuration = A.Fake<IRazorConfiguration>();
            this.engine = new RazorViewEngine(this.configuration, environment);

            var cache = A.Fake<IViewCache>();
            A.CallTo(() => cache.GetOrAdd(A<ViewLocationResult>.Ignored, A<Func<ViewLocationResult, Func<INancyRazorView>>>.Ignored))
                .ReturnsLazily(x =>
                {
                    var result = x.GetArgument<ViewLocationResult>(0);
                    return x.GetArgument<Func<ViewLocationResult, Func<INancyRazorView>>>(1).Invoke(result);
                });

            this.renderContext = A.Fake<IRenderContext>();
            A.CallTo(() => this.renderContext.ViewCache).Returns(cache);
            A.CallTo(() => this.renderContext.LocateView(A<string>.Ignored, A<object>.Ignored))
                .ReturnsLazily(x =>
                {
                    var viewName = x.GetArgument<string>(0);
                    return FindView(viewName);
                });

            this.rootPathProvider = A.Fake<IRootPathProvider>();
            A.CallTo(() => this.rootPathProvider.GetRootPath()).Returns(Path.Combine(Environment.CurrentDirectory, "TestViews"));

            this.fileSystemViewLocationProvider = new FileSystemViewLocationProvider(this.rootPathProvider, new DefaultFileSystemReader());

            AppDomainAssemblyTypeScanner.AddAssembliesToScan("Nancy.ViewEngines.Razor.Tests.Models.dll");
        }
Exemplo n.º 3
0
        public RazorViewEngineFixture()
        {
            var environment = new DefaultNancyEnvironment();

            environment.Tracing(
                enabled: true,
                displayErrorTraces: true);

            this.configuration = A.Fake <IRazorConfiguration>();
            this.engine        = new RazorViewEngine(this.configuration, environment, new AppDomainAssemblyCatalog());

            var cache = A.Fake <IViewCache>();

            A.CallTo(() => cache.GetOrAdd(A <ViewLocationResult> .Ignored, A <Func <ViewLocationResult, Func <INancyRazorView> > > .Ignored))
            .ReturnsLazily(x =>
            {
                var result = x.GetArgument <ViewLocationResult>(0);
                return(x.GetArgument <Func <ViewLocationResult, Func <INancyRazorView> > >(1).Invoke(result));
            });

            this.renderContext = A.Fake <IRenderContext>();
            A.CallTo(() => this.renderContext.ViewCache).Returns(cache);
            A.CallTo(() => this.renderContext.LocateView(A <string> .Ignored, A <object> .Ignored))
            .ReturnsLazily(x =>
            {
                var viewName = x.GetArgument <string>(0);
                return(FindView(viewName));
            });

            this.rootPathProvider = A.Fake <IRootPathProvider>();
            A.CallTo(() => this.rootPathProvider.GetRootPath()).Returns(Path.Combine(Environment.CurrentDirectory, "TestViews"));

            this.fileSystemViewLocationProvider = new FileSystemViewLocationProvider(this.rootPathProvider, new DefaultFileSystemReader());
        }
Exemplo n.º 4
0
        public RazorViewEngineFixture()
        {
            this.configuration = A.Fake<IRazorConfiguration>();
            this.engine = new RazorViewEngine(this.configuration);

            var cache = A.Fake<IViewCache>();
            A.CallTo(() => cache.GetOrAdd(A<ViewLocationResult>.Ignored, A<Func<ViewLocationResult, Func<NancyRazorViewBase>>>.Ignored))
                .ReturnsLazily(x =>
                {
                    var result = x.GetArgument<ViewLocationResult>(0);
                    return x.GetArgument<Func<ViewLocationResult, Func<NancyRazorViewBase>>>(1).Invoke(result);
                });

            this.renderContext = A.Fake<IRenderContext>();
            A.CallTo(() => this.renderContext.ViewCache).Returns(cache);
            A.CallTo(() => this.renderContext.LocateView(A<string>.Ignored, A<object>.Ignored))
                .ReturnsLazily(x =>
                {
                    var viewName = x.GetArgument<string>(0);
                    return FindView(viewName); ;
                });

            this.rootPathProvider = A.Fake<IRootPathProvider>();
            A.CallTo(() => this.rootPathProvider.GetRootPath()).Returns(Path.Combine(Environment.CurrentDirectory, "TestViews"));

            this.fileSystemViewLocationProvider = new FileSystemViewLocationProvider(this.rootPathProvider, new DefaultFileSystemReader());
        }
Exemplo n.º 5
0
        public RazorViewEngineFixture()
        {
            this.configuration = A.Fake <IRazorConfiguration>();
            this.textResource  = A.Fake <ITextResource>();
            this.engine        = new RazorViewEngine(this.configuration, this.textResource);

            var cache = A.Fake <IViewCache>();

            A.CallTo(() => cache.GetOrAdd(A <ViewLocationResult> .Ignored, A <Func <ViewLocationResult, Func <NancyRazorViewBase> > > .Ignored))
            .ReturnsLazily(x =>
            {
                var result = x.GetArgument <ViewLocationResult>(0);
                return(x.GetArgument <Func <ViewLocationResult, Func <NancyRazorViewBase> > >(1).Invoke(result));
            });

            this.renderContext = A.Fake <IRenderContext>();
            A.CallTo(() => this.renderContext.ViewCache).Returns(cache);
            A.CallTo(() => this.renderContext.LocateView(A <string> .Ignored, A <object> .Ignored))
            .ReturnsLazily(x =>
            {
                var viewName = x.GetArgument <string>(0);
                return(FindView(viewName));;
            });

            this.rootPathProvider = A.Fake <IRootPathProvider>();
            A.CallTo(() => this.rootPathProvider.GetRootPath()).Returns(Path.Combine(Environment.CurrentDirectory, "TestViews"));

            this.fileSystemViewLocationProvider = new FileSystemViewLocationProvider(this.rootPathProvider, new DefaultFileSystemReader());
        }
Exemplo n.º 6
0
 /// <summary>
 /// Initializes a new instance of the <see cref="RazorViewEngine"/> class.
 /// </summary>
 /// <param name="configuration">The <see cref="IRazorConfiguration"/> that should be used by the engine.</param>
 /// <param name="environment">An <see cref="INancyEnvironment"/> instance.</param>
 /// <param name="assemblyCatalog">An <see cref="IAssemblyCatalog"/> instance.</param>
 public RazorViewEngine(IRazorConfiguration configuration, INancyEnvironment environment, IAssemblyCatalog assemblyCatalog)
 {
     this.razorAssemblyProvider = new RazorAssemblyProvider(configuration, assemblyCatalog);
     this.viewRenderer = new CSharpRazorViewRenderer(this.razorAssemblyProvider);
     this.razorConfiguration = configuration;
     this.traceConfiguration = environment.GetValue<TraceConfiguration>();
     this.AddDefaultNameSpaces(this.viewRenderer.Host);
 }
Exemplo n.º 7
0
 /// <summary>
 /// Initializes a new instance of the <see cref="RazorViewEngine"/> class.
 /// </summary>
 /// <param name="configuration">The <see cref="IRazorConfiguration"/> that should be used by the engine.</param>
 /// <param name="environment">An <see cref="INancyEnvironment"/> instance.</param>
 /// <param name="assemblyCatalog">An <see cref="IAssemblyCatalog"/> instance.</param>
 public RazorViewEngine(IRazorConfiguration configuration, INancyEnvironment environment, IAssemblyCatalog assemblyCatalog)
 {
     this.razorAssemblyProvider = new RazorAssemblyProvider(configuration, assemblyCatalog);
     this.viewRenderer          = new CSharpRazorViewRenderer(this.razorAssemblyProvider);
     this.razorConfiguration    = configuration;
     this.traceConfiguration    = environment.GetValue <TraceConfiguration>();
     this.AddDefaultNameSpaces(this.viewRenderer.Host);
 }
Exemplo n.º 8
0
        /// <summary>
        /// Initializes a new instance of the <see cref="RazorViewEngine"/> class.
        /// </summary>
        /// <param name="configuration">The <see cref="IRazorConfiguration"/> that should be used by the engine.</param>
        public RazorViewEngine(IRazorConfiguration configuration)
        {
            this.viewRenderers = new List<IRazorViewRenderer>
            {
                new CSharp.CSharpRazorViewRenderer(),
                new VisualBasic.VisualBasicRazorViewRenderer()
            };

            this.razorConfiguration = configuration;
        }
Exemplo n.º 9
0
        /// <summary>
        /// Initializes a new instance of the <see cref="RazorViewEngine"/> class.
        /// </summary>
        /// <param name="configuration">The <see cref="IRazorConfiguration"/> that should be used by the engine.</param>
        public RazorViewEngine(IRazorConfiguration configuration)
        {
            this.viewRenderers = new List <IRazorViewRenderer>
            {
                new CSharp.CSharpRazorViewRenderer(),
                new VisualBasic.VisualBasicRazorViewRenderer()
            };

            this.razorConfiguration = configuration;
        }
Exemplo n.º 10
0
        /// <summary>
        /// Initializes a new instance of the <see cref="RazorViewEngine"/> class.
        /// </summary>
        /// <param name="configuration">The <see cref="IRazorConfiguration"/> that should be used by the engine.</param>
        /// <param name="textResource">The <see cref="ITextResource"/> that should be used by the engine.</param>
        public RazorViewEngine(IRazorConfiguration configuration, ITextResource textResource)
        {
            this.viewRenderers = new List<IRazorViewRenderer>
            {
                new CSharp.CSharpRazorViewRenderer(),
                new VisualBasic.VisualBasicRazorViewRenderer()
            };

            this.razorConfiguration = configuration;
            this.textResource = textResource;
        }
Exemplo n.º 11
0
        public RazorViewCompiler(IFileSystem fileSystem, IRazorConfiguration razorConfiguration)
        {
            this.fileSystem          = fileSystem;
            this.razorConfiguration  = razorConfiguration;
            this.razorTemplateEngine = BuildRazorTemplateEngine(RazorProjectFileSystem.Create(this.fileSystem.GetFullPath("~/")));
            var defaultTagHelpers            = razorConfiguration.GetDefaultTagHelpers();
            var defaultDirectivesProjectItem = new DefaultDirectivesProjectItem(this.razorConfiguration.GetDefaultNamespaces(), defaultTagHelpers);

            this.defaultImports = new[] { RazorSourceDocument.ReadFrom(defaultDirectivesProjectItem) };
            this.GetReferenceAssemblies();
        }
Exemplo n.º 12
0
        /// <summary>
        /// Initializes a new instance of the <see cref="RazorViewEngine"/> class.
        /// </summary>
        /// <param name="configuration">The <see cref="IRazorConfiguration"/> that should be used by the engine.</param>
        /// <param name="textResource">The <see cref="ITextResource"/> that should be used by the engine.</param>
        public RazorViewEngine(IRazorConfiguration configuration, ITextResource textResource)
        {
            this.viewRenderers = new List <IRazorViewRenderer>
            {
                new CSharp.CSharpRazorViewRenderer(),
                new VisualBasic.VisualBasicRazorViewRenderer()
            };

            this.razorConfiguration = configuration;
            this.textResource       = textResource;
        }
Exemplo n.º 13
0
        /// <summary>
        /// Initializes a new instance of the <see cref="RazorViewEngine"/> class.
        /// </summary>
        /// <param name="configuration">The <see cref="IRazorConfiguration"/> that should be used by the engine.</param>
        public RazorViewEngine(IRazorConfiguration configuration)
        {
            this.viewRenderers = new List<IRazorViewRenderer>
            {
                new CSharp.CSharpRazorViewRenderer(),
                new VisualBasic.VisualBasicRazorViewRenderer()
            };

            this.razorConfiguration = configuration;

            foreach (var renderer in this.viewRenderers)
            {
                this.AddDefaultNameSpaces(renderer.Host);
            }
        }
Exemplo n.º 14
0
        /// <summary>
        /// Initializes a new instance of the <see cref="RazorViewEngine"/> class.
        /// </summary>
        /// <param name="configuration">The <see cref="IRazorConfiguration"/> that should be used by the engine.</param>
        public RazorViewEngine(IRazorConfiguration configuration)
        {
            this.viewRenderers = new List <IRazorViewRenderer>
            {
                new CSharp.CSharpRazorViewRenderer(),
                new VisualBasic.VisualBasicRazorViewRenderer()
            };

            this.razorConfiguration = configuration;

            foreach (var renderer in this.viewRenderers)
            {
                this.AddDefaultNameSpaces(renderer.Host);
            }
        }
Exemplo n.º 15
0
        public RazorViewCompilerFixture()
        {
            this.configuration = A.Fake<IRazorConfiguration>();
            this.engine = new RazorViewEngine(this.configuration);

            var cache = A.Fake<IViewCache>();
            A.CallTo(() => cache.GetOrAdd(A<ViewLocationResult>.Ignored, A<Func<ViewLocationResult, Func<NancyRazorViewBase>>>.Ignored))
                .ReturnsLazily(x =>
                {
                    var result = x.GetArgument<ViewLocationResult>(0);
                    return x.GetArgument<Func<ViewLocationResult, Func<NancyRazorViewBase>>>(1).Invoke(result);
                });

            this.renderContext = A.Fake<IRenderContext>();
            A.CallTo(() => this.renderContext.ViewCache).Returns(cache);
        }
Exemplo n.º 16
0
        /// <summary>
        /// Initializes a new instance of the <see cref="RazorViewEngine"/> class.
        /// </summary>
        /// <param name="configuration">The <see cref="IRazorConfiguration"/> that should be used by the engine.</param>
        /// <param name="environment">An <see cref="INancyEnvironment"/> instance.</param>
        public RazorViewEngine(IRazorConfiguration configuration, INancyEnvironment environment)
        {
            this.viewRenderers = new List<IRazorViewRenderer>
            {
                new CSharpRazorViewRenderer(),
                new VisualBasicRazorViewRenderer()
            };

            this.razorConfiguration = configuration;
            this.traceConfiguration = environment.GetValue<TraceConfiguration>();

            foreach (var renderer in this.viewRenderers)
            {
                this.AddDefaultNameSpaces(renderer.Host);
            }
        }
Exemplo n.º 17
0
        /// <summary>
        /// Initializes a new instance of the <see cref="RazorViewEngine"/> class.
        /// </summary>
        /// <param name="configuration">The <see cref="IRazorConfiguration"/> that should be used by the engine.</param>
        /// <param name="environment">An <see cref="INancyEnvironment"/> instance.</param>
        /// <param name="assemblyCatalog">An <see cref="IAssemblyCatalog"/> instance.</param>
        public RazorViewEngine(IRazorConfiguration configuration, INancyEnvironment environment, IAssemblyCatalog assemblyCatalog)
        {
            this.viewRenderers = new List <IRazorViewRenderer>
            {
                new CSharpRazorViewRenderer(assemblyCatalog),
                new VisualBasicRazorViewRenderer(assemblyCatalog)
            };

            this.razorConfiguration = configuration;
            this.assemblyCatalog    = assemblyCatalog;
            this.traceConfiguration = environment.GetValue <TraceConfiguration>();

            foreach (var renderer in this.viewRenderers)
            {
                this.AddDefaultNameSpaces(renderer.Host);
            }
        }
Exemplo n.º 18
0
        public RazorViewCompilerFixture()
        {
            this.configuration = A.Fake <IRazorConfiguration>();
            this.engine        = new RazorViewEngine(this.configuration);

            var cache = A.Fake <IViewCache>();

            A.CallTo(() => cache.GetOrAdd(A <ViewLocationResult> .Ignored, A <Func <ViewLocationResult, Func <NancyRazorViewBase> > > .Ignored))
            .ReturnsLazily(x =>
            {
                var result = x.GetArgument <ViewLocationResult>(0);
                return(x.GetArgument <Func <ViewLocationResult, Func <NancyRazorViewBase> > >(1).Invoke(result));
            });

            this.renderContext = A.Fake <IRenderContext>();
            A.CallTo(() => this.renderContext.ViewCache).Returns(cache);
        }
Exemplo n.º 19
0
 /// <summary>
 /// Initializes a new instance of the <see cref="RazorAssemblyProvider"/> class.
 /// </summary>
 /// <param name="configuration">An <see cref="IRazorConfiguration"/> instance.</param>
 /// <param name="assemblyCatalog">An <see cref="IAssemblyCatalog"/> instance.</param>
 public RazorAssemblyProvider(IRazorConfiguration configuration, IAssemblyCatalog assemblyCatalog)
 {
     this.configuration = configuration;
     this.assemblyCatalog = assemblyCatalog;
     this.assemblies = new Lazy<IReadOnlyCollection<Assembly>>(this.GetAllAssemblies);
 }
Exemplo n.º 20
0
 public AssetEnrichedRazorViewCompiler(IJavascriptPreprocessor jsPreprocessor, IEnumerable <ICssPreprocessor> cssPreprocessors, IFileSystem fileSystem, IAssetLoader assetLoader, IRazorConfiguration razorConfiguration) : base(fileSystem, razorConfiguration)
 {
     this.jsPreprocessor   = jsPreprocessor;
     this.cssPreprocessors = cssPreprocessors;
     this.assetLoader      = assetLoader;
 }
Exemplo n.º 21
0
 /// <summary>
 /// Initializes a new instance of the <see cref="RazorAssemblyProvider"/> class.
 /// </summary>
 /// <param name="configuration">An <see cref="IRazorConfiguration"/> instance.</param>
 /// <param name="assemblyCatalog">An <see cref="IAssemblyCatalog"/> instance.</param>
 public RazorAssemblyProvider(IRazorConfiguration configuration, IAssemblyCatalog assemblyCatalog)
 {
     this.configuration   = configuration;
     this.assemblyCatalog = assemblyCatalog;
     this.assemblies      = new Lazy <IReadOnlyCollection <Assembly> >(this.GetAllAssemblies);
 }
 public AssetEnrichedRazorViewCompiler(IRazorConfiguration razorConfiguration, IJavascriptCompressor jsCompressor, ICssPreprocessor cssPreprocessor, IFileSystem fileSystem, IAssetLoader assetLoader) : base(razorConfiguration, fileSystem)
 {
     this.jsCompressor    = jsCompressor;
     this.cssPreprocessor = cssPreprocessor;
     this.assetLoader     = assetLoader;
 }
Exemplo n.º 23
0
 /// <summary>
 /// Initializes a new instance of the <see cref="RazorViewEngine"/> class.
 /// </summary>
 /// <param name="configuration"></param>
 public RazorViewEngine(IRazorConfiguration configuration)
 {
     this.razorConfiguration = configuration;
     this.engine             = this.GetRazorTemplateEngine();
     this.codeDomProvider    = new CSharpCodeProvider();
 }
Exemplo n.º 24
0
 public RazorViewCompiler(IRazorConfiguration razorConfiguration, IFileSystem fileSystem)
 {
     this.razorConfiguration = razorConfiguration;
     this.fileSystem         = fileSystem;
 }