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); }
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); }
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); }
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); }