public void ContainterCreatesDefaultServices() { var container = new SparkServiceContainer(); var langauageFactory = container.GetService<ISparkLanguageFactory>(); Assert.IsInstanceOfType(typeof(DefaultLanguageFactory), langauageFactory); var resourcePathManager = container.GetService<IResourcePathManager>(); Assert.IsInstanceOfType(typeof(DefaultResourcePathManager), resourcePathManager); }
public void EmptyMasterPreventsDefaultLayout() { var settings = new SparkSettings() .SetPageBaseType(typeof(StubSparkView)); var container = new SparkServiceContainer(settings); var viewFolder = new InMemoryViewFolder { { "Home\\Index.spark", "<use master=\"\"/><p>Hello world</p><content:title>bar</content:title>" }, { "Layouts\\Application.spark", "<h1>alpha</h1><use:view/><p>beta</p>" } }; container.SetServiceBuilder <IViewFolder>(c => viewFolder); var engine = container.GetService <ISparkViewEngine>(); var descriptor = new SparkViewDescriptor() .AddTemplate("Home\\Index.spark") .AddTemplate("Layouts\\Application.spark"); var view = engine.CreateInstance(descriptor); var contents = view.RenderView(); engine.ReleaseInstance(view); Assert.AreEqual("<p>Hello world</p>", contents); }
public void ConfigSettingsUsedByDefault() { var container = new SparkServiceContainer(); var settings = container.GetService<ISparkViewEngine>().Settings; Assert.AreSame(ConfigurationManager.GetSection("spark"), settings); }
public void ContainerCreatesDefaultServices() { var container = new SparkServiceContainer(); var langauageFactory = container.GetService <ISparkLanguageFactory>(); Assert.IsInstanceOf(typeof(DefaultLanguageFactory), langauageFactory); var resourcePathManager = container.GetService <IResourcePathManager>(); Assert.IsInstanceOf(typeof(DefaultResourcePathManager), resourcePathManager); var bindingProvider = container.GetService <IBindingProvider>(); Assert.IsInstanceOf(typeof(DefaultBindingProvider), bindingProvider); }
public void SettingsServiceReplacesType() { var container = new SparkServiceContainer(); container.SetService <ISparkExtensionFactory>(new StubExtensionFactory()); Assert.IsInstanceOf(typeof(StubExtensionFactory), container.GetService <ISparkExtensionFactory>()); }
public void ContainerCreatesDefaultServices() { var container = new SparkServiceContainer(); var langauageFactory = container.GetService<ISparkLanguageFactory>(); Assert.IsInstanceOf(typeof(DefaultLanguageFactory), langauageFactory); var resourcePathManager = container.GetService<IResourcePathManager>(); Assert.IsInstanceOf(typeof(DefaultResourcePathManager), resourcePathManager); var bindingProvider = container.GetService<IBindingProvider>(); Assert.IsInstanceOf(typeof(DefaultBindingProvider), bindingProvider); var partialProvider = container.GetService<IPartialProvider>(); Assert.IsInstanceOf(typeof(DefaultPartialProvider), partialProvider); }
public void AddingServiceBuilderCallsInitialize() { var container = new SparkServiceContainer(); container.SetServiceBuilder(typeof(ITestService), c => new TestService()); var service = container.GetService<ITestService>(); Assert.IsInstanceOfType(typeof(TestService), service); Assert.IsTrue(((TestService)service).Initialized); }
public void ConfigSettingsUsedByDefault() { var container = new SparkServiceContainer(); var settings = container.GetService <ISparkViewEngine>().Settings; Assert.AreSame(ConfigurationManager.GetSection("spark"), settings); }
public void AddingServiceInstanceCallsInitialize() { var container = new SparkServiceContainer(); var service = new TestService(); Assert.IsFalse(service.Initialized); container.SetService<ITestService>(service); Assert.IsTrue(service.Initialized); Assert.AreSame(service, container.GetService<ITestService>()); }
public void CreatedSettingsUsedWhenProvided() { var settings = new SparkSettings().SetPrefix("foo"); var container = new SparkServiceContainer(settings); var settings2 = container.GetService <ISparkViewEngine>().Settings; Assert.AreSame(settings, settings2); }
public void AddingServiceBuilderCallsInitialize() { var container = new SparkServiceContainer(); container.SetServiceBuilder(typeof(ITestService), c => new TestService()); var service = container.GetService <ITestService>(); Assert.IsInstanceOf(typeof(TestService), service); Assert.IsTrue(((TestService)service).Initialized); }
public void AddingServiceInstanceCallsInitialize() { var container = new SparkServiceContainer(); var service = new TestService(); Assert.IsFalse(service.Initialized); container.SetService <ITestService>(service); Assert.IsTrue(service.Initialized); Assert.AreSame(service, container.GetService <ITestService>()); }
public void Init() { var settings = new SparkSettings() .SetPageBaseType(typeof(StubSparkView)); var container = new SparkServiceContainer(settings); _viewFolder = new InMemoryViewFolder(); container.SetServiceBuilder <IViewFolder>(c => _viewFolder); _engine = container.GetService <ISparkViewEngine>(); }
private static HtmlResponse GetViewResponse <T>(byte[] viewTemplate, IEnumerable <string> namespaces, Action <T> populateView = null) where T : AbstractSparkView { return(new HtmlResponse( () => { Type viewType = typeof(T); SparkSettings settings = new SparkSettings() .SetPageBaseType(viewType) .SetDebug(false); foreach (string @namespace in namespaces.Distinct()) { settings.AddNamespace(@namespace); } var container = new SparkServiceContainer(settings); var viewFolder = new InMemoryViewFolder(); container.SetServiceBuilder <IViewFolder>(arg => viewFolder); var viewEngine = container.GetService <ISparkViewEngine>(); string viewKey = viewType.Name.Replace("View", "") + ".spark"; const string applicationKey = @"Layouts\application.spark"; viewFolder.AddLayoutsPath("Layouts"); viewFolder.Add(viewKey, viewTemplate); viewFolder.Add(applicationKey, ResponseResources.Application); SparkViewDescriptor descriptor = new SparkViewDescriptor() .AddTemplate(viewKey) .AddTemplate(applicationKey); var view = (T)viewEngine.CreateInstance(descriptor); try { if (populateView != null) { populateView(view); } var writer = new StringWriter(); view.RenderView(writer); return writer.ToString(); } finally { viewEngine.ReleaseInstance(view); } })); }
public void Init(bool automaticEncoding) { _settings = new SparkSettings() .SetPageBaseType(typeof(StubSparkView)) .SetAutomaticEncoding(automaticEncoding); var container = new SparkServiceContainer(_settings); _viewFolder = new InMemoryViewFolder(); container.SetServiceBuilder <IViewFolder>(c => _viewFolder); _engine = container.GetService <ISparkViewEngine>(); }
public static void Start() { LoggingConfig.Configure(); ViewEngines.Engines.Clear(); var settings = new SparkSettings() .AddViewFolder(ViewFolderType.FileSystem, new Dictionary<string, string> { {"basePath", ThemeDirectory} }) .SetAutomaticEncoding(true); if (Debugger.IsAttached) settings.SetDebug(true); var viewFactory = new SparkViewFactory(settings); var sparkServiceContainer = new SparkServiceContainer(settings); sparkServiceContainer.SetServiceBuilder<IViewEngine>(c => viewFactory); sparkServiceContainer.SetServiceBuilder<IDescriptorBuilder>(c => new DefaultDescriptorBuilder()); sparkServiceContainer.SetServiceBuilder<ICacheServiceProvider>(c => new DefaultCacheServiceProvider()); sparkServiceContainer.AddFilter(new AreaDescriptorFilter()); sparkServiceContainer.AddFilter(CustomThemeFilter.For(GetCustomerId)); ViewEngines.Engines.Add(sparkServiceContainer.GetService<IViewEngine>()); var sparkEngine = sparkServiceContainer.GetService<ISparkViewEngine>(); var timer = new Stopwatch(); timer.Start(); sparkEngine.BatchCompilation(AllKnownDescriptors(viewFactory)); timer.Stop(); "SparkWebMvc".Log().Info("Pre-compile time: {0} seconds", timer.Elapsed.TotalSeconds); }
public void EngineGetsCustomServiceAndViewFolderSettings() { var settings = new SparkSettings(); settings.AddViewFolder(typeof(TestViewFolder), new Dictionary <string, string> { { "testpath", Path.Combine("hello", "world.spark") } }); var container = new SparkServiceContainer(settings); container.SetServiceBuilder <IViewActivatorFactory>(c => new TestActivatorFactory()); var engine = container.GetService <ISparkViewEngine>(); Assert.IsInstanceOf(typeof(TestActivatorFactory), engine.ViewActivatorFactory); Assert.IsTrue(engine.ViewFolder.HasView(Path.Combine("hello", "world.spark"))); }
public void CreatedSettingsUsedWhenProvided() { var settings = new SparkSettings().SetPrefix("foo"); var container = new SparkServiceContainer(settings); var settings2 = container.GetService<ISparkViewEngine>().Settings; Assert.AreSame(settings, settings2); }
public void SettingsServiceReplacesType() { var container = new SparkServiceContainer(); container.SetService<ISparkExtensionFactory>(new StubExtensionFactory()); Assert.IsInstanceOfType(typeof(StubExtensionFactory), container.GetService<ISparkExtensionFactory>()); }
public void EmptyMasterPreventsDefaultLayout() { var settings = new SparkSettings() .SetPageBaseType(typeof(StubSparkView)); var container = new SparkServiceContainer(settings); var viewFolder = new InMemoryViewFolder { {"Home\\Index.spark", "<use master=\"\"/><p>Hello world</p><content:title>bar</content:title>"}, {"Layouts\\Application.spark", "<h1>alpha</h1><use:view/><p>beta</p>"} }; container.SetServiceBuilder<IViewFolder>(c => viewFolder); var engine = container.GetService<ISparkViewEngine>(); var descriptor = new SparkViewDescriptor() .AddTemplate("Home\\Index.spark") .AddTemplate("Layouts\\Application.spark"); var view = engine.CreateInstance(descriptor); var contents = view.RenderView(); engine.ReleaseInstance(view); Assert.AreEqual("<p>Hello world</p>", contents); }
public void EngineGetsCustomServiceAndViewFolderSettings() { var settings = new SparkSettings(); settings.AddViewFolder(typeof(TestViewFolder), new Dictionary<string, string> { { "testpath", "hello\\world.spark" } }); var container = new SparkServiceContainer(settings); container.SetServiceBuilder<IViewActivatorFactory>(c=>new TestActivatorFactory()); var engine = container.GetService<ISparkViewEngine>(); Assert.IsInstanceOfType(typeof(TestActivatorFactory), engine.ViewActivatorFactory); Assert.IsTrue(engine.ViewFolder.HasView("hello\\world.spark")); }
public void CreatingViewEngineWithSimpleContainer() { var settings = new SparkSettings().AddNamespace("System.Web.Mvc.Html"); var container = new SparkServiceContainer(settings); container.SetServiceBuilder<IViewEngine>(c => new SparkViewFactory(c.GetService<ISparkSettings>())); var viewFactory = (SparkViewFactory)container.GetService<IViewEngine>(); var viewEngine = container.GetService<ISparkViewEngine>(); var viewFolder = container.GetService<IViewFolder>(); Assert.AreSame(settings, viewFactory.Settings); Assert.AreSame(settings, viewEngine.Settings); Assert.AreSame(viewEngine, viewFactory.Engine); Assert.AreSame(viewFolder, viewEngine.ViewFolder); Assert.AreSame(viewFolder, viewFactory.ViewFolder); }
public void Init() { CompiledViewHolder.Current = new CompiledViewHolder(); var settings = new SparkSettings() .SetPageBaseType(typeof(StubSparkView)); var container = new SparkServiceContainer(settings); _viewFolder = new InMemoryViewFolder(); container.SetServiceBuilder<IViewFolder>(c => _viewFolder); _engine = container.GetService<ISparkViewEngine>(); }
public void Init(bool automaticEncoding) { _settings = new SparkSettings() .SetPageBaseType(typeof(StubSparkView)) .SetAutomaticEncoding(automaticEncoding); var container = new SparkServiceContainer(_settings); _viewFolder = new InMemoryViewFolder(); container.SetServiceBuilder<IViewFolder>(c => _viewFolder); _engine = container.GetService<ISparkViewEngine>(); }