Beispiel #1
0
        public static EsiFragmentExecutor Create(
            EsiFragmentCacheFacade cache,
            IHttpLoader httpLoader,
            EsiBodyParser parser,
            Log log,
            ServiceFactory serviceFactory,
            IncludeUriParser includeUriParser)
        {
            if (cache == null)
            {
                throw new ArgumentNullException(nameof(cache));
            }
            if (httpLoader == null)
            {
                throw new ArgumentNullException(nameof(httpLoader));
            }
            if (parser == null)
            {
                throw new ArgumentNullException(nameof(parser));
            }
            if (log == null)
            {
                throw new ArgumentNullException(nameof(log));
            }
            if (serviceFactory == null)
            {
                throw new ArgumentNullException(nameof(serviceFactory));
            }
            if (includeUriParser == null)
            {
                throw new ArgumentNullException(nameof(includeUriParser));
            }

            var executors = new Dictionary <Type, Func <IEsiFragment, EsiExecutionContext, Task <IEnumerable <string> > > >();

            var fragmentExecutor  = new EsiFragmentExecutor(executors, serviceFactory);
            var includeExecutor   = new EsiIncludeFragmentExecutor(includeUriParser, cache, httpLoader, parser, fragmentExecutor);
            var ignoreExecutor    = new EsiIgnoreFragmentExecutor();
            var textExecutor      = new EsiTextFragmentExecutor();
            var compositeExecutor = new EsiCompositeFragmentExecutor(fragmentExecutor);
            var tryExecutor       = new EsiTryFragmentExecutor(fragmentExecutor, log);
            var chooseExecutor    = new EsiChooseFragmentExecutor(fragmentExecutor);
            var varsExecutor      = new EsiVarsFragmentExecutor();

            executors[typeof(EsiIncludeFragment)]   = (f, ec) => includeExecutor.Execute((EsiIncludeFragment)f, ec);
            executors[typeof(EsiIgnoreFragment)]    = (f, ec) => ignoreExecutor.Execute((EsiIgnoreFragment)f, ec);
            executors[typeof(EsiTextFragment)]      = (f, ec) => textExecutor.Execute((EsiTextFragment)f, ec);
            executors[typeof(EsiCompositeFragment)] = (f, ec) => compositeExecutor.Execute((EsiCompositeFragment)f, ec);
            executors[typeof(EsiTryFragment)]       = (f, ec) => tryExecutor.Execute((EsiTryFragment)f, ec);
            executors[typeof(EsiChooseFragment)]    = (f, ec) => chooseExecutor.Execute((EsiChooseFragment)f, ec);
            executors[typeof(EsiVarsFragment)]      = (f, ec) => varsExecutor.Execute((EsiVarsFragment)f, ec);

            return(fragmentExecutor);
        }
        public async Task Should_run_pipeline_when_executing()
        {
            var textExecutor = new EsiTextFragmentExecutor();
            var executors    = new Dictionary <Type, Func <IEsiFragment, EsiExecutionContext, Task <IEnumerable <string> > > >
            {
                [typeof(EsiTextFragment)] = (f, ec) => textExecutor.Execute((EsiTextFragment)f, ec)
            };

            var resolver = new PipelineContainer();

            resolver.Add(new FakeTextPipeline());

            var fragmentExecutor = new EsiFragmentExecutor(executors, resolver.GetInstance);

            var fragment = new EsiTextFragment("body");
            var result   = await fragmentExecutor.Execute(fragment, EmptyExecutionContext());

            result.Should().Have.SameSequenceAs("pre", "<body>", "post");
        }