diff --git a/bin/add-practice-exercise.ps1 b/bin/add-practice-exercise.ps1 index b44b9a11ad..8fbfc780fc 100644 --- a/bin/add-practice-exercise.ps1 +++ b/bin/add-practice-exercise.ps1 @@ -51,15 +51,15 @@ $generator = "${exerciseDir}/.meta/Generator.tpl" Add-Content -Path $generator -Value @" using Xunit; -public class ${exerciseName}Tests +public class {{testClass}} { - {{#test_cases}} - [Fact{{#unless @first}}(Skip = "Remove this Skip property to run this test"){{/unless}}] - public void {{test_method_name}}() + {{for test in tests}} + [Fact{{if !for.first}}(Skip = "Remove this Skip property to run this test"){{end}}] + public void {{test.testMethod}}() { // TODO: implement the test } - {{/test_cases}} + {{end}} } "@ & dotnet run --project generators --exercise $Exercise diff --git a/exercises/practice/acronym/.meta/Generator.tpl b/exercises/practice/acronym/.meta/Generator.tpl index fe1454f0eb..5807d0342b 100644 --- a/exercises/practice/acronym/.meta/Generator.tpl +++ b/exercises/practice/acronym/.meta/Generator.tpl @@ -1,12 +1,12 @@ using Xunit; -public class AcronymTests +public class {{testClass}} { {{for test in tests}} [Fact{{if !for.first}}(Skip = "Remove this Skip property to run this test"){{end}}] - public void {{test.methodName}}() + public void {{test.testMethod}}() { - Assert.Equal({{test.expected | string.literal}}, Acronym.Abbreviate({{test.input.phrase | string.literal}})); + Assert.Equal({{test.expected | string.literal}}, {{testedClass}}.{{test.testedMethod}}({{test.input.phrase | string.literal}})); } {{end}} } diff --git a/exercises/practice/affine-cipher/.meta/Generator.tpl b/exercises/practice/affine-cipher/.meta/Generator.tpl index 00368f6ba2..f00a698635 100644 --- a/exercises/practice/affine-cipher/.meta/Generator.tpl +++ b/exercises/practice/affine-cipher/.meta/Generator.tpl @@ -1,16 +1,16 @@ using System; using Xunit; -public class AffineCipherTests +public class {{testClass}} { {{for test in tests}} [Fact{{if !for.first}}(Skip = "Remove this Skip property to run this test"){{end}}] - public void {{test.shortMethodName}}() + public void {{test.shortTestMethod}}() { {{if test.expected.error}} - Assert.Throws(() => AffineCipher.{{test.property | string.capitalize}}({{test.input.phrase | string.literal}}, {{test.input.key.a}}, {{test.input.key.b}})); + Assert.Throws(() => AffineCipher.{{test.testedMethod}}({{test.input.phrase | string.literal}}, {{test.input.key.a}}, {{test.input.key.b}})); {{else}} - Assert.Equal({{test.expected | string.literal}}, AffineCipher.{{test.property | string.capitalize}}({{test.input.phrase | string.literal}}, {{test.input.key.a}}, {{test.input.key.b}})); + Assert.Equal({{test.expected | string.literal}}, {{testedClass}}.{{test.testedMethod}}({{test.input.phrase | string.literal}}, {{test.input.key.a}}, {{test.input.key.b}})); {{end}} } {{end}} diff --git a/exercises/practice/all-your-base/.meta/Generator.tpl b/exercises/practice/all-your-base/.meta/Generator.tpl index 6b2978e1fb..b534c10b76 100644 --- a/exercises/practice/all-your-base/.meta/Generator.tpl +++ b/exercises/practice/all-your-base/.meta/Generator.tpl @@ -1,11 +1,11 @@ using System; using Xunit; -public class AllYourBaseTests +public class {{testClass}} { {{for test in tests}} [Fact{{if !for.first}}(Skip = "Remove this Skip property to run this test"){{end}}] - public void {{test.methodName}}() + public void {{test.testMethod}}() { {{if test.expected.error}} int[] digits = {{test.input.digits}}; @@ -13,7 +13,7 @@ public class AllYourBaseTests {{else}} int[] digits = {{test.input.digits}}; int[] expected = {{test.expected}}; - Assert.Equal(expected, AllYourBase.Rebase({{test.input.inputBase}}, digits, {{test.input.outputBase}})); + Assert.Equal(expected, {{testedClass}}.{{test.testedMethod}}({{test.input.inputBase}}, digits, {{test.input.outputBase}})); {{end}} } {{end}} diff --git a/exercises/practice/allergies/.meta/Generator.tpl b/exercises/practice/allergies/.meta/Generator.tpl index 2371a1b37a..ee4c9f7c1f 100644 --- a/exercises/practice/allergies/.meta/Generator.tpl +++ b/exercises/practice/allergies/.meta/Generator.tpl @@ -1,21 +1,21 @@ using Xunit; -public class AllergiesTests +public class {{testClass}} { {{for test in tests | property "allergicTo" }} [Fact{{if !for.first}}(Skip = "Remove this Skip property to run this test"){{end}}] - public void {{test.methodName}}() + public void {{test.testMethod}}() { - var sut = new Allergies({{test.input.score}}); + var sut = new {{testedClass}}({{test.input.score}}); Assert.{{test.expected ? "True" : "False"}}(sut.IsAllergicTo({{test.input.item | enum "Allergen"}})); } {{end}} {{for test in tests | property "list"}} [Fact(Skip = "Remove this Skip property to run this test")] - public void {{test.methodName}}() + public void {{test.testMethod}}() { - var sut = new Allergies({{test.input.score}}); + var sut = new {{testedClass}}({{test.input.score}}); {{if test.expected.empty?}} Assert.Empty(sut.List()); {{else}} diff --git a/exercises/practice/alphametics/.meta/Generator.tpl b/exercises/practice/alphametics/.meta/Generator.tpl index 45695ebef9..1044977e94 100644 --- a/exercises/practice/alphametics/.meta/Generator.tpl +++ b/exercises/practice/alphametics/.meta/Generator.tpl @@ -2,11 +2,11 @@ using System; using System.Collections.Generic; using Xunit; -public class AlphameticsTests +public class {{testClass}} { {{for test in tests}} [Fact{{if !for.first}}(Skip = "Remove this Skip property to run this test"){{end}}] - public void {{test.methodName}}() + public void {{test.testMethod}}() { {{if test.expected}} var actual = Alphametics.Solve({{test.input.puzzle | string.literal}}); diff --git a/exercises/practice/anagram/.meta/Generator.tpl b/exercises/practice/anagram/.meta/Generator.tpl index 53d4277f33..6e3f569aca 100644 --- a/exercises/practice/anagram/.meta/Generator.tpl +++ b/exercises/practice/anagram/.meta/Generator.tpl @@ -1,13 +1,13 @@ using Xunit; -public class AnagramTests +public class {{testClass}} { {{for test in tests}} [Fact{{if !for.first}}(Skip = "Remove this Skip property to run this test"){{end}}] - public void {{test.methodName}}() + public void {{test.testMethod}}() { string[] candidates = {{test.input.candidates}}; - var sut = new Anagram({{test.input.subject | string.literal}}); + var sut = new {{testedClass}}({{test.input.subject | string.literal}}); {{if test.expected.empty?}} Assert.Empty(sut.FindAnagrams(candidates)); {{else}} diff --git a/exercises/practice/armstrong-numbers/.meta/Generator.tpl b/exercises/practice/armstrong-numbers/.meta/Generator.tpl index 57a683a92a..98362fce70 100644 --- a/exercises/practice/armstrong-numbers/.meta/Generator.tpl +++ b/exercises/practice/armstrong-numbers/.meta/Generator.tpl @@ -1,12 +1,12 @@ using Xunit; -public class ArmstrongNumbersTests +public class {{testClass}} { {{for test in tests}} [Fact{{if !for.first}}(Skip = "Remove this Skip property to run this test"){{end}}] - public void {{test.methodName}}() + public void {{test.testMethod}}() { - Assert.{{test.expected ? "True" : "False"}}(ArmstrongNumbers.IsArmstrongNumber({{test.input.number}})); + Assert.{{test.expected ? "True" : "False"}}({{testedClass}}.{{test.testedMethod}}({{test.input.number}})); } {{end}} } diff --git a/exercises/practice/atbash-cipher/.meta/Generator.tpl b/exercises/practice/atbash-cipher/.meta/Generator.tpl index 3698894da0..eb4e92c92c 100644 --- a/exercises/practice/atbash-cipher/.meta/Generator.tpl +++ b/exercises/practice/atbash-cipher/.meta/Generator.tpl @@ -1,12 +1,12 @@ using Xunit; -public class AtbashCipherTests +public class {{testClass}} { {{for test in tests}} [Fact{{if !for.first}}(Skip = "Remove this Skip property to run this test"){{end}}] - public void {{test.shortMethodName}}() + public void {{test.shortTestMethod}}() { - Assert.Equal({{test.expected | string.literal}}, AtbashCipher.{{test.property | string.capitalize}}({{test.input.phrase | string.literal}})); + Assert.Equal({{test.expected | string.literal}}, {{testedClass}}.{{test.testedMethod}}({{test.input.phrase | string.literal}})); } {{end}} } diff --git a/exercises/practice/darts/.meta/Generator.tpl b/exercises/practice/darts/.meta/Generator.tpl index af965a68bc..4f5ae33fc7 100644 --- a/exercises/practice/darts/.meta/Generator.tpl +++ b/exercises/practice/darts/.meta/Generator.tpl @@ -1,12 +1,12 @@ using Xunit; -public class DartsTests +public class {{testClass}} { {{for test in tests}} [Fact{{if !for.first}}(Skip = "Remove this Skip property to run this test"){{end}}] - public void {{test.methodName}}() + public void {{test.testMethod}}() { - Assert.Equal({{test.expected}}, Darts.Score({{test.input.x}}, {{test.input.y}})); + Assert.Equal({{test.expected}}, {{testedClass}}.{{test.testedMethod}}({{test.input.x}}, {{test.input.y}})); } {{end}} } diff --git a/exercises/practice/difference-of-squares/.meta/Generator.tpl b/exercises/practice/difference-of-squares/.meta/Generator.tpl index f10ba5c8ae..bbbc231519 100644 --- a/exercises/practice/difference-of-squares/.meta/Generator.tpl +++ b/exercises/practice/difference-of-squares/.meta/Generator.tpl @@ -1,12 +1,12 @@ using Xunit; -public class DifferenceOfSquaresTests +public class {{testClass}} { {{for test in tests}} [Fact{{if !for.first}}(Skip = "Remove this Skip property to run this test"){{end}}] - public void {{test.shortMethodName}}() + public void {{test.shortTestMethod}}() { - Assert.Equal({{test.expected}}, DifferenceOfSquares.Calculate{{test.property | string.capitalize}}({{test.input.number}})); + Assert.Equal({{test.expected}}, {{testedClass}}.Calculate{{test.testedMethod}}({{test.input.number}})); } {{end}} } diff --git a/exercises/practice/eliuds-eggs/.meta/Generator.tpl b/exercises/practice/eliuds-eggs/.meta/Generator.tpl index 4cf21ff809..758ff59b62 100644 --- a/exercises/practice/eliuds-eggs/.meta/Generator.tpl +++ b/exercises/practice/eliuds-eggs/.meta/Generator.tpl @@ -1,12 +1,12 @@ using Xunit; -public class EliudsEggsTests +public class {{testClass}} { {{for test in tests}} [Fact{{if !for.first}}(Skip = "Remove this Skip property to run this test"){{end}}] - public void {{test.methodName}}() + public void {{test.testMethod}}() { - Assert.Equal({{test.expected}}, EliudsEggs.EggCount({{test.input.number}})); + Assert.Equal({{test.expected}}, {{testedClass}}.{{test.testedMethod}}({{test.input.number}})); } {{end}} } diff --git a/exercises/practice/hamming/.meta/Generator.tpl b/exercises/practice/hamming/.meta/Generator.tpl index 216c7e75aa..87ccf15879 100644 --- a/exercises/practice/hamming/.meta/Generator.tpl +++ b/exercises/practice/hamming/.meta/Generator.tpl @@ -1,16 +1,16 @@ using System; using Xunit; -public class HammingTests +public class {{testClass}} { {{for test in tests}} [Fact{{if !for.first}}(Skip = "Remove this Skip property to run this test"){{end}}] - public void {{test.methodName}}() + public void {{test.testMethod}}() { {{if test.expected.error}} Assert.Throws(() => Hamming.Distance({{test.input.strand1 | string.literal}}, {{test.input.strand2 | string.literal}})); {{else}} - Assert.Equal({{test.expected}}, Hamming.Distance({{test.input.strand1 | string.literal}}, {{test.input.strand2 | string.literal}})); + Assert.Equal({{test.expected}}, {{testedClass}}.{{test.testedMethod}}({{test.input.strand1 | string.literal}}, {{test.input.strand2 | string.literal}})); {{end}} } {{end}} diff --git a/exercises/practice/isogram/.meta/Generator.tpl b/exercises/practice/isogram/.meta/Generator.tpl index 89ae8337ed..a636693ad6 100644 --- a/exercises/practice/isogram/.meta/Generator.tpl +++ b/exercises/practice/isogram/.meta/Generator.tpl @@ -1,12 +1,12 @@ using Xunit; -public class IsogramTests +public class {{testClass}} { {{for test in tests}} [Fact{{if !for.first}}(Skip = "Remove this Skip property to run this test"){{end}}] - public void {{test.methodName}}() + public void {{test.testMethod}}() { - Assert.{{test.expected ? "True" : "False"}}(Isogram.IsIsogram({{test.input.phrase | string.literal}})); + Assert.{{test.expected ? "True" : "False"}}({{testedClass}}.{{test.testedMethod}}({{test.input.phrase | string.literal}})); } {{end}} } diff --git a/exercises/practice/leap/.meta/Generator.tpl b/exercises/practice/leap/.meta/Generator.tpl index 8b5014381c..63d0f7e149 100644 --- a/exercises/practice/leap/.meta/Generator.tpl +++ b/exercises/practice/leap/.meta/Generator.tpl @@ -1,12 +1,12 @@ using Xunit; -public class LeapTests +public class {{testClass}} { {{for test in tests}} [Fact{{if !for.first}}(Skip = "Remove this Skip property to run this test"){{end}}] - public void {{test.methodName}}() + public void {{test.testMethod}}() { - Assert.{{test.expected ? "True" : "False"}}(Leap.IsLeapYear({{test.input.year}})); + Assert.{{test.expected ? "True" : "False"}}({{testedClass}}.Is{{test.testedMethod}}({{test.input.year}})); } {{end}} } diff --git a/exercises/practice/pangram/.meta/Generator.tpl b/exercises/practice/pangram/.meta/Generator.tpl index 2894851815..c225b8b785 100644 --- a/exercises/practice/pangram/.meta/Generator.tpl +++ b/exercises/practice/pangram/.meta/Generator.tpl @@ -1,12 +1,12 @@ using Xunit; -public class PangramTests +public class {{testClass}} { {{for test in tests}} [Fact{{if !for.first}}(Skip = "Remove this Skip property to run this test"){{end}}] - public void {{test.methodName}}() + public void {{test.testMethod}}() { - Assert.{{test.expected ? "True" : "False"}}(Pangram.IsPangram({{test.input.sentence | string.literal}})); + Assert.{{test.expected ? "True" : "False"}}({{testedClass}}.{{test.testedMethod}}({{test.input.sentence | string.literal}})); } {{end}} } diff --git a/exercises/practice/perfect-numbers/.meta/Generator.tpl b/exercises/practice/perfect-numbers/.meta/Generator.tpl index 6ecab3a079..503b03d3a7 100644 --- a/exercises/practice/perfect-numbers/.meta/Generator.tpl +++ b/exercises/practice/perfect-numbers/.meta/Generator.tpl @@ -1,16 +1,16 @@ using System; using Xunit; -public class PerfectNumbersTests +public class {{testClass}} { {{for test in tests}} [Fact{{if !for.first}}(Skip = "Remove this Skip property to run this test"){{end}}] - public void {{test.shortMethodName}}() + public void {{test.shortTestMethod}}() { {{if test.expected.error}} Assert.Throws(() => PerfectNumbers.Classify({{test.input.number}})); {{else}} - Assert.Equal({{test.expected | enum "Classification"}}, PerfectNumbers.Classify({{test.input.number}})); + Assert.Equal({{test.expected | enum "Classification"}}, {{testedClass}}.{{test.testedMethod}}({{test.input.number}})); {{end}} } {{end}} diff --git a/exercises/practice/rotational-cipher/.meta/Generator.tpl b/exercises/practice/rotational-cipher/.meta/Generator.tpl index ce8e1461f9..4f93a62d24 100644 --- a/exercises/practice/rotational-cipher/.meta/Generator.tpl +++ b/exercises/practice/rotational-cipher/.meta/Generator.tpl @@ -1,12 +1,12 @@ using Xunit; -public class RotationalCipherTests +public class {{testClass}} { {{for test in tests}} [Fact{{if !for.first}}(Skip = "Remove this Skip property to run this test"){{end}}] - public void {{test.methodName}}() + public void {{test.testMethod}}() { - Assert.Equal({{test.expected | string.literal}}, RotationalCipher.Rotate({{test.input.text | string.literal}}, {{test.input.shiftKey}})); + Assert.Equal({{test.expected | string.literal}}, {{testedClass}}.{{test.testedMethod}}({{test.input.text | string.literal}}, {{test.input.shiftKey}})); } {{end}} } diff --git a/exercises/practice/series/.meta/Generator.tpl b/exercises/practice/series/.meta/Generator.tpl index 500c522b66..3c48c31eef 100644 --- a/exercises/practice/series/.meta/Generator.tpl +++ b/exercises/practice/series/.meta/Generator.tpl @@ -1,17 +1,17 @@ using System; using Xunit; -public class SeriesTests +public class {{testClass}} { {{for test in tests}} [Fact{{if !for.first}}(Skip = "Remove this Skip property to run this test"){{end}}] - public void {{test.methodName}}() + public void {{test.testMethod}}() { {{if test.expected.error}} Assert.Throws(() => Series.Slices({{test.input.series | string.literal}}, {{test.input.sliceLength}})); {{else}} string[] expected = {{test.expected}}; - Assert.Equal(expected, Series.Slices({{test.input.series | string.literal}}, {{test.input.sliceLength}})); + Assert.Equal(expected, {{testedClass}}.{{test.testedMethod}}({{test.input.series | string.literal}}, {{test.input.sliceLength}})); {{end}} } {{end}} diff --git a/exercises/practice/sieve/.meta/Generator.tpl b/exercises/practice/sieve/.meta/Generator.tpl index 01e3a05a48..607ea04ee6 100644 --- a/exercises/practice/sieve/.meta/Generator.tpl +++ b/exercises/practice/sieve/.meta/Generator.tpl @@ -1,13 +1,13 @@ using Xunit; -public class SieveTests +public class {{testClass}} { {{for test in tests}} [Fact{{if !for.first}}(Skip = "Remove this Skip property to run this test"){{end}}] - public void {{test.methodName}}() + public void {{test.testMethod}}() { int[] expected = {{test.expected}}; - Assert.Equal(expected, Sieve.Primes({{test.input.limit}})); + Assert.Equal(expected, {{testedClass}}.{{test.testedMethod}}({{test.input.limit}})); } {{end}} } diff --git a/exercises/practice/simple-cipher/.meta/Generator.tpl b/exercises/practice/simple-cipher/.meta/Generator.tpl index b57a4df06b..998e29189f 100644 --- a/exercises/practice/simple-cipher/.meta/Generator.tpl +++ b/exercises/practice/simple-cipher/.meta/Generator.tpl @@ -18,11 +18,11 @@ using Xunit; {{end}} {{end}} -public class SimpleCipherTests +public class {{testClass}} { {{for test in tests}} [Fact{{if !for.first}}(Skip = "Remove this Skip property to run this test"){{end}}] - public void {{test.methodName}}() + public void {{test.testMethod}}() { var sut = new SimpleCipher({{if test.input.key}}{{test.input.key | string.literal}}{{end}}); {{if test.property == "encode"}} diff --git a/exercises/practice/space-age/.meta/Generator.tpl b/exercises/practice/space-age/.meta/Generator.tpl index 164acffd61..dd15e0bcbe 100644 --- a/exercises/practice/space-age/.meta/Generator.tpl +++ b/exercises/practice/space-age/.meta/Generator.tpl @@ -1,10 +1,10 @@ using Xunit; -public class SpaceAgeTests +public class {{testClass}} { {{for test in tests}} [Fact{{if !for.first}}(Skip = "Remove this Skip property to run this test"){{end}}] - public void {{test.methodName}}() + public void {{test.testMethod}}() { var sut = new SpaceAge({{test.input.seconds}}); Assert.Equal({{test.expected}}, sut.On{{test.input.planet}}(), precision: 2); diff --git a/exercises/practice/square-root/.meta/Generator.tpl b/exercises/practice/square-root/.meta/Generator.tpl index 1e9acf6ef0..c21303ef7b 100644 --- a/exercises/practice/square-root/.meta/Generator.tpl +++ b/exercises/practice/square-root/.meta/Generator.tpl @@ -1,12 +1,12 @@ using Xunit; -public class SquareRootTests +public class {{testClass}} { {{for test in tests}} [Fact{{if !for.first}}(Skip = "Remove this Skip property to run this test"){{end}}] - public void {{test.methodName}}() + public void {{test.testMethod}}() { - Assert.Equal({{test.expected}}, SquareRoot.Root({{test.input.radicand}})); + Assert.Equal({{test.expected}}, {{testedClass}}.Root({{test.input.radicand}})); } {{end}} } diff --git a/exercises/practice/strain/.meta/Generator.tpl b/exercises/practice/strain/.meta/Generator.tpl index d443d6ff86..f2413f56b5 100644 --- a/exercises/practice/strain/.meta/Generator.tpl +++ b/exercises/practice/strain/.meta/Generator.tpl @@ -18,15 +18,15 @@ using Xunit; {{end}} {{end}} -public class StrainTests +public class {{testClass}} { {{for test in tests}} [Fact{{if !for.first}}(Skip = "Remove this Skip property to run this test"){{end}}] - public void {{test.methodName}}() + public void {{test.testMethod}}() { {{test.description | test_case_type}} expected = {{test.expected}}; {{test.description | test_case_type}} input = {{test.input.list}}; - Assert.Equal(expected, input.{{test.property | string.capitalize}}({{test.input.predicate | normalize_predicate}}).ToArray()); + Assert.Equal(expected, input.{{test.testedMethod}}({{test.input.predicate | normalize_predicate}}).ToArray()); } {{end}} } diff --git a/exercises/practice/sublist/.meta/Generator.tpl b/exercises/practice/sublist/.meta/Generator.tpl index 152d382515..e8e4d2ef3d 100644 --- a/exercises/practice/sublist/.meta/Generator.tpl +++ b/exercises/practice/sublist/.meta/Generator.tpl @@ -1,15 +1,15 @@ using System.Collections.Generic; using Xunit; -public class SublistTests +public class {{testClass}} { {{for test in tests}} [Fact{{if !for.first}}(Skip = "Remove this Skip property to run this test"){{end}}] - public void {{test.methodName}}() + public void {{test.testMethod}}() { List listOne = {{test.input.listOne}}; List listTwo = {{test.input.listTwo}}; - Assert.Equal({{test.expected | enum "SublistType"}}, Sublist.Classify(listOne, listTwo)); + Assert.Equal({{test.expected | enum "SublistType"}}, {{testedClass}}.Classify(listOne, listTwo)); } {{end}} } diff --git a/exercises/practice/sum-of-multiples/.meta/Generator.tpl b/exercises/practice/sum-of-multiples/.meta/Generator.tpl index 2302b01bd9..2218f7c76a 100644 --- a/exercises/practice/sum-of-multiples/.meta/Generator.tpl +++ b/exercises/practice/sum-of-multiples/.meta/Generator.tpl @@ -1,12 +1,12 @@ using Xunit; -public class SumOfMultiplesTests +public class {{testClass}} { {{for test in tests}} [Fact{{if !for.first}}(Skip = "Remove this Skip property to run this test"){{end}}] - public void {{test.methodName}}() + public void {{test.testMethod}}() { - Assert.Equal({{test.expected}}, SumOfMultiples.Sum({{test.input.factors}}, {{test.input.limit}})); + Assert.Equal({{test.expected}}, {{testedClass}}.{{test.testedMethod}}({{test.input.factors}}, {{test.input.limit}})); } {{end}} } diff --git a/exercises/practice/triangle/.meta/Generator.tpl b/exercises/practice/triangle/.meta/Generator.tpl index 68c332a264..cec04b9d67 100644 --- a/exercises/practice/triangle/.meta/Generator.tpl +++ b/exercises/practice/triangle/.meta/Generator.tpl @@ -1,12 +1,12 @@ using Xunit; -public class TriangleTests +public class {{testClass}} { {{for test in tests}} [Fact{{if !for.first}}(Skip = "Remove this Skip property to run this test"){{end}}] - public void {{test.methodName}}() + public void {{test.testMethod}}() { - Assert.{{test.expected ? "True" : "False"}}(Triangle.Is{{test.property | string.capitalize}}({{test.input.sides | array.join ", "}})); + Assert.{{test.expected ? "True" : "False"}}({{testedClass}}.Is{{test.testedMethod}}({{test.input.sides | array.join ", "}})); } {{end}} } diff --git a/exercises/practice/two-fer/.meta/Generator.tpl b/exercises/practice/two-fer/.meta/Generator.tpl index 37899fb203..c47e16ca44 100644 --- a/exercises/practice/two-fer/.meta/Generator.tpl +++ b/exercises/practice/two-fer/.meta/Generator.tpl @@ -1,12 +1,12 @@ using Xunit; -public class TwoFerTests +public class {{testClass}} { {{for test in tests}} [Fact{{if !for.first}}(Skip = "Remove this Skip property to run this test"){{end}}] - public void {{test.methodName}}() + public void {{test.testMethod}}() { - Assert.Equal({{test.expected | string.literal}}, TwoFer.Speak({{if !test.input.name.empty?}}{{test.input.name | string.literal}}{{end}})); + Assert.Equal({{test.expected | string.literal}}, {{testedClass}}.Speak({{if !test.input.name.empty?}}{{test.input.name | string.literal}}{{end}})); } {{end}} } diff --git a/exercises/practice/variable-length-quantity/.meta/Generator.tpl b/exercises/practice/variable-length-quantity/.meta/Generator.tpl index 5ef5c8caf8..dc8bf76dfb 100644 --- a/exercises/practice/variable-length-quantity/.meta/Generator.tpl +++ b/exercises/practice/variable-length-quantity/.meta/Generator.tpl @@ -1,11 +1,11 @@ using System; using Xunit; -public class VariableLengthQuantityTests +public class {{testClass}} { {{for test in tests}} [Fact{{if !for.first}}(Skip = "Remove this Skip property to run this test"){{end}}] - public void {{test.methodName}}() + public void {{test.testMethod}}() { uint[] integers = [ {{for integer in test.input.integers}} @@ -13,14 +13,14 @@ public class VariableLengthQuantityTests {{end}} ]; {{if test.expected.error}} - Assert.Throws(() => VariableLengthQuantity.{{test.property | string.capitalize}}(integers)); + Assert.Throws(() => VariableLengthQuantity.{{test.testedMethod}}(integers)); {{else}} uint[] expected = [ {{for expected in test.expected}} {{expected}}{{if !for.last}},{{end}} {{end}} ]; - Assert.Equal(expected, VariableLengthQuantity.{{test.property | string.capitalize}}(integers)); + Assert.Equal(expected, {{testedClass}}.{{test.testedMethod}}(integers)); {{end}} } {{end}} diff --git a/exercises/practice/word-count/.meta/Generator.tpl b/exercises/practice/word-count/.meta/Generator.tpl index 682f2b0d87..0506113963 100644 --- a/exercises/practice/word-count/.meta/Generator.tpl +++ b/exercises/practice/word-count/.meta/Generator.tpl @@ -1,11 +1,11 @@ using System.Collections.Generic; using Xunit; -public class WordCountTests +public class {{testClass}} { {{for test in tests}} [Fact{{if !for.first}}(Skip = "Remove this Skip property to run this test"){{end}}] - public void {{test.methodName}}() + public void {{test.testMethod}}() { var actual = WordCount.CountWords({{test.input.sentence | string.literal}}); var expected = new Dictionary diff --git a/exercises/practice/wordy/.meta/Generator.tpl b/exercises/practice/wordy/.meta/Generator.tpl index 6ece5a8eeb..d3b8a68729 100644 --- a/exercises/practice/wordy/.meta/Generator.tpl +++ b/exercises/practice/wordy/.meta/Generator.tpl @@ -1,16 +1,16 @@ using System; using Xunit; -public class WordyTests +public class {{testClass}} { {{for test in tests}} [Fact{{if !for.first}}(Skip = "Remove this Skip property to run this test"){{end}}] - public void {{test.methodName}}() + public void {{test.testMethod}}() { {{if test.expected.error}} Assert.Throws(() => Wordy.Answer({{test.input.question | string.literal}})); {{else}} - Assert.Equal({{test.expected}}, Wordy.Answer({{test.input.question | string.literal}})); + Assert.Equal({{test.expected}}, {{testedClass}}.{{test.testedMethod}}({{test.input.question | string.literal}})); {{end}} } {{end}} diff --git a/exercises/practice/yacht/.meta/Generator.tpl b/exercises/practice/yacht/.meta/Generator.tpl index 1302ff3afd..1c22204474 100644 --- a/exercises/practice/yacht/.meta/Generator.tpl +++ b/exercises/practice/yacht/.meta/Generator.tpl @@ -1,11 +1,11 @@ using System; using Xunit; -public class YachtTests +public class {{testClass}} { {{for test in tests}} [Fact{{if !for.first}}(Skip = "Remove this Skip property to run this test"){{end}}] - public void {{test.methodName}}() + public void {{test.testMethod}}() { Assert.Equal({{test.expected}}, YachtGame.Score({{test.input.dice}}, {{test.input.category | enum "YachtCategory"}})); } diff --git a/exercises/practice/zebra-puzzle/.meta/Generator.tpl b/exercises/practice/zebra-puzzle/.meta/Generator.tpl index c372f0f03c..dfd8bd3486 100644 --- a/exercises/practice/zebra-puzzle/.meta/Generator.tpl +++ b/exercises/practice/zebra-puzzle/.meta/Generator.tpl @@ -1,10 +1,10 @@ using Xunit; -public class ZebraPuzzleTests +public class {{testClass}} { {{for test in tests}} [Fact{{if !for.first}}(Skip = "Remove this Skip property to run this test"){{end}}] - public void {{test.methodName}}() + public void {{test.testMethod}}() { Assert.Equal(Nationality.{{test.expected}}, {{test.property | enum "ZebraPuzzle"}}()); } diff --git a/generators/Naming.cs b/generators/Naming.cs index 378acf2171..34f6897c6c 100644 --- a/generators/Naming.cs +++ b/generators/Naming.cs @@ -4,7 +4,10 @@ namespace Generators; internal static class Naming { - internal static string ToMethodName(params string[] path) => + internal static string ToMethodName(string property) => + property.Dehumanize(); + + internal static string ToTestMethodName(params string[] path) => path.Unwords() .Words() .Select(Transform) diff --git a/generators/Templates.cs b/generators/Templates.cs index 6429cf2e4c..8372da8bcd 100644 --- a/generators/Templates.cs +++ b/generators/Templates.cs @@ -29,13 +29,20 @@ public static string RenderTestsCode(CanonicalData canonicalData) private static class TemplateData { internal static JsonElement ForCanonicalData(CanonicalData canonicalData) => - JsonSerializer.SerializeToElement(new { tests = canonicalData.TestCases.Select(Create).ToArray() }); + JsonSerializer.SerializeToElement( + new + { + testClass = $"{canonicalData.Exercise.Name}Tests".Pascalize(), + testedClass = canonicalData.Exercise.Name.Pascalize(), + tests = canonicalData.TestCases.Select(Create).ToArray() + }); private static JsonElement Create(JsonNode testCase) { - testCase["methodName"] = Naming.ToMethodName(testCase["path"]!.AsArray().GetValues().ToArray()); - testCase["shortMethodName"] = Naming.ToMethodName(testCase["description"]!.GetValue()); - + testCase["testMethod"] = Naming.ToTestMethodName(testCase["path"]!.AsArray().GetValues().ToArray()); + testCase["shortTestMethod"] = Naming.ToTestMethodName(testCase["description"]!.GetValue()); + testCase["testedMethod"] = Naming.ToMethodName(testCase["property"]!.GetValue()); + return JsonSerializer.SerializeToElement(testCase); } }