public Task <IEnumerable <string> > Execute(EsiVarsFragment fragment, EsiExecutionContext executionContext)
        {
            if (fragment == null)
            {
                throw new ArgumentNullException(nameof(fragment));
            }
            if (executionContext == null)
            {
                throw new ArgumentNullException(nameof(executionContext));
            }

            var result = VariableStringResolver.Resolve(executionContext, fragment.Body);

            return(Task.FromResult(result));
        }
        public async Task <IEnumerable <string> > Execute(
            EsiIncludeFragment fragment,
            EsiExecutionContext executionContext)
        {
            if (fragment == null)
            {
                throw new ArgumentNullException(nameof(fragment));
            }

            var rawUrl = string.Concat(VariableStringResolver.Resolve(executionContext, fragment.Url));
            var uri    = _uriParser(rawUrl);

            var remoteFragment = await _cache.GetOrAdd(
                uri,
                executionContext,
                () => RequestAndParse(uri, executionContext));

            return(await _fragmentExecutor.Execute(remoteFragment, executionContext));
        }
Exemple #3
0
        public void Parse_and_build(string input, string expected)
        {
            var variables = new Dictionary <string, IVariableValueResolver>
            {
                ["HTTP_HOST"]   = new SimpleVariableValueResolver(new Lazy <string>("example.com")),
                ["HTTP_COOKIE"] = new DictionaryVariableValueResolver(new Lazy <IReadOnlyDictionary <string, string> >(
                                                                          new Dictionary <string, string>
                {
                    ["showPricesWithVat"] = "true"
                }))
            };
            var executionContext = new EsiExecutionContext(
                new Dictionary <string, IReadOnlyCollection <string> >(), variables);

            var variableString = VariableStringParser.Parse(input);
            var actual         = string.Concat(VariableStringResolver.Resolve(executionContext, variableString));

            actual.Should().Be.EqualTo(expected);
        }