Skip to content

Commit 1c92fa8

Browse files
Remove grouped test cases
1 parent a046e76 commit 1c92fa8

File tree

2 files changed

+8
-15
lines changed

2 files changed

+8
-15
lines changed

exercises/practice/allergies/.meta/Generator.tpl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ using Xunit;
22

33
public class AllergiesTests
44
{
5-
{{for testCase in testCasesByProperty.allergicTo}}
5+
{{for testCase in testCases | property "allergicTo" }}
66
[Fact{{if !for.first}}(Skip = "Remove this Skip property to run this test"){{end}}]
77
public void {{testCase.testMethodName}}()
88
{
@@ -11,7 +11,7 @@ public class AllergiesTests
1111
}
1212
{{end}}
1313

14-
{{for testCase in testCasesByProperty.list}}
14+
{{for testCase in testCases | property "list"}}
1515
[Fact(Skip = "Remove this Skip property to run this test")]
1616
public void {{testCase.testMethodName}}()
1717
{

generators/Templates.cs

Lines changed: 6 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,10 @@ internal static class Templates
1313
public static string RenderTestsCode(CanonicalData canonicalData)
1414
{
1515
var scriptObject = new ScriptObject();
16-
scriptObject.Import("enum", new Func<string, string, string>((text, enumType) => $"{enumType.Pascalize()}.{text.Pascalize()}"));;
16+
scriptObject.Import("enum", new Func<string, string, string>((text, enumType) =>
17+
$"{enumType.Pascalize()}.{text.Pascalize()}"));
18+
scriptObject.Import("property", new Func<ScriptArray, string, ScriptArray>((testCases, name) =>
19+
new ScriptArray(testCases.Cast<ScriptObject>().Where(testCase => testCase["property"].ToString() == name))));
1720
scriptObject.Import(TemplateData.ForCanonicalData(canonicalData));
1821

1922
var context = new TemplateContext();
@@ -25,13 +28,8 @@ public static string RenderTestsCode(CanonicalData canonicalData)
2528

2629
private static class TemplateData
2730
{
28-
internal static JsonElement ForCanonicalData(CanonicalData canonicalData)
29-
{
30-
var testCases = canonicalData.TestCases.Select(Create).ToArray();
31-
var testCasesByProperty = GroupTestCasesByProperty(testCases);
32-
33-
return JsonSerializer.SerializeToElement(new { testCases, testCasesByProperty });
34-
}
31+
internal static JsonElement ForCanonicalData(CanonicalData canonicalData) =>
32+
JsonSerializer.SerializeToElement(new { testCases = canonicalData.TestCases.Select(Create).ToArray() });
3533

3634
private static JsonElement Create(JsonNode testCase)
3735
{
@@ -40,10 +38,5 @@ private static JsonElement Create(JsonNode testCase)
4038

4139
return JsonSerializer.SerializeToElement(testCase);
4240
}
43-
44-
private static Dictionary<string, JsonElement[]> GroupTestCasesByProperty(IEnumerable<JsonElement> testCases) =>
45-
testCases
46-
.GroupBy(testCase => testCase.GetProperty("property").GetString()!)
47-
.ToDictionary(kv => kv.Key, kv => kv.ToArray());
4841
}
4942
}

0 commit comments

Comments
 (0)