public void ReloadOnChanged_GetTokenBeforeReload() { // Arrange var tokenSource1 = new CancellationTokenSource(); var tokenSource2 = new CancellationTokenSource(); var fileProvider = new MockFileProvider(); fileProvider.Cancel = tokenSource1; var configuration = new MockConfigurationRoot(); configuration.OnReload = () => Assert.Equal(2, fileProvider.WatchCount); // Act-1 configuration.ReloadOnChanged(fileProvider, "config.json"); // Assert-1 Assert.Equal(1, fileProvider.WatchCount); Assert.Equal(0, configuration.ReloadCount); // Act-2 fileProvider.Cancel = tokenSource2; tokenSource1.Cancel(); Assert.Equal(2, fileProvider.WatchCount); Assert.Equal(1, configuration.ReloadCount); }
public async Task IncludeWithTagParamShouldNotBeSetInTheParentTemplate() { var source = @"{% assign Partials = 'parent value' %} {% include 'Partials' with 'included value' %} Parent Content {{ Partials }}"; var expected = @"Partial Content Partials: 'included value' color: '' shape: '' Parent Content parent value"; var fileProvider = new MockFileProvider(); fileProvider.Add("Partials.liquid", @"{{ 'Partial Content' }} Partials: '{{ Partials }}' color: '{{ color }}' shape: '{{ shape }}'"); FluidTemplate.TryParse(source, out var template, out var messages); var context = new TemplateContext { FileProvider = fileProvider }; var result = await template.RenderAsync(context); Assert.Equal(expected, result); }
public async Task IncludeSatement_ShouldLoadPartial_IfThePartialsFolderExist() { var expression = new LiteralExpression(new StringValue("_Partial.liquid")); var sw = new StringWriter(); var fileProvider = new MockFileProvider(); fileProvider.Add("_Partial.liquid", @"{{ 'Partial Content' }} Partials: '{{ Partials }}' color: '{{ color }}' shape: '{{ shape }}'"); var context = new TemplateContext { FileProvider = fileProvider }; var expectedResult = @"Partial Content Partials: '' color: '' shape: ''"; await new IncludeStatement(expression).WriteToAsync(sw, HtmlEncoder.Default, context); Assert.Equal(expectedResult, sw.ToString()); }
public async Task IncludeSatement_WithTagParams_ShouldBeEvaluated() { var pathExpression = new LiteralExpression(new StringValue("color")); var withExpression = new LiteralExpression(new StringValue("blue")); var sw = new StringWriter(); var fileProvider = new MockFileProvider(); fileProvider.Add("color.liquid", @"{{ 'Partial Content' }} Partials: '{{ Partials }}' color: '{{ color }}' shape: '{{ shape }}'"); var context = new TemplateContext { FileProvider = fileProvider }; var expectedResult = @"Partial Content Partials: '' color: 'blue' shape: ''"; await new IncludeStatement(pathExpression, with: withExpression).WriteToAsync(sw, HtmlEncoder.Default, context); Assert.Equal(expectedResult, sw.ToString()); }
public async Task IncludeParamsShouldNotBeSetInTheParentTemplate() { var source = @"{% assign color = 'blue' %} {% include 'Partials', color: 'red', shape: 'circle' %} Parent Content color: '{{ color }}' shape: '{{ shape }}'"; var expected = @"Partial Content Partials: '' color: 'red' shape: 'circle' Parent Content color: 'blue' shape: ''"; FluidTemplate.TryParse(source, out var template, out var messages); var fileProvider = new MockFileProvider(); fileProvider.Add("Partials.liquid", @"{{ 'Partial Content' }} Partials: '{{ Partials }}' color: '{{ color }}' shape: '{{ shape }}'"); var context = new TemplateContext { FileProvider = fileProvider }; var result = await template.RenderAsync(context); Assert.Equal(expected, result); }
public async Task IncludeSatement_WithInlinevariableAssignment_ShouldBeEvaluated() { var expression = new LiteralExpression(new StringValue("_Partial.liquid")); var assignStatements = new List <AssignStatement> { new AssignStatement("color", new LiteralExpression(new StringValue("blue"))), new AssignStatement("shape", new LiteralExpression(new StringValue("circle"))) }; var sw = new StringWriter(); var fileProvider = new MockFileProvider(); fileProvider.Add("_Partial.liquid", @"{{ 'Partial Content' }} Partials: '{{ Partials }}' color: '{{ color }}' shape: '{{ shape }}'"); var context = new TemplateContext { FileProvider = fileProvider }; var expectedResult = @"Partial Content Partials: '' color: 'blue' shape: 'circle'"; await new IncludeStatement(expression, assignStatements: assignStatements).WriteToAsync(sw, HtmlEncoder.Default, context); Assert.Equal(expectedResult, sw.ToString()); }
public void ReloadOnChanged_GetTokenBeforeReload() { // Arrange var tokenSource1 = new CancellationTokenSource(); var tokenSource2 = new CancellationTokenSource(); var fileProvider = new MockFileProvider(); fileProvider.Cancel = tokenSource1; var configuration = new MockConfigurationRoot(); configuration.OnReload = () => Assert.Equal(2, fileProvider.WatchCount); // Act-1 configuration.ReloadOnChanged(fileProvider, "config.json"); // Assert-1 Assert.Equal(1, fileProvider.WatchCount); Assert.Equal(0, configuration.ReloadCount); // Act-2 fileProvider.Cancel = tokenSource2; tokenSource1.Cancel(); Assert.Equal(2, fileProvider.WatchCount); Assert.Equal(1, configuration.ReloadCount); }
public void TestLibDdsNotAvailable() { var fileProvider = new MockFileProvider(); fileProvider.FileExistsResultQueue.Enqueue(false); LibDDS.FindDependencies(fileProvider); Assert.IsFalse(LibDDS.IsAvailable); }
/// <summary> /// Builds the configuration source from a list of file names. /// </summary> /// <param name="fileNames">The list of file names.</param> /// <returns>A configuration source for testing purposes.</returns> private static XmlDictionarySectionConfigurationSource BuildConfigSource(string[] fileNames) { MockFileProvider fileProvider = new MockFileProvider(new MockDirectoryContents(fileNames)); ConfigurationBuilder configBuilder = new ConfigurationBuilder(); configBuilder.SetFileProvider(fileProvider); XmlDictionarySectionConfigurationSource source = new XmlDictionarySectionConfigurationSource(SECTION_NAME); source.Build(configBuilder); return(source); }
public MockHostEnvironment(string root = @"C:\Testing\Test\", IFileSystem fileSystem = null) { EnvironmentName = "Development"; ApplicationName = "Test"; FileSystem = fileSystem ?? new MockFileSystem(); ContentRootPath = root; FileSystem.Directory.CreateDirectory(ContentRootPath); ContentRootFileProvider = new MockFileProvider(ContentRootPath, FileSystem); WebRootPath = Path.Combine(ContentRootPath, "wwwroot"); WebRootFileProvider = new MockFileProvider(WebRootPath, FileSystem); FileSystem.Directory.CreateDirectory(WebRootPath); }
public void RenderTagCantUseDynamicName() { var fileProvider = new MockFileProvider(); var options = new TemplateOptions() { FileProvider = fileProvider, MemberAccessStrategy = UnsafeMemberAccessStrategy.Instance }; var context = new TemplateContext(options); var result = _parser.TryParse("{% assign name = 'snippet' %}{% render name %}", out var template, out var error); Assert.False(result); Assert.Contains(ErrorMessages.ExpectedStringRender, error); }
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 void TestGetImageBytes_NoLibDDS() { var ddsPath = Path.Combine(TestContext.CurrentContext.TestDirectory, "Samples", "Resources", "Texture", "4d0ab27f42b14326ed4987ed25566663.Texture-Resource.v9a8d4bbd19b4cd55.payload.v0.noVariants.dds"); var ddsBytes = File.ReadAllBytes(ddsPath); var fileProvider = new MockFileProvider(); fileProvider.FileExistsResultQueue.Enqueue(false); LibDDS.FindDependencies(fileProvider); Assert.Throws <Exception>(() => { LibDDS.GetImageBytesFromDds(ddsBytes, 0, 0, LibDDS.ConversionOptions.CodecType.CODEC_PNG); }); }
public async Task IncludeSatement_ShouldLimitRecursion() { var sw = new StringWriter(); var fileProvider = new MockFileProvider(); fileProvider.Add("_Partial.liquid", @"{{ 'Partial Content' }} {% include _Partial.liquid %}"); var context = new TemplateContext { FileProvider = fileProvider }; await Assert.ThrowsAsync <InvalidOperationException>(() => new IncludeStatement("_Partial.liquid").WriteToAsync(sw, HtmlEncoder.Default, context).AsTask()); }
public async Task IncludeSatement_ShouldLimitRecursion() { var expression = new LiteralExpression(new StringValue("_Partial.liquid")); var sw = new StringWriter(); var fileProvider = new MockFileProvider(); fileProvider.Add("_Partial.liquid", @"{{ 'Partial Content' }} {% include '_Partial' %}"); var options = new TemplateOptions() { FileProvider = fileProvider }; var context = new TemplateContext(options); await Assert.ThrowsAsync <InvalidOperationException>(() => new IncludeStatement(_parser, expression).WriteToAsync(sw, HtmlEncoder.Default, context).AsTask()); }
public void Increment_Is_Isolated_Between_Renders() { var fileProvider = new MockFileProvider(); fileProvider.Add("incr.liquid", "{% increment %}"); var options = new TemplateOptions() { FileProvider = fileProvider, MemberAccessStrategy = UnsafeMemberAccessStrategy.Instance }; var context = new TemplateContext(options); _parser.TryParse("{% increment %}{% increment %}{% render 'incr' %}", out var template, out var error); Assert.Null(error); var result = template.Render(context); Assert.Equal("010", result); }
public void IncludeTag_With_Alias() { var fileProvider = new MockFileProvider(); fileProvider.Add("product_alias.liquid", "Product: {{ product.title }} "); var options = new TemplateOptions() { FileProvider = fileProvider, MemberAccessStrategy = UnsafeMemberAccessStrategy.Instance }; var context = new TemplateContext(options); context.SetValue("products", new[] { new { title = "Draft 151cm" }, new { title = "Element 155cm" } }); _parser.TryParse("{% include 'product_alias' with products[0] as product %}", out var template); var result = template.Render(context); Assert.Equal("Product: Draft 151cm ", result); }
public void IncludeTag_Does_Inherit_Parent_Scope_Variables() { var fileProvider = new MockFileProvider(); fileProvider.Add("snippet.liquid", "{{ outer_variable }}"); var options = new TemplateOptions() { FileProvider = fileProvider, MemberAccessStrategy = UnsafeMemberAccessStrategy.Instance }; var context = new TemplateContext(options); context.SetValue("product", new { title = "Draft 151cm" }); _parser.TryParse("{% assign outer_variable = 'should be visible' %}{% include 'snippet' %}", out var template); var result = template.Render(context); Assert.Equal("should be visible", result); }
public void RenderTag_With_Default_Name() { var fileProvider = new MockFileProvider(); fileProvider.Add("product.liquid", "Product: {{ product.title }} "); var options = new TemplateOptions() { FileProvider = fileProvider, MemberAccessStrategy = UnsafeMemberAccessStrategy.Instance }; var context = new TemplateContext(options); context.SetValue("product", new { title = "Draft 151cm" }); _parser.TryParse("{% render 'product' %}", out var template); var result = template.Render(context); Assert.Equal("Product: Draft 151cm ", result); }
public void RenderTag_For_Loop() { var fileProvider = new MockFileProvider(); fileProvider.Add("product.liquid", "Product: {{ product.title }} {% if forloop.first %}first{% endif %} {% if forloop.last %}last{% endif %} index:{{ forloop.index }} "); var options = new TemplateOptions() { FileProvider = fileProvider, MemberAccessStrategy = UnsafeMemberAccessStrategy.Instance }; var context = new TemplateContext(options); context.SetValue("products", new[] { new { title = "Draft 151cm" }, new { title = "Element 155cm" } }); _parser.TryParse("{% render 'product' for products %}", out var template); var result = template.Render(context); Assert.Equal("Product: Draft 151cm first index:1 Product: Element 155cm last index:2 ", result); }
public void RenderTag_Inherits_Global_Scope_Variables() { var fileProvider = new MockFileProvider(); fileProvider.Add("snippet.liquid", "{{ global_variable }}"); var options = new TemplateOptions() { FileProvider = fileProvider, MemberAccessStrategy = UnsafeMemberAccessStrategy.Instance }; var context = new TemplateContext(options); options.Scope.SetValue("global_variable", new StringValue("global value")); context.SetValue("product", new { title = "Draft 151cm" }); _parser.TryParse("{% render 'snippet' %}", out var template); var result = template.Render(context); Assert.Equal("global value", result); }
public void TestExtractWhileUnavailable() { var fileProvider = new MockFileProvider(); fileProvider.FileExistsResultQueue.Enqueue(false); fileProvider.FileExistsResultQueue.Enqueue(false); fileProvider.FileExistsResultQueue.Enqueue(false); fileProvider.FileExistsResultQueue.Enqueue(false); fileProvider.FileExistsResultQueue.Enqueue(false); fileProvider.FileExistsResultQueue.Enqueue(false); fileProvider.FileExistsResultQueue.Enqueue(false); Unpacker.FindDependencies(fileProvider); var path = Path.Combine(TestContext.CurrentContext.TestDirectory, "Samples", "OodleLz", "Compressed_F2_Resource.bin"); Assert.Throws <Exception>(() => { Unpacker.DecompressResource(path); }); }
public void IncludeTagsFlowTemplateType() { var source = "A {% include 'test.liquid' %} B"; var include = "{% more '2' | append: 'pack' %}"; var expected = "A here is some more 2pack B"; var fileProvider = new MockFileProvider() .Add("test.liquid", include); var context = new TemplateContext() { FileProvider = fileProvider }; var success = FluidTemplate2.TryParse(source, out var template); Assert.True(success); var result = template.Render(context); Assert.Equal(expected, result); }
public _AddDotenvFile_all_arguments_overload() : base() { _MockProvider = new MockFileProvider(_ConfigBody); _Builder = new ConfigurationBuilder(); }