Exemplo n.º 1
0
        public RazorViewEngineFixture()
        {
            var assemblyCatalog = new AppDomainAssemblyCatalog();

            var environment = new DefaultNancyEnvironment();
            environment.Tracing(
                enabled: true,
                displayErrorTraces: true);

            this.configuration = A.Fake<IRazorConfiguration>();
            this.engine = new RazorViewEngine(this.configuration, environment, assemblyCatalog);
            A.CallTo(() => this.configuration.GetAssemblyNames()).Returns(new[] { "Nancy.ViewEngines.Razor.Tests.Models" });

            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());
        }
        public NancyInternalConfigurationFixture()
        {
            IAssemblyCatalog assemblyCatalog;

#if !DNX
            assemblyCatalog = new AppDomainAssemblyCatalog();
#else
            assemblyCatalog = new LibraryManagerAssemblyCatalog();
#endif

            this.typeCatalog = new DefaultTypeCatalog(assemblyCatalog);
        }
        public NancyInternalConfigurationFixture()
        {
            IAssemblyCatalog assemblyCatalog;

#if !CORE
            assemblyCatalog = new AppDomainAssemblyCatalog();
#else
            assemblyCatalog = new DependencyContextAssemblyCatalog();
#endif

            this.typeCatalog = new DefaultTypeCatalog(assemblyCatalog);
        }
Exemplo n.º 4
0
        public NancyInternalConfigurationFixture()
        {
            IAssemblyCatalog assemblyCatalog;

#if !CORE
            assemblyCatalog = new AppDomainAssemblyCatalog();
#else
            assemblyCatalog = new DependencyContextAssemblyCatalog();
#endif

            this.typeCatalog = new DefaultTypeCatalog(assemblyCatalog);
        }
Exemplo n.º 5
0
        public NancyInternalConfigurationFixture()
        {
            IAssemblyCatalog assemblyCatalog;

#if !DNX
            assemblyCatalog = new AppDomainAssemblyCatalog();
#else
            assemblyCatalog = new LibraryManagerAssemblyCatalog();
#endif

            this.typeCatalog = new DefaultTypeCatalog(assemblyCatalog);
        }
Exemplo n.º 6
0
        public RazorViewEngineFixture()
        {
            IAssemblyCatalog assemblyCatalog;

#if !DNX
            assemblyCatalog = new AppDomainAssemblyCatalog();
#else
            assemblyCatalog = new LibraryManagerAssemblyCatalog();
#endif

            var environment = new DefaultNancyEnvironment();
            environment.Tracing(
                enabled: true,
                displayErrorTraces: true);

            this.configuration = A.Fake <IRazorConfiguration>();
            this.engine        = new RazorViewEngine(this.configuration, environment, assemblyCatalog);
            A.CallTo(() => this.configuration.GetAssemblyNames()).Returns(new[] { "Nancy.ViewEngines.Razor.Tests.Models" });

            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.º 7
0
        public void Modules_without_Nancy_references_should_not_keep_loaded_after_inspection()
        {
            // Given
            var compilerAppDomain = AppDomain.CreateDomain("AssemblyGenerator",
                                                           AppDomain.CurrentDomain.Evidence, AppDomain.CurrentDomain.SetupInformation);

            var assemblyGenerator = (ProxyAssemblyGenerator)compilerAppDomain.CreateInstanceAndUnwrap(
                typeof(ProxyAssemblyGenerator).Assembly.FullName,
                typeof(ProxyAssemblyGenerator).FullName);

            try
            {
                var generatedAssemblyName = assemblyGenerator.GenerateAssemblyAndGetName();

                var assemblyCatalog = new AppDomainAssemblyCatalog();

                // When

                // the following call will load the assemblies into its own inspection AppDomain
                // and release the assemblies that do not reference Nancy afterwards,
                // keeping the application AppDomain free of such assemblies, that is, the created
                // assembly should not be loaded by AppDomain.GetAssemblies after this call
                assemblyCatalog.GetAssemblies();

                var loadedAssembliesAfterInspection = AppDomain.CurrentDomain.GetAssemblies();

                // Then
                loadedAssembliesAfterInspection
                .Select(assembly => assembly.GetName().Name)
                .Contains(generatedAssemblyName.Name)
                .ShouldBeFalse();
            }
            finally
            {
                AppDomain.Unload(compilerAppDomain);
            }
        }