Exemplo n.º 1
0
        public void LavaEngine_CreateSecondInstance_FirstInstanceConfigurationIsUnaffected()
        {
            const int mobilePhoneNumberTypeValueId = 12;

            var templateInput = @"
{{ CurrentPerson.NickName }}'s other contact numbers are: {{ CurrentPerson.PhoneNumbers | Where:'NumberTypeValueId', 12, 'notequal' | Select:'NumberFormatted' | Join:', ' }}.'
";

            templateInput.Replace("<mobilePhoneId>", mobilePhoneNumberTypeValueId.ToString());

            var expectedOutput = @"
Ted's other contact numbers are: (623) 555-3322,(623) 555-2444.'
";

            var mergeFields = new Dictionary <string, object> {
                { "CurrentPerson", GetWhereFilterTestPersonTedDecker() }
            };

            TestHelper.ExecuteForActiveEngines((engine) =>
            {
                // Create a second instance of the engine, and verify that the template is resolved identically.
                var secondEngine = LavaIntegrationTestHelper.NewEngineInstance(engine.GetType(), new LavaEngineConfigurationOptions {
                    FileSystem = new MockFileProvider(), CacheService = null
                });

                TestHelper.AssertTemplateOutput(engine, expectedOutput, templateInput, new LavaTestRenderOptions {
                    MergeFields = mergeFields
                });

                TestHelper.AssertTemplateOutput(secondEngine, expectedOutput, templateInput, new LavaTestRenderOptions {
                    MergeFields = mergeFields
                });
            });
        }
        public static void Initialize(bool testRockLiquidEngine, bool testDotLiquidEngine, bool testFluidEngine)
        {
            // Verify the test environment: RockLiquidEngine and DotLiquidEngine are mutually exclusive test environments.
            if (testRockLiquidEngine && testDotLiquidEngine)
            {
                throw new Exception("RockLiquidEngine/DotLiquidEngine cannot be tested simultaneously because they require different global configurations of the DotLiquid library.");
            }

            RockLiquidEngineIsEnabled = testRockLiquidEngine;
            DotLiquidEngineIsEnabled  = testDotLiquidEngine;
            FluidEngineIsEnabled      = testFluidEngine;

            RegisterLavaEngines();

            var engineOptions = new LavaEngineConfigurationOptions();

            engineOptions.ExceptionHandlingStrategy = ExceptionHandlingStrategySpecifier.RenderToOutput;
            engineOptions.FileSystem   = new MockFileProvider();
            engineOptions.CacheService = new MockTemplateCacheService();

            if (RockLiquidEngineIsEnabled)
            {
                // Initialize the Rock variant of the DotLiquid Engine.
                _rockliquidEngine = global::Rock.Lava.LavaService.NewEngineInstance(typeof(RockLiquidEngine), engineOptions);
            }

            if (DotLiquidEngineIsEnabled)
            {
                // Initialize the Lava library DotLiquid Engine.
                _dotliquidEngine = global::Rock.Lava.LavaService.NewEngineInstance(typeof(DotLiquidEngine), engineOptions);
            }

            if (FluidEngineIsEnabled)
            {
                // Initialize the Fluid Engine.
                _fluidEngine = global::Rock.Lava.LavaService.NewEngineInstance(typeof(FluidEngine), engineOptions);
            }

            _instance = new LavaIntegrationTestHelper();
        }