Esempio n. 1
0
        public void RenderView_csharp_should_be_able_to_use_a_using_statement()
        {
            AppDomainAssemblyTypeScanner.AddAssembliesToScan("Nancy.ViewEngines.Razor.Tests.Models");

            // Given
            var view = new StringBuilder()
                .AppendLine("@model Nancy.ViewEngines.Razor.Tests.Models.Person")
                .AppendLine("@using Nancy.ViewEngines.Razor.Tests.Models")
                .AppendLine(@"@{ var hobby = new Hobby { Name = ""Music"" }; }")
                .Append("<h1>Mr. @Model.Name likes @hobby.Name!</h1>");

            var location = new ViewLocationResult(
                string.Empty,
                string.Empty,
                "cshtml",
                () => new StringReader(view.ToString())
            );

            var stream = new MemoryStream();

            var model = new Person { Name = "Jeff" };

            // When
            var response = this.engine.RenderView(location, model, this.renderContext);
            response.Contents.Invoke(stream);

            // Then
            stream.ShouldEqual("<h1>Mr. Jeff likes Music!</h1>", true);
        }
Esempio 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");
        }
Esempio n. 3
0
        public void RenderView_csharp_should_be_able_to_use_a_model_from_another_assembly()
        {
            AppDomainAssemblyTypeScanner.AddAssembliesToScan("Nancy.ViewEngines.Razor.Tests.Models.dll");

            // Given
            var view = new StringBuilder()
                .AppendLine("@model Nancy.ViewEngines.Razor.Tests.Models.Person")
                .Append("<h1>Hello Mr. @Model.Name</h1>");

            var location = new ViewLocationResult(
                string.Empty,
                string.Empty,
                "cshtml",
                () => new StringReader(view.ToString())
            );

            var stream = new MemoryStream();

            var model = new Person { Name = "Jeff" };

            // When
            var response = this.engine.RenderView(location, model, this.renderContext);
            response.Contents.Invoke(stream);

            // Then
            stream.ShouldEqual("<h1>Hello Mr. Jeff</h1>");
        }
Esempio n. 4
0
 public CassetteNancyPluginRegistrations()
 {
     AppDomainAssemblyTypeScanner.AddAssembliesToScan(new string[] {
         "Cassette.CoffeeScript.dll"
         , "Cassette.Hogan.dll"
         , "Cassette.JQueryTmpl.dll"
         , "Cassette.KnockoutJQueryTmpl.dll"
         , "Cassette.Less.dll"
         , "Cassette.Sass.dll"
     });
 }
Esempio n. 5
0
        private void ConfigureNamespaces(IEnumerable <PluginConfiguration> plugins)
        {
            foreach (var plugin in plugins)
            {
                ResourceViewLocationProvider.RootNamespaces.Add(plugin.GetType().Assembly, plugin.ViewLocation);
            }

            ResourceViewLocationProvider.RootNamespaces.Add(typeof(KolaNancyBootstrapper).Assembly, "Kola.Nancy");
            ResourceViewLocationProvider.Ignore.Add(typeof(RazorViewEngine).Assembly);
            ResourceViewLocationProvider.Ignore.Add(Assembly.Load("System.Web, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a"));
            AppDomainAssemblyTypeScanner.AddAssembliesToScan(AppDomainAssemblyTypeScanner.DefaultAssembliesToScan.ToArray());
        }
Esempio n. 6
0
        // public void Load()
        void RecursivelyLoad(string path)
        {
            // 20150826
            // if (!Directory.Exists(_path)) return;
            if (!Directory.Exists(path))
            {
                return;
            }
            try {
                // 20150826
                // var dir = new DirectoryInfo(_path);
                var dir = new DirectoryInfo(path);
                // var files = dir.GetFiles(@"Nancy.ViewEngines*.dll");
                var files = dir.GetFiles(_fileNameTemplate);
                // 20150317
                // if (null == files || !files.Any()) return;
                if (!files.Any())
                {
                    return;
                }
                foreach (var probablyAssembly in files)
                {
                    try {
                        var assembly = Assembly.LoadFrom(probablyAssembly.FullName);
                        AppDomainAssemblyTypeScanner.AddAssembliesToScan(assembly.FullName);
                    }
                    catch {}
                }

                // 20150617
                if (_recurse)
                {
                    var subDirs = dir.GetDirectories();
                    // if (!subDirs.Any()) return;
                    if (subDirs.Any())
                    {
                        foreach (var subDir in subDirs)
                        {
                            RecursivelyLoad(subDir.FullName);
                        }
                    }
                }

                // AppDomainAssemblyTypeScanner.UpdateTypes();
            }
            catch {}
        }
Esempio n. 7
0
 public GlimpseRegistrations()
 {
     AppDomainAssemblyTypeScanner.AddAssembliesToScan(typeof(Glimpse.Core.Tab.Timeline).Assembly);
 }
Esempio n. 8
0
        // The bootstrapper enables you to reconfigure the composition of the framework,
        // by overriding the various methods and properties.
        // For more information https://github.com/NancyFx/Nancy/wiki/Bootstrapper

        public Bootstrapper()
        {
            AppDomainAssemblyTypeScanner.AddAssembliesToScan("photoCore.dll");
        }