public void Should_return_outer_body_when_no_matching_tag() { var fragmentParser = new EsiFragmentParser( new Dictionary <string, IEsiFragmentParser>(), Array.Empty <IFragmentParsePipeline>()); const string tag = "esi:unknown"; const string body = "body"; const string outerBody = "<esi:unknown>body</unknown>"; var attributes = new Dictionary <string, string>(); var fragment = fragmentParser.Parse(tag, attributes, body, outerBody); fragment.Should().Be.InstanceOf <EsiTextFragment>(); ((EsiTextFragment)fragment).Body.Should().Be.EqualTo(outerBody); }
public void Should_execute_pipeline_when_parsing() { var attributes = new Dictionary <string, string>(); var fragmentParser = new EsiFragmentParser( new Dictionary <string, IEsiFragmentParser> { ["esi:text"] = new EsiTextParser() }, new IFragmentParsePipeline[] { new RoundPipeline(), new SquarePipeline(), new CurlyPipeline() }); var fragment = fragmentParser.Parse("esi:text", attributes, "body", "outer"); ((EsiTextFragment)fragment).Body.Should().Be.EqualTo("{[(body)]}"); }
public void Should_return_fragment_for_matching_tag() { var attributes = new Dictionary <string, string>(); var fooParser = A.Fake <IEsiFragmentParser>(); var fooFragment = A.Fake <IEsiFragment>(); A.CallTo(() => fooParser.Parse(attributes, "")).Returns(fooFragment); var fragmentParser = new EsiFragmentParser( new Dictionary <string, IEsiFragmentParser> { ["esi:foo"] = fooParser }, Array.Empty <IFragmentParsePipeline>()); var fragment = fragmentParser.Parse("esi:foo", attributes, "", ""); fragment.Should().Be.EqualTo(fooFragment); }
public static EsiBodyParser Create( IEnumerable <IFragmentParsePipeline> parsePipelines) { if (parsePipelines == null) { throw new ArgumentNullException(nameof(parsePipelines)); } var parsers = new Dictionary <string, IEsiFragmentParser>(); var fragmentParser = new EsiFragmentParser(parsers, parsePipelines); var bodyParser = new EsiBodyParser(fragmentParser); parsers["esi:include"] = new EsiIncludeParser(); parsers["esi:remove"] = new EsiIgnoreParser(); parsers["esi:comment"] = new EsiIgnoreParser(); parsers["esi:text"] = new EsiTextParser(); parsers["esi:try"] = new EsiTryParser(bodyParser); parsers["esi:choose"] = new EsiChooseParser(bodyParser); parsers["esi:vars"] = new EsiVarsParser(); return(bodyParser); }