コード例 #1
0
ファイル: EsiIncludeParser.cs プロジェクト: cdon-dev/EsiNet
        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);
        }
コード例 #2
0
ファイル: ParsingTests.cs プロジェクト: cdon-dev/EsiNet
        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);
        }
コード例 #3
0
ファイル: ParsingTests.cs プロジェクト: cdon-dev/EsiNet
        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);
        }
コード例 #4
0
ファイル: ParsingTests.cs プロジェクト: cdon-dev/EsiNet
        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);
        }