コード例 #1
0
        protected override void beforeEach()
        {
            const string viewPath    = "/_Package1_/Handlers/Models/SerieSL.spark";
            var          appRoot     = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "Templates");
            var          packageRoot = Path.Combine(appRoot, "App", "fubu-packages", "Package1", "WebContent");

            var binding1       = new Template(Path.Combine(packageRoot, "Handlers", "Shared", "bindings.xml"), packageRoot, "Package1");
            var binding2       = new Template(Path.Combine(appRoot, "Shared", "bindings.xml"), appRoot, TemplateConstants.HostOrigin);
            var viewPathPolicy = new ViewPathPolicy <ITemplate>();

            viewPathPolicy.Apply(binding1);
            viewPathPolicy.Apply(binding2);

            _viewFolder = MockFor <IViewFolder>();
            _viewFolder.Expect(x => x.GetViewSource(binding1.ViewPath)).Return(new FileSystemViewFile(binding1.FilePath));
            _viewFolder.Expect(x => x.GetViewSource(binding2.ViewPath)).Return(new FileSystemViewFile(binding2.FilePath));

            _request = new BindingRequest(_viewFolder)
            {
                ViewPath = viewPath
            };

            _templateRegistry = MockFor <ISparkTemplateRegistry>();
            _templateRegistry.Expect(x => x.BindingsForView(viewPath)).Return(new[] { binding1, binding2 });
        }
コード例 #2
0
        public ExtendedTester()
        {
            var testRoot = Path.Combine(Directory.GetCurrentDirectory(), "Templates");

            var pathApp      = Path.Combine(testRoot, "App");
            var pathPackage1 = Path.Combine(pathApp, "fubu-packages", "Package1", "WebContent");
            var pathPackage2 = Path.Combine(testRoot, "Package2");

            var allTemplates = new TemplateRegistry <IRazorTemplate>();

            var razorSettings = new RazorEngineSettings();
            var razorSet      = razorSettings.Search;

            new ContentFolder(TemplateConstants.HostOrigin, pathApp).FindFiles(razorSet)
            .Union(new ContentFolder("Package1", pathPackage1).FindFiles(razorSet)
                   .Union(new ContentFolder("Package2", pathPackage2).FindFiles(razorSet)))
            .Each(x =>
            {
                if (x.Provenance == TemplateConstants.HostOrigin && x.Path.StartsWith(pathPackage1))
                {
                    return;
                }
                allTemplates.Register(new Template(x.Path, x.ProvenancePath, x.Provenance));
            });

            var viewPathPolicy = new ViewPathPolicy <IRazorTemplate>();

            allTemplates.Each(x =>
            {
                viewPathPolicy.Apply(x);
                x.Descriptor = new ViewDescriptor <IRazorTemplate>(x);
            });

            var commonNamespaces = new CommonViewNamespaces();

            commonNamespaces.AddForType <string>();
            _templateFactory = new TemplateFactoryCache(commonNamespaces, razorSettings, new TemplateCompiler(), new RazorTemplateGenerator());

            _pak1TemplateRegistry = new TemplateRegistry <IRazorTemplate>(allTemplates.ByOrigin(Package1));
            _pak2TemplateRegistry = new TemplateRegistry <IRazorTemplate>(allTemplates.ByOrigin(Package2));
            _appTemplateRegistry  = new TemplateRegistry <IRazorTemplate>(allTemplates.FromHost());

            _serviceLocator = MockRepository.GenerateMock <IServiceLocator>();

            var sharingGraph = new SharingGraph();

            sharingGraph.Dependency("Package1", ContentFolder.Application);
            sharingGraph.Dependency("Package2", ContentFolder.Application);
            var templateDirectory = new TemplateDirectoryProvider <IRazorTemplate>(new SharedPathBuilder(), allTemplates,
                                                                                   sharingGraph);

            _sharedTemplateLocator = new SharedTemplateLocator <IRazorTemplate>(templateDirectory, allTemplates,
                                                                                new RazorTemplateSelector());

            var partialRenderer = new PartialRenderer(_sharedTemplateLocator, _templateFactory);

            _serviceLocator.Expect(x => x.GetInstance(Arg.Is(typeof(IPartialRenderer)))).Return(partialRenderer);
            _serviceLocator.Expect(x => x.GetInstance(typeof(IOutputWriter))).Return(MockRepository.GenerateMock <IOutputWriter>());
        }
コード例 #3
0
        public ExtendedTester()
        {
            var testRoot = Path.Combine(Directory.GetCurrentDirectory(), "Templates");

            var pathApp = Path.Combine(testRoot, "App");
            var pathPackage1 = Path.Combine(pathApp, "fubu-packages", "Package1", "WebContent");
            var pathPackage2 = Path.Combine(testRoot, "Package2");

            var allTemplates = new TemplateRegistry<IRazorTemplate>();

            var razorSettings = new RazorEngineSettings();
            var razorSet = razorSettings.Search;

            new ContentFolder(TemplateConstants.HostOrigin, pathApp).FindFiles(razorSet)
                .Union(new ContentFolder("Package1", pathPackage1).FindFiles(razorSet)
                .Union(new ContentFolder("Package2", pathPackage2).FindFiles(razorSet)))
                .Each(x =>
                {
                    if (x.Provenance == TemplateConstants.HostOrigin && x.Path.StartsWith(pathPackage1)) return;
                    allTemplates.Register(new Template(x.Path, x.ProvenancePath, x.Provenance));
                });

            var viewPathPolicy = new ViewPathPolicy<IRazorTemplate>();
            allTemplates.Each(x =>
            {
                viewPathPolicy.Apply(x);
                x.Descriptor = new ViewDescriptor<IRazorTemplate>(x);
            });

            var commonNamespaces = new CommonViewNamespaces();
            commonNamespaces.AddForType<string>();
            _templateFactory = new TemplateFactoryCache(commonNamespaces, razorSettings, new TemplateCompiler(), new RazorTemplateGenerator());

            _pak1TemplateRegistry = new TemplateRegistry<IRazorTemplate>(allTemplates.ByOrigin(Package1));
            _pak2TemplateRegistry = new TemplateRegistry<IRazorTemplate>(allTemplates.ByOrigin(Package2));
            _appTemplateRegistry = new TemplateRegistry<IRazorTemplate>(allTemplates.FromHost());

            _serviceLocator = MockRepository.GenerateMock<IServiceLocator>();

            var sharingGraph = new SharingGraph();
            sharingGraph.Dependency("Package1", ContentFolder.Application);
            sharingGraph.Dependency("Package2", ContentFolder.Application);
            var templateDirectory = new TemplateDirectoryProvider<IRazorTemplate>(new SharedPathBuilder(), allTemplates,
                                                                                  sharingGraph);
            _sharedTemplateLocator = new SharedTemplateLocator<IRazorTemplate>(templateDirectory, allTemplates,
                                                                               new RazorTemplateSelector());

            var partialRenderer = new PartialRenderer(_sharedTemplateLocator, _templateFactory);
            _serviceLocator.Expect(x => x.GetInstance(Arg.Is(typeof (IPartialRenderer)))).Return(partialRenderer);
            _serviceLocator.Expect(x => x.GetInstance(typeof (IOutputWriter))).Return(MockRepository.GenerateMock<IOutputWriter>());
        }