diff --git a/exercises/phone-number/PhoneNumberTest.cs b/exercises/phone-number/PhoneNumberTest.cs index 0a09e51e1b..de9e7634f3 100644 --- a/exercises/phone-number/PhoneNumberTest.cs +++ b/exercises/phone-number/PhoneNumberTest.cs @@ -29,14 +29,14 @@ public void Cleans_numbers_with_multiple_spaces() public void Invalid_when_9_digits() { var phrase = "123456789"; - Assert.Equal(null, PhoneNumber.Clean(phrase)); + Assert.Null(PhoneNumber.Clean(phrase)); } [Fact(Skip = "Remove to run test")] public void Invalid_when_11_digits_does_not_start_with_a_1() { var phrase = "22234567890"; - Assert.Equal(null, PhoneNumber.Clean(phrase)); + Assert.Null(PhoneNumber.Clean(phrase)); } [Fact(Skip = "Remove to run test")] @@ -57,34 +57,34 @@ public void Valid_when_11_digits_and_starting_with_1_even_with_punctuation() public void Invalid_when_more_than_11_digits() { var phrase = "321234567890"; - Assert.Equal(null, PhoneNumber.Clean(phrase)); + Assert.Null(PhoneNumber.Clean(phrase)); } [Fact(Skip = "Remove to run test")] public void Invalid_with_letters() { var phrase = "123-abc-7890"; - Assert.Equal(null, PhoneNumber.Clean(phrase)); + Assert.Null(PhoneNumber.Clean(phrase)); } [Fact(Skip = "Remove to run test")] public void Invalid_with_punctuations() { var phrase = "123-@:!-7890"; - Assert.Equal(null, PhoneNumber.Clean(phrase)); + Assert.Null(PhoneNumber.Clean(phrase)); } [Fact(Skip = "Remove to run test")] public void Invalid_if_area_code_does_not_start_with_2_9() { var phrase = "(123) 456-7890"; - Assert.Equal(null, PhoneNumber.Clean(phrase)); + Assert.Null(PhoneNumber.Clean(phrase)); } [Fact(Skip = "Remove to run test")] public void Invalid_if_exchange_code_does_not_start_with_2_9() { var phrase = "(223) 056-7890"; - Assert.Equal(null, PhoneNumber.Clean(phrase)); + Assert.Null(PhoneNumber.Clean(phrase)); } } \ No newline at end of file diff --git a/generators/Exercise.cs b/generators/Exercise.cs index 9c10e013ee..73aaf1ced0 100644 --- a/generators/Exercise.cs +++ b/generators/Exercise.cs @@ -69,10 +69,19 @@ protected virtual string RenderTestMethodBody(CanonicalDataCase canonicalDataCas protected virtual TestMethodBody CreateTestMethodBody(CanonicalDataCase canonicalDataCase) { if (canonicalDataCase.ExceptionThrown != null) + { return new TestMethodBodyWithExceptionCheck(canonicalDataCase, CanonicalData); + } if (canonicalDataCase.Expected is bool) + { return new TestMethodBodyWithBooleanCheck(canonicalDataCase, CanonicalData); + } + + if (canonicalDataCase.Expected is null) + { + return new TestMethodBodyWithNullCheck(canonicalDataCase, CanonicalData); + } return new TestMethodBodyWithEqualityCheck(canonicalDataCase, CanonicalData); } @@ -86,4 +95,4 @@ protected virtual string RenderTestMethodBodyAct(TestMethodBody testMethodBody) protected virtual string RenderTestMethodBodyAssert(TestMethodBody testMethodBody) => TemplateRenderer.RenderPartial(testMethodBody.AssertTemplateName, testMethodBody.AssertTemplateParameters); } -} \ No newline at end of file +} diff --git a/generators/Exercises/PhoneNumber.cs b/generators/Exercises/PhoneNumber.cs index feece6c61e..2d0605b72b 100644 --- a/generators/Exercises/PhoneNumber.cs +++ b/generators/Exercises/PhoneNumber.cs @@ -1,5 +1,4 @@ using Generators.Input; -using Generators.Output; namespace Generators.Exercises { @@ -10,7 +9,6 @@ protected override void UpdateCanonicalData(CanonicalData canonicalData) foreach (var canonicalDataCase in CanonicalData.Cases) { canonicalDataCase.UseVariablesForInput = true; - canonicalDataCase.Expected = canonicalDataCase.Expected ?? new UnescapedValue("null"); } } } diff --git a/generators/Output/Templates/_AssertNull.liquid b/generators/Output/Templates/_AssertNull.liquid new file mode 100644 index 0000000000..93d9af2a94 --- /dev/null +++ b/generators/Output/Templates/_AssertNull.liquid @@ -0,0 +1 @@ +Assert.Null({{ TestedValue }}); \ No newline at end of file diff --git a/generators/Output/TestMethodBodyWithNullCheck.cs b/generators/Output/TestMethodBodyWithNullCheck.cs new file mode 100644 index 0000000000..03f716f789 --- /dev/null +++ b/generators/Output/TestMethodBodyWithNullCheck.cs @@ -0,0 +1,13 @@ +using Generators.Input; + +namespace Generators.Output +{ + public class TestMethodBodyWithNullCheck : TestMethodBody + { + public TestMethodBodyWithNullCheck(CanonicalDataCase canonicalDataCase, CanonicalData canonicalData) : base(canonicalDataCase, canonicalData) + { + AssertTemplateName = "AssertNull"; + AssertTemplateParameters = new { Data.TestedValue }; + } + } +} \ No newline at end of file