public void IncludeTest() { IncludeStatement inc = new IncludeStatement() { IncludeFile = "colors.inc" }; var povCode = inc.ToPovCode(); Check.That(povCode).IsEqualTo("#include \"colors.inc\""); }
public async Task IncludeSatement_ShouldThrowsFileNotFoundException_IfTheFileProviderIsNotPresent() { var stmt = new IncludeStatement( new LiteralExpression(new StringValue("_Partial.liquid")) ); var sw = new StringWriter(); await Assert.ThrowsAsync <FileNotFoundException>(async() => await stmt.WriteToAsync(sw, HtmlEncoder.Default, new TemplateContext()) ); }
public async Task IncludeSatement_ShouldLoadPartial_IfThePartialsFolderExist() { var stmt = new IncludeStatement( new LiteralExpression(new StringValue("_Partial.liquid")) ); var sw = new StringWriter(); var context = new TemplateContext { FileProvider = new TestFileProvider("Partials") }; await stmt.WriteToAsync(sw, HtmlEncoder.Default, context); Assert.Equal("Partial Content", sw.ToString()); }
public async Task IncludeSatement_ShouldLoadCorrectTemplate_IfTheMemberExpressionValueChanges() { var expression = new MemberExpression(new IdentifierSegment("Firstname")); var sw = new StringWriter(); var fileProvider = new MockFileProvider(); fileProvider.Add("_First.liquid", @"{{ 'Partial Content One' }} Partials_One: '{{ Partials }}' color_One: '{{ color }}' shape_One: '{{ shape }}'"); fileProvider.Add("_Second.liquid", @"{{ 'Partial Content Two' }} Partials_Two: '{{ Partials }}' color_Two: '{{ color }}' shape_Two: '{{ shape }}'"); var model = new Domain.Person { Firstname = "_First.liquid" }; var options = new TemplateOptions() { FileProvider = fileProvider }; var context = new TemplateContext(model, options); var expectedResultFirstCall = @"Partial Content One Partials_One: '' color_One: '' shape_One: ''"; var expectedResultSecondCall = @"Partial Content Two Partials_Two: '' color_Two: '' shape_Two: ''"; var include = new IncludeStatement(_parser, expression); await include.WriteToAsync(sw, HtmlEncoder.Default, context); Assert.Equal(expectedResultFirstCall, sw.ToString()); model.Firstname = "_Second.liquid"; sw = new StringWriter(); await include.WriteToAsync(sw, HtmlEncoder.Default, context); Assert.Equal(expectedResultSecondCall, sw.ToString()); }
public async Task IncludeSatement_ShouldThrowsDirectoryNotFoundException_IfThePartialsFolderNotExist() { var stmt = new IncludeStatement( new LiteralExpression(new StringValue("_Partial.liquid")) ); await Assert.ThrowsAsync <DirectoryNotFoundException>(async() => { var sw = new StringWriter(); var context = new TemplateContext { FileProvider = new TestFileProvider("NonPartials") }; await stmt.WriteToAsync(sw, HtmlEncoder.Default, context); }); }