Exemplo n.º 1
0
        public IEsiFragment Parse(IReadOnlyDictionary <string, string> attributes, string body)
        {
            if (attributes == null)
            {
                throw new ArgumentNullException(nameof(attributes));
            }
            if (body == null)
            {
                throw new ArgumentNullException(nameof(body));
            }

            var srcUrl = VariableStringParser.Parse(attributes["src"]);

            var srcFragment = new EsiIncludeFragment(srcUrl);

            IEsiFragment includeFragment;

            if (attributes.TryGetValue("alt", out var altUrl))
            {
                var altFragment = new EsiIncludeFragment(VariableStringParser.Parse(altUrl));
                includeFragment = new EsiTryFragment(srcFragment, altFragment);
            }
            else
            {
                includeFragment = srcFragment;
            }

            return(ShouldContinueOnError(attributes)
                ? new EsiTryFragment(includeFragment, new EsiIgnoreFragment())
                : includeFragment);
        }
Exemplo n.º 2
0
        public void Parse_IncludeTagWithAltUrl_TryFragmentReturned()
        {
            var fragment = Parse(
                @"<esi:include src=""http://host/fragment"" alt=""http://alt/fragment""/>");

            var expected = new EsiTryFragment(
                EsiIncludeFragmentFactory.Create("http://host/fragment"),
                EsiIncludeFragmentFactory.Create("http://alt/fragment"));

            fragment.ShouldDeepEqual(expected);
        }
Exemplo n.º 3
0
        public void Parse_TryTagWithAttemptExcept_TryFragmentReturned()
        {
            var fragment = Parse(
                @"<esi:try><esi:attempt>Attempt</esi:attempt><esi:except>Except</esi:except></esi:try>");

            var expected = new EsiTryFragment(
                new EsiTextFragment("Attempt"),
                new EsiTextFragment("Except"));

            fragment.ShouldDeepEqual(expected);
        }
Exemplo n.º 4
0
        public void Parse_IncludeTagWithOnErrorContinue_TryFragmentReturned()
        {
            var fragment = Parse(
                @"<esi:include src=""http://host/fragment"" onerror=""continue""/>");

            var expected = new EsiTryFragment(
                EsiIncludeFragmentFactory.Create("http://host/fragment"),
                new EsiIgnoreFragment());

            fragment.ShouldDeepEqual(expected);
        }