Ejemplo n.º 1
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());
        }
Ejemplo n.º 2
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");
        }
Ejemplo n.º 3
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());
        }
Ejemplo n.º 4
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");
        }
Ejemplo n.º 5
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());
        }
Ejemplo n.º 6
0
        private ViewLocationResult GetShadeViewLocation(string viewName)
        {
            A.CallTo(() => this.rootPathProvider.GetRootPath()).Returns(Path.Combine(Environment.CurrentDirectory, "ShadeViews"));
            this.fileSystemViewLocationProvider = new FileSystemViewLocationProvider(this.rootPathProvider, new DefaultFileSystemReader());
            var viewLocationResult = new ViewLocationResult("Features", viewName, "shade", GetEmptyContentReader());

            return(viewLocationResult);
        }
        public MarkdownViewEngineFixture()
        {
            this.renderContext = A.Fake <IRenderContext>();
            this.viewEngine    = new MarkDownViewEngine(new SuperSimpleViewEngine(Enumerable.Empty <ISuperSimpleViewEngineMatcher>()));

            this.rootPathProvider = A.Fake <IRootPathProvider>();

            A.CallTo(() => this.rootPathProvider.GetRootPath()).Returns(Path.Combine(Environment.CurrentDirectory, "Markdown"));

            this.fileSystemViewLocationProvider = new FileSystemViewLocationProvider(this.rootPathProvider, new DefaultFileSystemReader());
        }
Ejemplo n.º 8
0
        public MarkdownViewEngineFixture()
        {
            this.renderContext = A.Fake<IRenderContext>();
            this.viewEngine = new MarkDownViewEngine(new SuperSimpleViewEngine());

            this.rootPathProvider = A.Fake<IRootPathProvider>();

            A.CallTo(() => this.rootPathProvider.GetRootPath()).Returns(Path.Combine(Environment.CurrentDirectory, "Markdown"));

            this.fileSystemViewLocationProvider = new FileSystemViewLocationProvider(this.rootPathProvider, new DefaultFileSystemReader());
        }
Ejemplo n.º 9
0
        public void Should_return_empty_result_when_root_path_is_empty()
        {
            // Given
            var extensions = new[] { "html" };

            A.CallTo(() => this.rootPathProvider.GetRootPath()).Returns(string.Empty);
            this.provider = new FileSystemViewLocationProvider(this.rootPathProvider, this.reader);

            // When
            var result = this.provider.GetLocatedViews(extensions);

            // Then
            result.ShouldHaveCount(0);
        }
Ejemplo n.º 10
0
        public FileSystemViewLocationProviderFixture()
        {
            this.reader           = A.Fake <IFileSystemReader>();
            this.rootPathProvider = A.Fake <IRootPathProvider>();

            A.CallTo(() => this.rootPathProvider.GetRootPath()).Returns("rootPath");

            this.provider = new FileSystemViewLocationProvider(this.rootPathProvider, this.reader);

            this.locationResult = new Tuple <string, Func <StreamReader> >(
                Path.Combine("this", "is", "a", "fake", "view.html"),
                () => null);

            A.CallTo(() => this.reader.GetViewsWithSupportedExtensions(A <string> ._, A <IEnumerable <string> > ._)).Returns(new[] { this.locationResult });
        }
Ejemplo n.º 11
0
        public SparkViewEngineFixture()
        {
            this.rootPathProvider = A.Fake <IRootPathProvider>();
            A.CallTo(() => this.rootPathProvider.GetRootPath()).Returns(Path.Combine(Environment.CurrentDirectory, "TestViews"));

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

            this.renderContext = A.Fake <IRenderContext>();

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

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

            A.CallTo(() => this.renderContext.ViewCache).Returns(cache);
        }
 public NSembleViewLocationProvider(IRootPathProvider rootPathProvider, IFileSystemReader fileSystemReader, global::Nancy.TinyIoc.TinyIoCContainer container)
 {
     _documentStore                = container.Resolve <IDocumentStore>("DocStore");
     fsViewLocationProvider        = new FileSystemViewLocationProvider(rootPathProvider, fileSystemReader);
     resourcesViewLocationProvider = new ResourceViewLocationProvider(new NSembleResourceReader(), new NSembleResourceAssemblyProvider());
 }