Skip to content

Commit

Permalink
Adding dictionary unit test
Browse files Browse the repository at this point in the history
  • Loading branch information
sebastienros committed May 3, 2021
1 parent c9d8d18 commit 8f86a6a
Showing 1 changed file with 21 additions and 0 deletions.
21 changes: 21 additions & 0 deletions Fluid.Tests/TemplateTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -993,5 +993,26 @@ public async Task UnsafeMemberStrategyShouldSupportSnakeCase(bool registerModelT
var result = await template.RenderAsync(context);
Assert.Equal(expected, result);
}

[Fact]
public async Task ShouldIterateOnDictionaries()
{
var model = new
{
Capitals = new Dictionary<string, string> { { "France", "Paris" }, { "Spain", "Madrid" }, { "Italy", "Rome" } }
};

var source = "{% for i in Capitals %}{{ Capitals[i.first] }}{{ i[1] }}{% endfor %}";
var expected = "ParisParisMadridMadridRomeRome";

_parser.TryParse(source, out var template, out var error);

var options = new TemplateOptions();
options.MemberAccessStrategy = UnsafeMemberAccessStrategy.Instance;
var context = new TemplateContext(model, options);

var result = await template.RenderAsync(context);
Assert.Equal(expected, result);
}
}
}

0 comments on commit 8f86a6a

Please sign in to comment.