public ILavaEngine GetEngineInstance(Type engineType)
        {
            ILavaEngine engine = null;

            if (engineType == typeof(DotLiquidEngine))
            {
                engine = _dotliquidEngine;
            }
            else if (engineType == typeof(FluidEngine))
            {
                engine = _fluidEngine;
            }
            else if (engineType == typeof(RockLiquidEngine))
            {
                engine = _rockliquidEngine;
            }

            if (engine == null)
            {
                throw new Exception($"Lava Engine instance not available. Engine Type \"{engineType}\" is not configured for this test run.");
            }

            // Set the global instance of the engine to ensure that it is available to Lava components.
            LavaService.SetCurrentEngine(engine);

            return(engine);
        }
        /// <summary>
        /// For each of the currently enabled Lava Engines, process the specified action.
        /// </summary>
        /// <param name="testMethod"></param>
        public void ExecuteForActiveEngines(Action <ILavaEngine> testMethod)
        {
            var engines = GetActiveTestEngines();

            var exceptions = new List <Exception>();

            foreach (var engine in engines)
            {
                LavaService.SetCurrentEngine(engine);

                Debug.Print($"\n**\n** Lava Render Test: {engine.EngineName}\n**\n");

                try
                {
                    testMethod(engine);
                }
                catch (Exception ex)
                {
                    // Write the error to debug output.
                    Debug.Print($"\n** ERROR:\n{ex.ToString()}");

                    exceptions.Add(ex);
                }
            }

            if (exceptions.Any())
            {
                throw new AggregateException("Test failed for one or more Lava engines.", exceptions);
            }
        }
示例#3
0
        private static void InitializeGlobalLavaEngineInstance(Type engineType)
        {
            // Initialize the Lava engine.
            var options = new LavaEngineConfigurationOptions();

            if (engineType != typeof(RockLiquidEngine))
            {
                var defaultEnabledLavaCommands = GlobalAttributesCache.Value("DefaultEnabledLavaCommands").SplitDelimitedValues(",").ToList();

                options.FileSystem             = new WebsiteLavaFileSystem();
                options.CacheService           = new WebsiteLavaTemplateCacheService();
                options.DefaultEnabledCommands = defaultEnabledLavaCommands;
            }

            LavaService.SetCurrentEngine(engineType, options);

            // Subscribe to exception notifications from the Lava Engine.
            var engine = LavaService.GetCurrentEngine();

            engine.ExceptionEncountered += Engine_ExceptionEncountered;

            // Initialize Lava extensions.
            InitializeLavaFilters(engine);
            InitializeLavaTags(engine);
            InitializeLavaBlocks(engine);
            InitializeLavaShortcodes(engine);
            InitializeLavaSafeTypes(engine);
        }
示例#4
0
        public void ExceptionHandling_RenderMergeFieldsExtensionMethod_IsRenderedToOutput()
        {
            var input = @"{% invalidTagName %}";

            TestHelper.ExecuteForActiveEngines((engine) =>
            {
                engine.ExceptionHandlingStrategy = ExceptionHandlingStrategySpecifier.RenderToOutput;

                LavaService.SetCurrentEngine(engine);

                var outputText = input.ResolveMergeFields(new Dictionary <string, object>());

                TestHelper.DebugWriteRenderResult(engine, input, outputText);

                Assert.IsTrue(outputText.StartsWith("Error resolving Lava merge fields: Unknown tag 'invalidTagName'\n"));
            });
        }
示例#5
0
        public void WebsiteLavaShortcodeProvider_ModifiedShortcode_ReturnsCorrectVersionAfterModification()
        {
            var options = new LavaEngineConfigurationOptions();

            ILavaTemplateCacheService cacheService = new WebsiteLavaTemplateCacheService();

            options.CacheService = cacheService;

            TestHelper.ExecuteForActiveEngines((defaultEngineInstance) =>
            {
                if (defaultEngineInstance.GetType() == typeof(DotLiquidEngine) ||
                    defaultEngineInstance.GetType() == typeof(RockLiquidEngine))
                {
                    Debug.Write("Shortcode caching is not currently implemented for RockLiquid/DotLiquid.");
                    return;
                }

                var engine = LavaService.NewEngineInstance(defaultEngineInstance.GetType(), options);

                var shortcodeProvider = new TestLavaDynamicShortcodeProvider();

                var rockContext          = new RockContext();
                var lavaShortCodeService = new LavaShortcodeService(rockContext);

                // Create a new Shortcode.
                var shortcodeGuid1 = TestGuids.Shortcodes.ShortcodeTest1.AsGuid();

                var lavaShortcode = lavaShortCodeService.Queryable().FirstOrDefault(x => x.Guid == shortcodeGuid1);

                if (lavaShortcode == null)
                {
                    lavaShortcode = new LavaShortcode();

                    lavaShortCodeService.Add(lavaShortcode);
                }

                lavaShortcode.Guid        = shortcodeGuid1;
                lavaShortcode.TagName     = "TestShortcode1";
                lavaShortcode.Name        = "Test Shortcode 1";
                lavaShortcode.IsActive    = true;
                lavaShortcode.Description = "Test shortcode";
                lavaShortcode.TagType     = TagType.Inline;

                lavaShortcode.Markup = "Hello!";

                rockContext.SaveChanges();

                shortcodeProvider.RegisterShortcode(engine, lavaShortcode);

                // Resolve a template using the new shortcode and verify the result.
                engine.ClearTemplateCache();

                shortcodeProvider.ClearCache();

                LavaService.SetCurrentEngine(engine);

                TestHelper.AssertTemplateOutput(engine, "Hello!", "{[ TestShortcode1 ]}");

                lavaShortcode.Markup = "Goodbye!";

                rockContext.SaveChanges();

                shortcodeProvider.ClearCache();

                engine.ClearTemplateCache();

                TestHelper.AssertTemplateOutput(engine, "Goodbye!", "{[ TestShortcode1 ]}");
            });
        }